У меня есть этот тестовый код Junit 5: < /p>
@InjectMocks
ReportAssembler reportAssembler;
private ReportingReturnResponse reportingReturnResponse;
private ReturnReport returnReport;
private StaticPathLinkBuilder staticPathLinkBuilder;
public ReportingResource mergeReturn(ReturnReport returnReport, ReportingResource reportingResource) {
Link link = staticPathLinkBuilder.linkTo(
methodOn(ReturnController.class).getReturnById(
returnReport.getAccount().getId(),
returnReport.getReturn().getId())
).withSelfRel();
return reportingResource;
}
public LinkBuilder linkTo(Object dummyInvocation) {
LastInvocationAware lastInvocationAware =
(LastInvocationAware) dummyInvocation;
MethodInvocation methodInvocation = lastInvocationAware.getLastInvocation();
StaticPathLinkBuilder staticPathLinkBuilder = getThis();
return staticPathLinkBuilder.linkTo(methodInvocation.getMethod(), methodInvocation.getArguments());
}
@Test
public void testMergeReturnCompletesSuccessfully() {
ReportingResource reportResource = reportAssembler.mergeReturn(returnReport, this.reportingResource);
assertNotNull(reportResource.getReturnResource());
}
для возврата строки staticpathlinkbuilder.linkto (methodInvocation.getMethod (), methodInvocation.getArguments ()); я получаю ошибку, вызванную: java.lang.illegalargumentException: невозможно подкласс окончательный класс java.lang.reflect.method . Как я могу решить?Cannot invoke "java.lang.reflect.Method.getDeclaringClass()" because "method" is null
java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Method.getDeclaringClass()" because "method" is null
at com.util.StaticPathLinkBuilder.createRelativeUri(StaticPathLinkBuilder.java:74)
at com.util.StaticPathLinkBuilder.linkTo(StaticPathLinkBuilder.java:32)
at com.reporting.assembler.ReportingAssemblerReturnTest.testMergeReturnCompletesSuccessfully(ReportingAssemblerReturnTest.java:53)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Подробнее здесь: https://stackoverflow.com/questions/795 ... ect-method