Upgrade to Pro — share decks privately, control downloads, hide ads and more …

spek

 spek

spek

Shinnosuke Kugimiya

November 21, 2017
Tweet

More Decks by Shinnosuke Kugimiya

Other Decks in Programming

Transcript

  1. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) }
  2. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } ςετͱͯ͠͸໰୊ͳ͍͕ɺ Կ͕ࣄલ৚݅Ͱ ԿΛͨ࣌͠ʹ ԿΛอূ͢Δςετͳͷ͔ ͺͬͱݟΘ͔Βͳ͍
  3. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } ࣄલ৚݅
  4. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } QSFTFOUFSͷPO$SFBUF7JFX͕ݺ͹Εͨ࣌ʹ
  5. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } WJFXTFU6Q 7JFX.PEFM ͕ݺ͹ΕΔ͜ͱΛ͔֬ΊΔςετ
  6. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } WJFXTFU6Q 7JFX.PEFM ͕ݺ͹ΕΔ͜ͱΛ͔֬ΊΔςετ ͜ͷΑ͏ʹॱংΛపఈ͢Δ͜ͱ ͦ͏͍͏ॱংͰ͋Δ͜ͱΛ஌͍ͬͯΔ͜ͱͰ Θ͔Γ΍͘͢ͳΔ͕ Ͱ͖Δ͜ͱͳΒڧ੍తͩͬͨΓΫϥεͷߏ଄Ͱ දݱ͍ͨ͠
  7. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } }
  8. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { subject.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } Կ͕ࣄલ৚݅Ͱ ԿΛͨ࣌͠ʹ ԿΛอূ͢Δςετͳͷ͔ ͺͬͱݟͰΘ͔Δ
  9. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } ࣄલ৚݅
  10. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } QSFTFOUFSͷPO$SFBUF7JFX͕ݺ͹Εͨ࣌ʹ
  11. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } WJFXTFU6Q 7JFX.PEFM ͕ݺ͹ΕΔ͜ͱΛ͔֬ΊΔςετ
  12. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } WJFXTFU6Q 7JFX.PEFM ͕ݺ͹ΕΔ͜ͱΛ͔֬ΊΔςετ Θ͔Δ
  13. @RunWith(JUnitPlatform::class) class BeforeSeasonWorkListPresenterTest : Spek({ val getBeforeSeasonWorkListUseCase = Mockito.mock(GetBeforeSeasonWorkListUseCase::class.jav given("GetBeforeSeasonWorkListUseCase

    return workList") { val works = DomainHelper. works() Mockito.`when`(getBeforeSeasonWorkListUseCase.execute()).thenReturn(Single.just(works)) on("onCreateView") { val presenter = BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkViewModelConverter.convertToViewModel(works) Mockito.verify(view).setUp(expected) } } } given("") { on("onClickWork") { val viewModel = WorkViewModelFactory.create() val presenter = BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) presenter.onClickWork(viewModel) it("should move to Detail") { Mockito.verify(screenTransition).moveToDetail() } } } })
  14. @RunWith(JUnitPlatform::class) class BeforeSeasonWorkListPresenterTest : Spek({ val getBeforeSeasonWorkListUseCase = Mockito.mock(GetBeforeSeasonWorkListUseCase::class.jav given("GetBeforeSeasonWorkListUseCase

    return workList") { val works = DomainHelper. works() Mockito.`when`(getBeforeSeasonWorkListUseCase.execute()).thenReturn(Single.just(works)) on("onCreateView") { val presenter = BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkViewModelConverter.convertToViewModel(works) Mockito.verify(view).setUp(expected) } } } given("") { on("onClickWork") { val viewModel = WorkViewModelFactory.create() val presenter = BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) presenter.onClickWork(viewModel) it("should move to Detail") { Mockito.verify(screenTransition).moveToDetail() } } } }) HJWFO PO JUΛ࢖ͬͯςετΛॻ͚ͩ͘
  15. @RunWith(JUnitPlatform::class) internal class BeforeSeasonWorkListPresenterSpec : SubjectSpek<BeforeSeasonWorkListPresenter>({ val getBeforeSeasonWorkListUseCase = Mockito.mock(GetBeforeSeasonWorkListUseCase::class.java)

    subject { BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) } given("GetBeforeSeasonWorkListUseCase return workList") { val works = DomainHelper.works() Mockito.`when`(getBeforeSeasonWorkListUseCase.execute()).thenReturn(Single.just(works)) on("onCreateView") { subject.onCreateView() it("should setUp ViewModel to view") { val expected = WorkViewModelConverter.convertToViewModel(works) Mockito.verify(view).setUp(expected) } } } given("") { on("onClickWork") { val viewModel = WorkViewModelFactory.create() subject.onClickWork(viewModel) it("should move to Detail") { Mockito.verify(screenTransition).moveToDetail() } } } })
  16. @RunWith(JUnitPlatform::class) internal class BeforeSeasonWorkListPresenterSpec : SubjectSpek<BeforeSeasonWorkListPresenter>({ val getBeforeSeasonWorkListUseCase = Mockito.mock(GetBeforeSeasonWorkListUseCase::class.java)

    subject { BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) } given("GetBeforeSeasonWorkListUseCase return workList") { val works = DomainHelper.works() Mockito.`when`(getBeforeSeasonWorkListUseCase.execute()).thenReturn(Single.just(works)) on("onCreateView") { subject.onCreateView() it("should setUp ViewModel to view") { val expected = WorkViewModelConverter.convertToViewModel(works) Mockito.verify(view).setUp(expected) } } } given("") { on("onClickWork") { val viewModel = WorkViewModelFactory.create() subject.onClickWork(viewModel) it("should move to Detail") { Mockito.verify(screenTransition).moveToDetail() } } } }) ςετର৅Ϋϥε͕Θ͔Γ΍͍͢
  17. Ҿ͔͔ͬͬͨΓͨ͠ͱ͜Ζᶅ Spek { val a: A = Mockito.mock(A::class.java) given() {

    Mockito.when(a.execute).thenReturn("a") on() { it() { assertEquals("a", a.execute) } } } } ͜ͷςετ͸1BTT 'BJM
  18. Ҿ͔͔ͬͬͨΓͨ͠ͱ͜Ζᶅ Spek { val a: A = Mockito.mock(A::class.java) given() {

    Mockito.when(a.execute).thenReturn("a") on() { it() { assertEquals("a", a.execute) } } } } 1BTT
  19. Spek { val a: A = Mockito.mock(A::class.java) given() { Mockito.when(a.execute).thenReturn("a")

    on() { it() { assertEquals("a", a.execute) } } } given() { Mockito.when(a.execute).thenReturn("b") on() { it() { assertEquals("b", a.execute) } } } } ͜ͷςετ͸1BTT 'BJM
  20. Spek { val a: A = Mockito.mock(A::class.java) given() { Mockito.when(a.execute).thenReturn("a")

    on() { it() { assertEquals("a", a.execute) } } } given() { Mockito.when(a.execute).thenReturn("b") on() { it() { assertEquals("b", a.execute) } } } }
  21. Spek { val a: A = Mockito.mock(A::class.java) given() { Mockito.when(a.execute).thenReturn("a")

    on() { it() { assertEquals("a", a.execute) } } } given() { Mockito.when(a.execute).thenReturn("b") on() { it() { assertEquals("b", a.execute) } } } } 1BTT 'BJM
  22. Spek { val a: A = Mockito.mock(A::class.java) given() { Mockito.when(a.execute).thenReturn("a")

    on() { it() { assertEquals("a", a.execute) } } } given() { Mockito.when(a.execute).thenReturn("b") on() { it() { assertEquals("b", a.execute) } } } } ΋ͬͱ΋Լʹ͋Δ΋ͷউͪ
  23. Spek { val a: A = Mockito.mock(A::class.java) given() { beforeGroup

    { Mockito.when(a.execute).thenReturn(“a”) } on() { it() { assertEquals("a", a.execute) } } } given() { beforeGroup { Mockito.when(a.execute).thenReturn(“b”) } on() { it() { assertEquals("b", a.execute) } } } ͜͏͠·͠ΐ͏