title: maven-surefire-plugin:2.22.1 test failing with NullPointerException
body: <p>I have a problem successfully compiling my tests with maven. I am mocking a service using EasyMock v 4.0.2. I should mention running the test with the intellij IDE works without problems Below is the code attached. The problem seems to arise when ever I try to inject the mocks into my mock test. I have seen a couple of posts on this issue but nothing that addresses my problem.</p>
  
  <p>The closest I have seen is this
  <a href="https://stackoverflow.com/questions/53663892/spring-boot-failed-to-execute-goal-org-apache-maven-pluginsmaven-surefire-plugi">Spring Boot Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test</a></p>
  
  <pre><code>public class EasyMockExtension implements TestInstancePostProcessor {
      @Override
      public void postProcessTestInstance(Object testInstance, ExtensionContext extensionContext) throws Exception {
          EasyMockSupport.injectMocks(testInstance);
      }
  }
  </code></pre>
  
  <pre><code>
  @ExtendWith(EasyMockExtension.class)
  public class TestUserService extends EasyMockSupport {
  
      @TestSubject
      private UserService userService = new UserService();
  
      @Mock
      private UserRepository userRepository;
  
      @Mock
      private PasswordEncoder passwordEncoder;
  
      @Mock
      private MessengerRoleRepository roleRepository;
  
      @Mock
      private AuthenticationManager authenticationManager;
  
      @Mock
      private JwtTokenProvider jwtTokenProvider;
  
  
      @Test
      public void testAuthenticateUser(){
          String username = "username";
          String password = "password";
          String token = UUID.randomUUID().toString();
          User user = TestUserHelper.createUserWithRoles(username, password);
          Collection&lt;String&gt; roles = user.getRoles().stream().map(MessengerRole::getRoleName).collect(Collectors.toList());
          EasyMock.expect(authenticationManager.authenticate(EasyMock.anyObject(UsernamePasswordAuthenticationToken.class)))
                  .andReturn(EasyMock.anyObject(Authentication.class));
          EasyMock.expect(userRepository.findByUsername(username)).andReturn(Optional.of(user));
          EasyMock.expect(jwtTokenProvider.createToken(EasyMock.anyString(), EasyMock.anyObject(Collection.class))).andReturn(token);
          replayAll();
          Map&lt;String, Object&gt; authenticatedUser =  userService.authenticateUser(username, password);
          Assertions.assertTrue(MapUtils.isNotEmpty(authenticatedUser));
          Assertions.assertSame(authenticatedUser.get("token"), token);
          Assertions.assertTrue(((Collection&lt;String&gt;)authenticatedUser.get("roles")).containsAll(roles));
          Assertions.assertTrue(roles.containsAll((Collection&lt;String&gt;)authenticatedUser.get("roles")));
          verifyAll();
      }
  
      @Test
      public void testAddFriendUsernameSuccess(){
          long userId = 10L;
          String username = "testUser2";
          User user = TestUserHelper.createUser();
          User friend = EasyMock.createMock(User.class);
  
          Optional&lt;User&gt; optionalUser = Optional.of(user);
          Optional&lt;User&gt;  optionalFriend = Optional.of(friend);
  
          EasyMock.expect(userRepository.findById(userId)).andReturn(optionalUser);
          EasyMock.expect(userRepository.findByUsername(username)).andReturn(optionalFriend);
          EasyMock.replay(userRepository, friend);
  
          User returnedUser = userService.addFriend(userId, username);
          Assertions.assertNotNull(returnedUser);
          Assertions.assertSame(returnedUser, user);
          Assertions.assertTrue(returnedUser.getFriends().contains(friend));
          EasyMock.verify(userRepository, friend);
      }
  }
  </code></pre>
  
  <p>This is what I get from that. I would appreciate any help on this as I'm not sure why surefire is not injecting my mocks</p>
  
  <pre><code>java.lang.NullPointerException
      at com.messenger.service.TestUserService.testAuthenticateUser(TestUserService.java)
  
  [ERROR] com.messenger.service.TestUserService.testAddFriendUserNotFound()  Time elapsed: 0 s  &lt;&lt;&lt; FAILURE!
  java.lang.NullPointerException
      at com.messenger.service.TestUserService.testAddFriendUserNotFound(TestUserService.java)
  
  [ERROR] com.messenger.service.TestUserService.testAddFriendUsernameNotFound()  Time elapsed: 0 s  &lt;&lt;&lt; FAILURE!
  java.lang.NullPointerException
      at com.messenger.service.TestUserService.testAddFriendUsernameNotFound(TestUserService.java)
  
  [ERROR] com.messenger.service.TestUserService.testAddFriendUsernameSuccess()  Time elapsed: 0.191 s  &lt;&lt;&lt; FAILURE!
  java.lang.NullPointerException
      at com.messenger.service.TestUserService.testAddFriendUsernameSuccess(TestUserService.java)
  
  [ERROR] com.messenger.service.TestUserService.testAuthenticateUserUnableToFindUser()  Time elapsed: 0.001 s  &lt;&lt;&lt; FAILURE!
  java.lang.NullPointerException
  </code></pre>