Skip to content

Instantly share code, notes, and snippets.

@travisdachi
Created April 13, 2017 15:47
Show Gist options
  • Save travisdachi/0f6381b86aeffbde73c91ad51a9b30c3 to your computer and use it in GitHub Desktop.
Save travisdachi/0f6381b86aeffbde73c91ad51a9b30c3 to your computer and use it in GitHub Desktop.
package com.example.android.testing.notes.notes
import com.example.android.testing.notes.data.Note
import com.example.android.testing.notes.data.NotesRepository
import com.nhaarman.mockito_kotlin.*
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
/**
* Created by travis on 3/13/2017 AD.
*/
object NotesPresenterSpec : Spek({
given("a NotesPresenter") {
val notesRepository: NotesRepository = mock()
val notesView: NotesContract.View = mock()
val notesPresenter: NotesPresenter = NotesPresenter(notesRepository, notesView)
val callbackCaptor = argumentCaptor<NotesRepository.LoadNotesCallback>()
val NOTES = listOf(Note("Title1", "Description1"), Note("Title2", "Description2"))
afterEachTest {
reset(notesRepository)
reset(notesView)
}
on("load notes") {
notesPresenter.loadNotes(true)
it("should load notes from the repository") {
verify(notesRepository).getNotes(callbackCaptor.capture())
callbackCaptor.lastValue.onNotesLoaded(NOTES)
}
it("should show and hide a progress in order") {
inOrder(notesView) {
verify(notesView).setProgressIndicator(true)
verify(notesView).setProgressIndicator(false)
}
}
it("should show notes on the view") {
verify(notesView).showNotes(NOTES)
}
}
on("add a new note") {
notesPresenter.addNewNote()
it("should show add note UI") {
verify(notesView).showAddNote()
}
}
on("open note detail") {
val requestedNote = Note("Details Requested", "For this note")
notesPresenter.openNoteDetails(requestedNote)
it("should show note detail UI") {
verify(notesView).showNoteDetailUi(any())
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment