title: Mocked repository returns null
body: <p>I'm using springMVC and I would like to test my services but my @Mock repository is not working, so I will never get my user because my repository is null, how can I fix this problem? am I doing something wrong in my annotations?</p>
  
  <p>Repository Interface:</p>
  
  <pre><code>package br.com.api.model.data;
  
  import br.com.api.model.resources.User;
  
  import java.util.List;
  
  public interface UserDao {
      User findByLoginAndPassword(String login, String password);
      List&lt;User&gt; listAll();
  }
  </code></pre>
  
  <p>Repository Implementation:</p>
  
  <pre><code>package br.com.api.model.repository;
  import br.com.api.model.data.UserDao;
  import br.com.api.model.resources.User;
  import org.springframework.stereotype.Repository;
  
  import java.util.ArrayList;
  import java.util.List;
  
  
  @Repository
  public class UserRepository implements UserDao {
  
      public User findByLoginAndPassword(String login, String password) {
          System.out.println("lets find:");
          User userMatch = new User();
          List&lt;User&gt; users = usersMockup();
  
          for (User user : users) {
              if(user.getLogin().equals(login)
                      &amp;&amp; user.getPassword().equals(password)){
                  userMatch = user;
              }
          }
  
          return userMatch;
      }
  
      public List&lt;User&gt; listAll() {
          List&lt;User&gt; users = usersMockup();
  
          return users;
      }
  
  
      private List&lt;User&gt; usersMockup(){
          List&lt;User&gt; users = new ArrayList&lt;User&gt;();
  
          User first = new User();
          first.setLogin("first");
          first.setPassword("teste");
  
          User scnd = new User();
          scnd.setLogin("second");
          scnd.setPassword("teste");
  
          users.add(first);
          users.add(scnd);
  
          return users;
      }
  }
  </code></pre>
  
  <p>This is my Service:</p>
  
  <pre><code>package br.com.api.model.services;
  
  
  import br.com.api.model.data.UserDao;
  import br.com.api.model.resources.User;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  @Service
  public class UserService {
  
      @Autowired
      private UserDao userRepository;
  
      public User findUser(String login, String password) {
          User userMatch;
          userMatch = userRepository.findByLoginAndPassword(login, password);
  
          return  userMatch;
      }
  }
  </code></pre>
  
  <p>Here is my Test:</p>
  
  <pre><code>package br.com.api.model.services;
  
  
  import br.com.api.model.repository.UserRepository;
  import br.com.api.model.resources.User;
  import org.junit.runner.RunWith;
  import org.mockito.MockitoAnnotations;
  import org.mockito.Mock;
  import org.junit.Before;
  import org.junit.Test;
  import org.mockito.InjectMocks;
  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  
  import static org.mockito.Mockito.when;
  
  @RunWith(SpringJUnit4ClassRunner.class)
  public class UserServiceTest {
  
      @Mock
      UserDao userRepository;
  
      @InjectMocks
      UserService userService;
  
      @Before
      public void setUp(){
          MockitoAnnotations.initMocks(this);
      }
  
      @Test
      public void findUser(){
  
          User user;
          user = userService.findUser("first", "teste");
  
          assertNotNull(user.getLogin());
  
      }
  
  }  
  </code></pre>