Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
4,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. class SignInViewModelTest {
  2.     /**
  3.      * Tests if clickSignIn calls expected method from Repository. Currently, that's its only task.
  4.      */
  5.     @Test
  6.     fun testclcikSignIn() {
  7.         val mockContext = Mockito.mock(Context::class.java)
  8.         val mockRepository = Mockito.mock(Repository::class.java)
  9.         val input = "inputHere"
  10.        
  11.     // return something to be expected
  12.         Mockito.`when`(mockRepository.signInOperation(mockContext, input))
  13.                 .thenReturn(Single.just(Intent()))
  14.        
  15.     val origRepository = ReflectionHelpers.getStaticField<Repository>(
  16.                 Repository::class.java, "instance")
  17.         ReflectionHelpers.setStaticField(Repository::class.java, "instance", mockRepository)
  18.        
  19.     // actual test – check output type and verify a Repository operation was called
  20.         assertTrue("Method return type wrong", viewModel.clickSignIn.(mockContext, input) is Single<Intent>)
  21.         verify(mockRepository, times(1)).signInOperation(mockContext, input)
  22.  
  23.         ReflectionHelpers.setStaticField(Repository::class.java, "instance",
  24.                 origRepository)
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement