Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
Migration to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
svtk committed Feb 18, 2019
1 parent dd43f86 commit 59faf6c
Show file tree
Hide file tree
Showing 45 changed files with 385 additions and 303 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ repositories {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.google.guava:guava:16.0'
testCompile 'junit:junit:4.12'
testCompile 'org.junit.jupiter:junit-jupiter:5.4.0'
}
7 changes: 4 additions & 3 deletions test/i_introduction/_0_Hello_World/N00StartKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package i_introduction._0_Hello_World

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N00StartKtTest {
@Test fun testOk() {
@Test
fun testOk() {
assertEquals("OK", task0())
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package i_introduction._10_Object_Expressions

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N10ObjectExpressionsKtTest {
@Test fun testSort() {
@Test
fun testSort() {
assertEquals(listOf(5, 2, 1), task10())
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package i_introduction._11_SAM_Conversions

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N11SAMConversionsKtTest {
@Test fun testSort() {
@Test
fun testSort() {
assertEquals(listOf(5, 2, 1), task11())
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package i_introduction._12_Extensions_On_Collections

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N12ExtensionsOnCollectionsKtTest {
@Test fun testSort() {
@Test
fun testSort() {
assertEquals(listOf(5, 2, 1), task12())
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package i_introduction._1_Java_To_Kotlin_Converter

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N01JavaToKotlinConverterKtTest {
@Test fun collection() {
@Test
fun collection() {
assertEquals("{1, 2, 3, 42, 555}", task1(listOf(1, 2, 3, 42, 555)))
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package i_introduction._2_Named_Arguments

import org.junit.Assert.assertEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N02NamedArgumentsKtTest {

@org.junit.Test fun testJoinToString() {
@Test
fun testJoinToString() {
assertEquals("{1, 2, 3, 42, 555}", task2(listOf(1, 2, 3, 42, 555)))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package i_introduction._3_Default_Arguments

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N03DefaultArgumentsKtTest {

@Test fun testDefaultAndNamedParams() {
@Test
fun testDefaultAndNamedParams() {
assertEquals("a42b1C42D2", task3())
}
}
12 changes: 7 additions & 5 deletions test/i_introduction/_4_Lambdas/N04LambdasKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package i_introduction._4_Lambdas

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class N04LambdasKtTest {
@Test fun contains() {
@Test
fun contains() {
assertTrue(task4(listOf(1, 2, 3)))
}

@Test fun notContains() {
@Test
fun notContains() {
assertFalse(task4(listOf(1, 3, 5)))
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package i_introduction._5_String_Templates

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.util.regex.Pattern
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class N05StringTemplatesKtTest {
@Test fun match() {
@Test
fun match() {
assertTrue("11 MAR 1952".matches(task5().toRegex()))
}

@Test fun match1() {
@Test
fun match1() {
assertTrue("24 AUG 1957".matches(task5().toRegex()))
}

@Test fun doNotMatch() {
@Test
fun doNotMatch() {
assertFalse("24 RRR 1957".matches(task5().toRegex()))
}
}
7 changes: 4 additions & 3 deletions test/i_introduction/_6_Data_Classes/N06DataClassesKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package i_introduction._6_Data_Classes

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test


class N06DataClassesKtTest {
@Test fun testListOfPeople() {
@Test
fun testListOfPeople() {
assertEquals("[Person(name=Alice, age=29), Person(name=Bob, age=31)]", task6().toString())
}
}
45 changes: 24 additions & 21 deletions test/i_introduction/_7_Nullable_Types/N07NullableTypesKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
package i_introduction._7_Nullable_Types

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N07NullableTypesKtTest {
fun testSendMessageToClient(
client: Client?,
message: String?,
email: String? = null,
shouldBeInvoked: Boolean = false
private fun testSendMessageToClient(
client: Client?,
message: String?,
email: String? = null,
shouldBeInvoked: Boolean = false
) {
var invoked = false
sendMessageToClient(client, message, object : Mailer {
override fun sendMessage(actualEmail: String, actualMessage: String) {
invoked = true
assertEquals("The message is not as expected:",
message, actualMessage)
assertEquals("The email is not as expected:",
email, actualEmail)
assertEquals(message, actualMessage, "The message is not as expected:")
assertEquals(email, actualEmail, "The email is not as expected:")
}
})
assertEquals("The function 'sendMessage' should${if (shouldBeInvoked) "" else "n't"} be invoked",
shouldBeInvoked, invoked)
assertEquals(shouldBeInvoked, invoked,
"The function 'sendMessage' should${if (shouldBeInvoked) "" else "n't"} be invoked")
}

@Test fun everythingIsOk() {
@Test
fun everythingIsOk() {
testSendMessageToClient(Client(PersonalInfo("[email protected]")),
"Hi Bob! We have an awesome proposition for you...",
"[email protected]",
true)
"Hi Bob! We have an awesome proposition for you...",
"[email protected]",
true)
}

@Test fun noMessage() {
@Test
fun noMessage() {
testSendMessageToClient(Client(PersonalInfo("[email protected]")), null)
}

@Test fun noEmail() {
@Test
fun noEmail() {
testSendMessageToClient(Client(PersonalInfo(null)), "Hi Bob! We have an awesome proposition for you...")
}

@Test fun noPersonalInfo() {
@Test
fun noPersonalInfo() {
testSendMessageToClient(Client(null), "Hi Bob! We have an awesome proposition for you...")
}

@Test fun noClient() {
@Test
fun noClient() {
testSendMessageToClient(null, "Hi Bob! We have an awesome proposition for you...")
}
}
19 changes: 11 additions & 8 deletions test/i_introduction/_8_Smart_Casts/N08SmartCastsKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package i_introduction._8_Smart_Casts

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N08SmartCastsKtTest {
@Test fun testNum() {
assertEquals("'eval' on Num should work:", 2, eval(Num(2)))
@Test
fun testNum() {
assertEquals(2, eval(Num(2)), "'eval' on Num should work:")
}

@Test fun testSum() {
assertEquals("'eval' on Sum should work:", 3, eval(Sum(Num(2), Num(1))))
@Test
fun testSum() {
assertEquals(3, eval(Sum(Num(2), Num(1))), "'eval' on Sum should work:")
}

@Test fun testRecursion() {
assertEquals("'eval' should work recursively:", 6, eval(Sum(Sum(Num(1), Num(2)), Num(3))))
@Test
fun testRecursion() {
assertEquals(6, eval(Sum(Sum(Num(1), Num(2)), Num(3))), "'eval' should work recursively:")
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package i_introduction._9_Extension_Functions

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N09ExtensionFunctionsKtTest {
@Test fun testIntExtension() {
assertEquals("Rational number creation error: ", RationalNumber(4, 1), 4.r())
@Test
fun testIntExtension() {
assertEquals(RationalNumber(4, 1), 4.r(), "Rational number creation error: ")
}

@Test fun testPairExtension() {
assertEquals("Rational number creation error: ", RationalNumber(2, 3), Pair(2, 3).r())
@Test
fun testPairExtension() {
assertEquals(RationalNumber(2, 3), Pair(2, 3).r(), "Rational number creation error: ")
}
}
7 changes: 4 additions & 3 deletions test/ii_collections/N13IntroductionKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package ii_collections

import ii_collections.data.customers
import ii_collections.data.shop
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N13IntroductionKtTest {
@Test fun testSetOfCustomers() {
@Test
fun testSetOfCustomers() {
assertEquals(customers.values.toSet(), shop.getSetOfCustomers())
}
}
10 changes: 6 additions & 4 deletions test/ii_collections/N14FilterMapKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package ii_collections

import ii_collections.data.*
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class N14FilterMapKtTest {
@Test fun testCitiesCustomersAreFrom() {
@Test
fun testCitiesCustomersAreFrom() {
assertEquals(setOf(Canberra, Vancouver, Budapest, Ankara, Tokyo), shop.getCitiesCustomersAreFrom())
}

/**
* Returns the list of the customers who live in the city 'city'
*/
@Test fun testCustomersFromCity() {
@Test
fun testCustomersFromCity() {
assertEquals(listOf(customers[lucas], customers[cooper]), shop.getCustomersFrom(Canberra))
}
}
19 changes: 12 additions & 7 deletions test/ii_collections/N15AllAnyAndOtherPredicatesKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
package ii_collections

import ii_collections.data.*
import org.junit.Assert.*
import org.junit.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

class N15AllAnyAndOtherPredicatesKtTest {
@Test fun testCustomerIsFromCity() {
@Test
fun testCustomerIsFromCity() {
assertTrue(customers[lucas]!!.isFrom(Canberra))
assertFalse(customers[lucas]!!.isFrom(Budapest))
}

@Test fun testAllCustomersAreFromCity() {
@Test
fun testAllCustomersAreFromCity() {
assertFalse(shop.checkAllCustomersAreFrom(Canberra))
}

@Test fun testAnyCustomerIsFromCity() {
@Test
fun testAnyCustomerIsFromCity() {
assertTrue(shop.hasCustomerFrom(Canberra))
}

@Test fun testCountCustomersFromCity() {
@Test
fun testCountCustomersFromCity() {
assertEquals(2, shop.countCustomersFrom(Canberra))
}

@Test fun testFirstCustomerFromCity() {
@Test
fun testFirstCustomerFromCity() {
assertEquals(customers[lucas], shop.findFirstCustomerFrom(Canberra))
assertEquals(null, shop.findFirstCustomerFrom(City("Chicago")))
}
Expand Down
Loading

0 comments on commit 59faf6c

Please sign in to comment.