Created
February 26, 2021 02:31
-
-
Save anandwana001/9bccce1f9a0413af5f86ec12dc331d24 to your computer and use it in GitHub Desktop.
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
@Test | |
fun `food is pizza and have 4 slices`() { | |
val underTest = generateTalkback() | |
assertThat(underTest).hasTalkBackLabel(context.getString(R.string.faq_activity_label)) | |
} | |
private fun generateTalkback(): Talkback { | |
return Talkback.TalkbackLable(context.getString(R.string.faq_activity_label)) | |
} |
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
sealed class Talkback { | |
class TalkbackLable(val lable: String): Talkback() | |
} | |
class TalkbackSubject(metadata: FailureMetadata, actual: Talkback) : | |
Subject<TalkbackSubject, Talkback>(metadata, actual) { | |
fun hasTalkBackLabel(lable: String) { | |
if (actual() !is Talkback.TalkbackLable) { | |
failWithoutActual(Fact.simpleFact("expected to be a lable!")) | |
} | |
val target = actual() as Talkback.TalkbackLable | |
if (target.lable != lable) { | |
failWithActual(Fact.simpleFact("expected to be have '$lable' but have '${target.lable}' instead")) | |
} | |
} | |
} | |
fun talkback(): Subject.Factory<TalkbackSubject, Talkback> { | |
return Subject.Factory<TalkbackSubject, Talkback> { metaData, target -> | |
TalkbackSubject( | |
metaData, | |
target | |
) | |
} | |
} | |
fun assertThat(@Nullable talkback: Talkback): TalkbackSubject { | |
return assertAbout(talkback()).that(talkback) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment