Code: Select all
// imports
@Component
@Aspect
@Slf4j
class aopClass {
pubic void log(Joinpoint jp) {
log.info("hi {} and {}", jp.getsignature(), jp.getSourceLocation());
}
}
< /code>
Jetzt funktioniert dies. Deshalb habe ich versucht, eine Testklasse dafür zu erstellen.//imports
@ExtendWith(MockitoExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class MyTest {
@InjectMocks
aopClass aopClass1= new aopClass();
JoinPoint joinPoint;
private static final org.slf4j.Logger log = mock(org.slf4j.LoggerFactory.getLogger(MyTest.class).getClass());
@BeforeAll
void setup(){
joinPoint = mock(JoinPoint.class);
when(joinPoint.getSignature()).thenReturn(null);
}
@Test
void log() {
aopClass1.log(joinPoint);
verify(joinPoint, times(1)).getSignature();
verify(joinPoint, times(1)).getSourceLocation();
verify(log, times(1)).info(anyString()); // always throws error here?
}
}
Code: Select all
Wanted but not invoked:
log.info();
-> at ch.qos.logback.classic.Logger.info(Logger.java:584)
Actually, there were zero interactions with this mock.