This file contains hidden or 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 SpecBody.detachPresenterAction(presenter: PeopleListPresenter) { | |
| on("presenter detach") { | |
| presenter.detach() | |
| it("should detach view") { | |
| Assert.assertNull(presenter.view) | |
| } | |
| } | |
| } |
This file contains hidden or 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
| given("no people in repository"){ | |
| val view: PeopleListContract.View = mock() | |
| val repository : Repository<Person> = mock { | |
| on { getAll() } doReturn Single.error(Error("no data")) | |
| } | |
| val presenter = PeopleListPresenter(repository) | |
| on("presenter attach"){ | |
| presenter.attach(view) | |
| presenterAttachStandardFlow(view, presenter){ | |
| it("should not add anything to view"){ |
This file contains hidden or 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
| on("presenter attach") { | |
| presenter.attach(view) | |
| presenterAttachStandardFlow(view, presenter) { | |
| it("should add people to view") { | |
| verify(view).addPeople(peopleList) | |
| } | |
| it("should never show error") { | |
| verify(view, never()).showError(anyOrNull()) | |
| } | |
| } |
This file contains hidden or 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 ActionBody.presenterAttachStandardFlow( | |
| view: PeopleListContract.View, | |
| presenter: PeopleListPresenter, | |
| additionalTestBlock: () -> Unit) { | |
| it("should attach view") { | |
| Assert.assertNotNull(presenter.view) | |
| } | |
| it("should start loading") { | |
| verify(view).showLoading() | |
| } |
This file contains hidden or 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 PeopleListPresenter(private val repository: Repository<Person>) : PeopleListContract.Presenter { | |
| var view: PeopleListContract.View? = null | |
| override fun attach(view: PeopleListContract.View) { | |
| this.view = view | |
| loadPeople() | |
| } | |
| private fun loadPeople() { |
This file contains hidden or 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 presenter = PeopleListPresenter(repository) | |
| on("presenter attach"){ | |
| presenter.attach(view) | |
| it("should attach view"){ | |
| assertNotNull(presenter.view) | |
| } | |
| it("should start loading") { | |
| verify(view).showLoading() | |
| } |
This file contains hidden or 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 peopleList : List<Person> = listOf( | |
| Person(id = "1", firstName = "Mark", surname = "Train"), | |
| Person(id = "2", firstName = "George", secondName = "Edward", surname = "Bicycle") | |
| ) | |
| val repository : Repository<Person> = mock{ | |
| on { getAll() } doReturn Single.just(peopleList) | |
| } |
This file contains hidden or 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 PeopleListPresenter(val repository: Repository<Person>) : PeopleListContract.Presenter { | |
| var view: PeopleListContract.View? = null | |
| override fun attach(view: PeopleListContract.View) { | |
| this.view = view | |
| } | |
| override fun detach() { | |
| this.view = null |
This file contains hidden or 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
| interface Repository<in T>{ | |
| fun getAll() : Single<List<T>> | |
| fun getOne(id : String) : Single<T> | |
| fun create(t : T) | |
| } |
This file contains hidden or 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
| on("presenter attach") { | |
| presenter.attach(view) | |
| it("should attach view") { | |
| assertNotNull(presenter.view) | |
| } | |
| it("should start loading") { | |
| verify(view).showLoading() | |
| } | |
| it("should load list into view") { | |
| verify(view).addPeople(peopleList) |