title: How to write AWS Cognito function's Unit Test?
body: <p>I am new to test cases and I'm trying to test Aws Cognito auth functions. In my production code, I have written sign-in functionality in AuthRepositoryImp class. And I'm trying to test this functionality with a unit test.</p>
  <p>I was trying to follow this <a href="https://stackoverflow.com/a/66863076">answer</a></p>
  <p>AuthRepositoryImp contains this function</p>
  <pre><code>  override suspend fun logIn(
      username: String,
      password: String
  ): Resource&lt;AuthSignInResult&gt; = try {
      val result = auth.signIn(username, password)
      if (result.isSignInComplete) {
          Resource.Success(result)
      } else {
          Resource.Failure(failureStatus = FailureStatus.OTHER, message = &quot;Something Went Wrong&quot;)
      }
  }catch (authException: AuthException){
      Resource.Failure(failureStatus = FailureStatus.OTHER, message = authException.message)
  }
  </code></pre>
  <p>Here is what I tried:</p>
  <pre><code>@RunWith(MockitoJUnitRunner::class)
  class AuthRepositoryTest {
  
  lateinit var mockAuth: KotlinAuthFacade
  lateinit var repository: AuthRepository
  
  @Before
  fun setup(){
      mockAuth = Mockito.mock(KotlinAuthFacade::class.java)
      repository = AuthRepositoryImpl(mockAuth)
  }
  
  @Test
  fun login() = runBlocking {
      val mock = Mockito.doAnswer {  invocation -&gt;
          val onResult =
              invocation.arguments[1] as Consumer&lt;AuthSignInResult&gt;
          // Invoke it with some canned result
          onResult.accept(Mockito.mock(AuthSignInResult::class.java))
      }
          .`when`(mockAuth)
          .signIn(eq(&quot;example@gmail.com&quot;), eq(&quot;Abcd$1234&quot;), any())
      assertThat(repository.logIn(&quot;example@gmail.com&quot;, &quot;Abcd$1234&quot;)).isEqualTo(mock)
  }
  }
  </code></pre>
  <p>And its giving an exception</p>
  <pre><code>java.lang.ClassCastException: class java.lang.String cannot be cast to class com.amplifyframework.core.Consumer (java.lang.String is in module java.base of loader 'bootstrap'; com.amplifyframework.core.Consumer is in unnamed module of loader 'app')
  </code></pre>