I can break a working test with this diff:
- protected void ingest(String filename) throws Exception {
+ protected JobExecution ingest(String filename) throws Exception {
JobParameters jobParameters = new JobParametersBuilder().addString("input.file", filename).toJobParameters();
JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(jobParameters);
Assertions.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
+ return jobExecution;
}
This yields:
java.lang.IllegalArgumentException: Could not create job execution from method: ingest
at org.springframework.batch.test.JobScopeTestExecutionListener.getJobExecution(JobScopeTestExecutionListener.java:128)
at org.springframework.batch.test.JobScopeTestExecutionListener.prepareTestInstance(JobScopeTestExecutionListener.java:77)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)
at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:163)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
at java.base/java.util.Optional.orElseGet(Optional.java:364)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.IllegalArgumentException: No matching arguments found for method: ingest
at org.springframework.batch.item.adapter.HippyMethodInvoker.findMatchingMethod(HippyMethodInvoker.java:73)
at org.springframework.util.MethodInvoker.prepare(MethodInvoker.java:190)
at org.springframework.batch.test.JobScopeTestExecutionListener.getJobExecution(JobScopeTestExecutionListener.java:124)
... 15 more
You seem to be using a
JobScopeTestExecutionListener. This listener looks for a factory method that creates aJobExecution, using it as the context for each test method. There is a note about this in the docs here. The factory method is detected by its signature (it must return aJobExecution), but the docs are not precise enough about the signature of the factory method, which should not accept any parameter.That's why when you change the signature of
ingestto return aJobExecution, the test fails.