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
fun String?.reversed() : String? = this //forgot to reverse it? | |
@Label("Reversing a reversed String returns the original") | |
@Property | |
fun reverseStringTest(@ForAll originalString: String?) { | |
assertTrue( | |
originalString?.reversed()?.reversed() == originalString | |
) | |
} |
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
@Label("If password without upper case chars," + | |
"the error message contains 'no upper case letters'" | |
) | |
@Property(seed = "-7293214509268013126") | |
fun testPasswordValidatorRight(@ForAll("noUpperCase") password: String?) { | |
collectPasswordStats(password) | |
val actualError = passwordValidator.validate(password) | |
Truth.assertThat(actualError).contains("no upper case letters") | |
} |
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
@Label("If password without upper case chars," + | |
"the error message contains 'no upper case letters'" | |
) | |
@Property | |
fun testPasswordValidatorRight(@ForAll("noUpperCase") password: String?) { | |
collectPasswordStats(password) | |
val actualError = passwordValidator.validate(password) | |
Truth.assertThat(actualError).contains("no upper case letters") | |
} |
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
fun statsUpperCase(password: String?){ | |
val withUpperCase = password?.contains("[A-Z]".toRegex()) | |
Statistics | |
.label("Upper case") | |
.collect(if (withUpperCase == true) "with upper case" else "without upper case") | |
} | |
... | |
fun collectPasswordStats(password: String?){ | |
statsUpperCase(password) |
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
@Provide | |
fun noUpperCase(): Arbitrary<String> = | |
Arbitraries.strings().ascii().filter { it.matches("[^A-Z]".toRegex()) } |
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
android { | |
... | |
testOptions { | |
unitTests.all { | |
useJUnitPlatform { | |
//this config supports Jqwik, Junit4 and Junit5 | |
includeEngines 'jqwik', 'junit-jupiter', 'junit-vintage' | |
} | |
include '**/*Properties.class' | |
include '**/*Test.class' |
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
class ContainsUpperCaseLetterValidator : RequirementValidator { | |
override val keywordOnError: String? = "no upper case letters" | |
override fun isValid(password: String?): Boolean = | |
password?.contains("[a-z]".toRegex()) == true | |
} |
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
val passwordValidator = PasswordValidator( | |
ContainsUpperCaseLetterValidator(), | |
MinCharsValidator(6), | |
ContainsDigitValidator(), | |
ContainsLowerCaseLetterValidator(), | |
NoBlanksValidator() | |
) | |
@DisplayName("PasswordValidator for invalid passwords") | |
@ParameterizedTest(name = "When password is \"{0}\", the error contains \"{1}\"") |
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
import android.content.Context | |
import android.text.SpannedString | |
import android.text.TextUtils | |
import androidx.annotation.PluralsRes | |
import androidx.annotation.StringRes | |
import androidx.core.text.HtmlCompat | |
fun Context.getStyledText( | |
@StringRes id: Int, | |
vararg args: Any |