Skip to content

Instantly share code, notes, and snippets.

@anandwana001
Created February 26, 2021 02:31
Show Gist options
  • Save anandwana001/9bccce1f9a0413af5f86ec12dc331d24 to your computer and use it in GitHub Desktop.
Save anandwana001/9bccce1f9a0413af5f86ec12dc331d24 to your computer and use it in GitHub Desktop.
@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))
}
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