More boundary refactoring and testing

Only testing branch logic is so nice...
This commit is contained in:
Bradlee Speice
2014-11-22 17:31:53 -05:00
parent 05d2d006e4
commit 8d65327853
2 changed files with 68 additions and 24 deletions

View File

@ -2,6 +2,7 @@ package org.bspeice.minimalbible.activity.downloader
import org.jetbrains.spek.api.Spek
import kotlin.test.assertTrue
import android.content.DialogInterface
/**
* Created by bspeice on 11/22/14.
@ -10,16 +11,13 @@ import kotlin.test.assertTrue
class BookListFragmentSpek : Spek() {{
given("A BookListFragment with showDialog() mocked out") {
class TestableFragment : BookListFragment() {
val fragment = object : BookListFragment() {
var condition = false
override fun showDialog() {
condition = true
}
}
val fragment = TestableFragment()
on("attempting to display modules with the dialog not shown already") {
fragment.displayModules(false)
@ -30,7 +28,7 @@ class BookListFragmentSpek : Spek() {{
}
given("a BookListFragment with displayLanguageSpinner() mocked out") {
class TestableFragment : BookListFragment() {
val fragment = object : BookListFragment() {
var condition = false
override fun displayLanguageSpinner() {
@ -38,8 +36,6 @@ class BookListFragmentSpek : Spek() {{
}
}
val fragment = TestableFragment()
on("attempting to display modules with the dialog already shown") {
fragment.displayModules(true)
@ -48,5 +44,39 @@ class BookListFragmentSpek : Spek() {{
}
}
}
given("a DownloadDialogListener with with buttonPositive() mocked out") {
val listener = object : BookListFragment.DownloadDialogListener(null, null) {
var condition = false
override fun buttonPositive() {
condition = true
}
}
on("handling a positive button press") {
listener.handleButton(DialogInterface.BUTTON_POSITIVE)
it("should call the proper handler") {
assertTrue(listener.condition)
}
}
}
given("A DownloadDialogListener with buttonNegative() mocked out") {
val listener = object : BookListFragment.DownloadDialogListener(null, null) {
var condition = false
override fun buttonNegative() {
condition = true
}
}
on("handling a negative button press") {
listener.handleButton(DialogInterface.BUTTON_NEGATIVE)
it("should call the proper handler") {
assertTrue(listener.condition)
}
}
}
}
}