use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.
the class CustomizableTraceInterceptorTests method testSunnyDayPathLogsCorrectly.
@Test
public void testSunnyDayPathLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class);
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
given(methodInvocation.getThis()).willReturn(this);
Logger log = mock(Logger.class);
given(log.isTraceEnabled()).willReturn(true);
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
interceptor.invoke(methodInvocation);
verify(log, times(2)).trace(anyString());
}
use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.
the class LambdaSafeTests method callbackWithLoggerShouldUseLogger.
@Test
@SuppressWarnings("unchecked")
void callbackWithLoggerShouldUseLogger() {
Logger logger = mock(Logger.class);
given(logger.isDebugEnabled()).willReturn(true);
GenericCallback<StringBuilder> callbackInstance = (s) -> fail("Should not get here");
String argument = "foo";
LambdaSafe.callback(GenericCallback.class, callbackInstance, argument).withLogger(logger).invoke((c) -> c.handle(argument));
verify(logger).debug(contains("Non-matching CharSequence type for callback LambdaSafeTests.GenericCallback"), any(Throwable.class));
}
use of cn.taketoday.logging.Logger in project today-framework by TAKETODAY.
the class CustomizableTraceInterceptorTests method testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching.
@Test
public void testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class);
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
given(methodInvocation.getThis()).willReturn(this);
given(methodInvocation.getArguments()).willReturn(new Object[] { "$ One \\$", 2L });
given(methodInvocation.proceed()).willReturn("Hello!");
Logger log = mock(Logger.class);
given(log.isTraceEnabled()).willReturn(true);
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
interceptor.setEnterMessage(new StringBuilder().append("Entering the '").append(CustomizableTraceInterceptor.PLACEHOLDER_METHOD_NAME).append("' method of the [").append(CustomizableTraceInterceptor.PLACEHOLDER_TARGET_CLASS_NAME).append("] class with the following args (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENTS).append(") and arg types (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENT_TYPES).append(").").toString());
interceptor.setExitMessage(new StringBuilder().append("Exiting the '").append(CustomizableTraceInterceptor.PLACEHOLDER_METHOD_NAME).append("' method of the [").append(CustomizableTraceInterceptor.PLACEHOLDER_TARGET_CLASS_SHORT_NAME).append("] class with the following args (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENTS).append(") and arg types (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENT_TYPES).append("), returning '").append(CustomizableTraceInterceptor.PLACEHOLDER_RETURN_VALUE).append("' and taking '").append(CustomizableTraceInterceptor.PLACEHOLDER_INVOCATION_TIME).append("' this long.").toString());
interceptor.invoke(methodInvocation);
verify(log, times(2)).trace(anyString());
}
use of cn.taketoday.logging.Logger in project today-framework by TAKETODAY.
the class CustomizableTraceInterceptorTests method testExceptionPathLogsCorrectly.
@Test
public void testExceptionPathLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class);
IllegalArgumentException exception = new IllegalArgumentException();
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
given(methodInvocation.getThis()).willReturn(this);
given(methodInvocation.proceed()).willThrow(exception);
Logger log = mock(Logger.class);
given(log.isTraceEnabled()).willReturn(true);
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invoke(methodInvocation));
verify(log).trace(anyString());
verify(log).trace(anyString(), eq(exception));
}
use of cn.taketoday.logging.Logger in project today-framework by TAKETODAY.
the class DebugInterceptorTests method testSunnyDayPathLogsCorrectly.
@Test
public void testSunnyDayPathLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class);
Logger log = mock(Logger.class);
given(log.isTraceEnabled()).willReturn(true);
DebugInterceptor interceptor = new StubDebugInterceptor(log);
interceptor.invoke(methodInvocation);
checkCallCountTotal(interceptor);
verify(log, times(2)).trace(anyString());
}
Aggregations