0

I have just received a new project, I have a fresh repo clone of a java spring project. When I build it with Gradle, all the dependencies are downloaded but when one of the Gradle tasks execute, the unit tests, the build fails.

I think the problem resides in the argThat() method of Mockito that is not getting well integrated with JUnit. This is one of the places where the issue occurs:

enter image description here

Any time a unit tests have this kind of logic, it fails with:

enter image description here

The console output is not for the above test but it is a similar method with more complex logic. The above tests still fail with the same issue.

This only happens in my machine and not on others that are on a Unix distribution, fedora.

I think the problem is due to the dependencies version, but I have tested with different ones to no avail.

I can give you more information if needed. Thank you.

EDIT: Code - not a screenshot

@Test
void shouldAbortEventExecutionWhenJobFails() throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
  when(jobLauncher.run(eq(job1), argThat(jobParametersForPath(TEST_PATH_1)))).thenReturn(jobExecutionFailed);
  when(job1.getName()).thenReturn("job1");

  ExecutionState result = executor.execute(asList(event1, event2));

  assertThat(result).isEqualTo(ExecutionState.FAILED);

  verify(jobLauncher).run(eq(job1), argThat(jobParametersForPath(TEST_PATH_1)));
  verify(jobLauncher, never()).run(eq(job2), argThat(jobParametersForPath(TEST_PATH_1)));
  verify(jobLauncher).run(eq(job1), argThat(jobParametersForPath(TEST_PATH_2)));
  verify(jobLauncher).run(eq(job2), argThat(jobParametersForPath(TEST_PATH_2)));
  verifyNoMoreInteractions(jobLauncher);
}

private ArgumentMatcher<JobParameters> jobParametersForPath(String inputPath) {
  return jobParameters ->
    jobParameters.getParameters().get("inputFilePath").toString().equals(inputPath) &&
      jobParameters.getParameters().get("outputFilePath").toString().equals(TEST_OUTPUT_PATH + "/" + inputPath) &&
      jobParameters.getParameters().containsKey("timestamp");
}
Ihor Patsian
  • 1,288
  • 2
  • 15
  • 25
Pedro Pereira
  • 312
  • 5
  • 21

1 Answers1

1

I can't tell you the exact problem without inspecting your code or without reproducing your issue. But I guess the problem should be related to file paths;

I can see that there is a variable called outputFilePath inside your assertation object. in Linux environments, we use slash / for file paths, but in windows environments it's back-slashes \.

[1] https://www.howtogeek.com/181774/why-windows-uses-backslashes-and-everything-else-uses-forward-slashes/

[2] https://stackoverflow.com/a/1589959/3728639

You need to debug your Junit test and compare actual assertation object with the expected one

Chathura Buddhika
  • 2,067
  • 1
  • 21
  • 35