title: Flutter UnitTest: Two different mocks for the same class
body: <p>currently I am writing Unit tests for my mobile web application (Android app). The unit tests refer to my login system built upon Google Firebase Auth. </p>
  
  <p>With one of the latest releases of the <code>firebase authentication</code> plugins, the return type of some functions have been changed. For example, the method <code>firebaseAuth.signInWithEmailAndPassword</code> has been changed from <code>FirebaseUser</code> to <code>AuthResult</code></p>
  
  <p>I have a <strong>login</strong> function in a <code>AuthService.dart</code> with the following content:</p>
  
  <pre><code>Future&lt;bool&gt; login(LoginUserData userData) async {
      try {
        _checkUserDataValidity(userData);
        final AuthResult authResult= await firebaseAuth.signInWithEmailAndPassword(email: userData.email, password: userData.password);
        return authResult.user != null;
      } catch (exception) {
        return false;
      }
    }
  </code></pre>
  
  <p>So, as you can see I am only checking whether the data of the user is correct or not - I am returning a boolean to check this in another file (if true is returned, the <code>Navigator</code> routes to another site, if wrong is returned an error message pops up).</p>
  
  <p>My Unit tests for example checks for a few cases:</p>
  
  <ol>
  <li>Correct data</li>
  <li>Incorrect data (userData is not empty or null)</li>
  <li>Empty data</li>
  </ol>
  
  <p>Example code of a test:</p>
  
  <pre><code>test('Login should work with valid user data', () async {
        when(
          firebaseAuthMock.signInWithEmailAndPassword(
            email: testValidUserData.email,
            password: testValidUserData.password,
          )
        ).thenAnswer(
          (_) =&gt; Future&lt;AuthResultMock&gt;.value(firebaseAuthResultMock)
        );
  
        final bool actionSuccess = await authService.login(testValidUserData);
  
        verify(
          firebaseAuthMock.signInWithEmailAndPassword(
            email: testValidUserData.email,
            password: testValidUserData.password,
          )
        ).called(1);
  
        expect(actionSuccess, true);
      });
  </code></pre>
  
  <p>To cover case one and two of my list above, I'd like to use two different Mocks. One Mock to contain a user, the other mock has no user in it.</p>
  
  <p>Current issue:</p>
  
  <pre><code>(_) =&gt; Future&lt;AuthResultMock&gt;.value(firebaseAuthResultMock)
  </code></pre>
  
  <p>in my test is in conflict with this code from the <code>AuthServie.dart</code></p>
  
  <pre><code>return authResult.user != null;
  </code></pre>
  
  <p>The mock is having null as user. How can I change this? :) Bt.w I am using Mockito.</p>
  
  <p>My idea was:</p>
  
  <ol>
  <li>For correct data, to return a mock, that contains a user.</li>
  <li>For invalid data, to return a mock, that has null as user.</li>
  </ol>
  
  <p>Thank you so much. :)</p>