jeudi 31 janvier 2019

Test throws NullPointerException instead of RandomCustomException, but only in some environments

I am working on a project with more people and branches. There is a test, written by someone else, which weirdly passes in some of the environments and fails in some other ones.

We are working on separate branches but we made sure that we see the same version of the project with

git pull origin develop

The code looks like:

@Test(expected = RandomCustomException.class)
 public void saveReturnsWithCustomException() throws 
   RandomCustomException {
   xService.save(notValidX);   
}

In some environments it throws a NullPointerException, thus fails, in some other ones it throws a RandomCustomException.

We've checked it, and it's weird, but all the related codes seem to be exactly the same in all the environments.

My xService looks like:

  public X saveX(X x) throws RandomCustomException {
if (!validXName(X.getName())) {
  throw new RandomCustomException("The given name wasn't correct or the field is empty!");
}
return xRepository.save(x);

xRepository is mocked in the test.

xRepository:

public interface xRepository extends JpaRepository<X, Long> {
  X findByApplicationUser(ApplicationUser applicationUser);
}

Does anyone have a suggestion what can the problem be?

Aucun commentaire:

Enregistrer un commentaire