-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protected-string): add more functionalities for conversion and c…
…oncatenation
- Loading branch information
Showing
3 changed files
with
68 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,6 @@ commit-message: | |
"protected-long", | ||
"protected-float", | ||
"protected-double", | ||
"protected-string", | ||
"tests" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/kotlin/com/vfmunhoz/protectedtypes/types/ProtectedStringTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.vfmunhoz.protectedtypes.types | ||
|
||
import org.junit.jupiter.api.assertAll | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertIs | ||
import kotlin.test.assertTrue | ||
|
||
internal class ProtectedStringTest { | ||
|
||
@Test | ||
fun `convert and compares strings and protected strings successfully`() { | ||
val testString = "Hello ProtectedTypes!" | ||
val protectedTestString = testString.toProtected() | ||
|
||
assertIs<ProtectedString>(protectedTestString) | ||
|
||
assertFalse(testString.equals(protectedTestString), "String.equals is impossible to overload for Protected parameter") | ||
|
||
assertAll("ProtectedString.equals", | ||
{ assertTrue(protectedTestString.equals(testString)) }, | ||
{ assertEquals(protectedTestString, testString.toProtected()) } | ||
) | ||
} | ||
|
||
@Test | ||
fun `concat two strings with the plus operator`() { | ||
val beginString = "Hello" | ||
val endString = "ProtectedTypes!" | ||
|
||
val beginProtectedString = beginString.toProtected() | ||
val endProtectedString = endString.toProtected() | ||
|
||
val nativeStringConcat = beginString + endString | ||
val protectedStringConcat = beginProtectedString + endProtectedString | ||
|
||
assertEquals(nativeStringConcat, protectedStringConcat.value) | ||
} | ||
} |