From 22b57081b7fac00138caa958e58b4489a84e4cee Mon Sep 17 00:00:00 2001 From: Sushant Date: Thu, 14 Feb 2019 23:21:11 +0100 Subject: [PATCH 1/6] Add tests for string comparison --- .../stringcomparison/StringComparisonTest.kt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt diff --git a/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt new file mode 100644 index 0000000000..b8eefdb144 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt @@ -0,0 +1,47 @@ +package com.baeldung.stringcomparison + +import org.junit.Test +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class StringComparisonUnitTest { + + @Test + fun compareUsingEqualsOperator() { + val first = "kotlin" + val second = "kotlin" + val firstCapitalized = "KOTLIN" + assertTrue { first == second } + assertFalse { first == firstCapitalized } + } + + @Test + fun compareUsingReferencialEqualsOperator() { + val first = "kotlin" + val second = "kotlin" + val firstBuildAgain = buildString { "kotlin" } + assertTrue { first === second } + assertFalse { first === firstBuildAgain } + } + + @Test + fun compareUsingEqualsMethod() { + val first = "kotlin" + val second = "kotlin" + val firstCapitalized = "KOTLIN" + assertTrue { first.equals(second) } + assertFalse { first.equals(firstCapitalized) } + assertTrue { first.equals(firstCapitalized, true) } + } + + @Test + fun compareUsingCompareToMethod() { + val first = "kotlin" + val second = "kotlin" + val firstCapitalized = "KOTLIN" + assertTrue { first.compareTo(second) == 0 } + assertTrue { first.compareTo(firstCapitalized) == 32 } + assertTrue { firstCapitalized.compareTo(first) == -32 } + assertTrue { first.compareTo(firstCapitalized, true) == 0 } + } +} \ No newline at end of file From c5a0ff9313a079e0649a2af228c269f69ef52766 Mon Sep 17 00:00:00 2001 From: Sushant Date: Thu, 14 Feb 2019 23:31:55 +0100 Subject: [PATCH 2/6] Fix method names --- .../test/kotlin/com/baeldung/datamapping/UserTest.kt | 2 +- .../baeldung/stringcomparison/StringComparisonTest.kt | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt index 44d350ea38..c65b74ac2d 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt @@ -8,7 +8,7 @@ class UserTest { @Test fun `maps User to UserResponse using extension function`() { - val p = buildUser() + val p = buildUser() val view = p.toUserView() assertUserView(view) } diff --git a/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt index b8eefdb144..43caddfcf5 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt @@ -7,8 +7,8 @@ import kotlin.test.assertTrue class StringComparisonUnitTest { @Test - fun compareUsingEqualsOperator() { - val first = "kotlin" + fun `compare using equals operator`() { + val first = "kotlin" val second = "kotlin" val firstCapitalized = "KOTLIN" assertTrue { first == second } @@ -16,7 +16,7 @@ class StringComparisonUnitTest { } @Test - fun compareUsingReferencialEqualsOperator() { + fun `compare using referential equals operator`() { val first = "kotlin" val second = "kotlin" val firstBuildAgain = buildString { "kotlin" } @@ -25,7 +25,7 @@ class StringComparisonUnitTest { } @Test - fun compareUsingEqualsMethod() { + fun `compare using equals method`() { val first = "kotlin" val second = "kotlin" val firstCapitalized = "KOTLIN" @@ -35,7 +35,7 @@ class StringComparisonUnitTest { } @Test - fun compareUsingCompareToMethod() { + fun `compare using compare method`() { val first = "kotlin" val second = "kotlin" val firstCapitalized = "KOTLIN" From da033e6c01bcf8eea59f337448f2a35cc03e0b5a Mon Sep 17 00:00:00 2001 From: Kumar Sushant Date: Thu, 14 Feb 2019 23:33:03 +0100 Subject: [PATCH 3/6] Update UserTest.kt --- .../src/test/kotlin/com/baeldung/datamapping/UserTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt index c65b74ac2d..aeff7c8cce 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt @@ -8,7 +8,7 @@ class UserTest { @Test fun `maps User to UserResponse using extension function`() { - val p = buildUser() + val p = buildUser() val view = p.toUserView() assertUserView(view) } @@ -40,4 +40,4 @@ class UserTest { { assertEquals(30, pr.age) } ) } -} \ No newline at end of file +} From b70ff29759b42b898054e94e93e7526bd4069515 Mon Sep 17 00:00:00 2001 From: Sushant Date: Thu, 14 Feb 2019 23:35:18 +0100 Subject: [PATCH 4/6] Revert commit --- .../src/test/kotlin/com/baeldung/datamapping/UserTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt index c65b74ac2d..44d350ea38 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/datamapping/UserTest.kt @@ -8,7 +8,7 @@ class UserTest { @Test fun `maps User to UserResponse using extension function`() { - val p = buildUser() + val p = buildUser() val view = p.toUserView() assertUserView(view) } From 74e52749d49ab744f6bf8e6cc1977536b3e5e14b Mon Sep 17 00:00:00 2001 From: Sushant Date: Thu, 14 Feb 2019 23:40:01 +0100 Subject: [PATCH 5/6] Formatting --- .../com/baeldung/stringcomparison/StringComparisonTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt index 43caddfcf5..1ba98da8dd 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt @@ -8,7 +8,7 @@ class StringComparisonUnitTest { @Test fun `compare using equals operator`() { - val first = "kotlin" + val first = "kotlin" val second = "kotlin" val firstCapitalized = "KOTLIN" assertTrue { first == second } From 19b0b021024d0add9dda880d5be59ad72bc36ba6 Mon Sep 17 00:00:00 2001 From: Sushant Date: Mon, 18 Feb 2019 19:39:36 +0100 Subject: [PATCH 6/6] Change variable name --- .../stringcomparison/StringComparisonTest.kt | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt index 1ba98da8dd..9528f62df5 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/stringcomparison/StringComparisonTest.kt @@ -6,42 +6,42 @@ import kotlin.test.assertTrue class StringComparisonUnitTest { - @Test - fun `compare using equals operator`() { - val first = "kotlin" - val second = "kotlin" - val firstCapitalized = "KOTLIN" - assertTrue { first == second } - assertFalse { first == firstCapitalized } - } + @Test + fun `compare using equals operator`() { + val first = "kotlin" + val second = "kotlin" + val firstCapitalized = "KOTLIN" + assertTrue { first == second } + assertFalse { first == firstCapitalized } + } - @Test - fun `compare using referential equals operator`() { - val first = "kotlin" - val second = "kotlin" - val firstBuildAgain = buildString { "kotlin" } - assertTrue { first === second } - assertFalse { first === firstBuildAgain } - } + @Test + fun `compare using referential equals operator`() { + val first = "kotlin" + val second = "kotlin" + val copyOfFirst = buildString { "kotlin" } + assertTrue { first === second } + assertFalse { first === copyOfFirst } + } - @Test - fun `compare using equals method`() { - val first = "kotlin" - val second = "kotlin" - val firstCapitalized = "KOTLIN" - assertTrue { first.equals(second) } - assertFalse { first.equals(firstCapitalized) } - assertTrue { first.equals(firstCapitalized, true) } - } + @Test + fun `compare using equals method`() { + val first = "kotlin" + val second = "kotlin" + val firstCapitalized = "KOTLIN" + assertTrue { first.equals(second) } + assertFalse { first.equals(firstCapitalized) } + assertTrue { first.equals(firstCapitalized, true) } + } - @Test - fun `compare using compare method`() { - val first = "kotlin" - val second = "kotlin" - val firstCapitalized = "KOTLIN" - assertTrue { first.compareTo(second) == 0 } - assertTrue { first.compareTo(firstCapitalized) == 32 } - assertTrue { firstCapitalized.compareTo(first) == -32 } - assertTrue { first.compareTo(firstCapitalized, true) == 0 } - } + @Test + fun `compare using compare method`() { + val first = "kotlin" + val second = "kotlin" + val firstCapitalized = "KOTLIN" + assertTrue { first.compareTo(second) == 0 } + assertTrue { first.compareTo(firstCapitalized) == 32 } + assertTrue { firstCapitalized.compareTo(first) == -32 } + assertTrue { first.compareTo(firstCapitalized, true) == 0 } + } } \ No newline at end of file