27
27
import static org .mockito .Mockito .mock ;
28
28
import static org .mockito .Mockito .times ;
29
29
import static org .mockito .Mockito .verify ;
30
+ import static org .springframework .aop .interceptor .CustomizableTraceInterceptor .PLACEHOLDER_ARGUMENTS ;
31
+ import static org .springframework .aop .interceptor .CustomizableTraceInterceptor .PLACEHOLDER_ARGUMENT_TYPES ;
32
+ import static org .springframework .aop .interceptor .CustomizableTraceInterceptor .PLACEHOLDER_EXCEPTION ;
33
+ import static org .springframework .aop .interceptor .CustomizableTraceInterceptor .PLACEHOLDER_INVOCATION_TIME ;
34
+ import static org .springframework .aop .interceptor .CustomizableTraceInterceptor .PLACEHOLDER_METHOD_NAME ;
35
+ import static org .springframework .aop .interceptor .CustomizableTraceInterceptor .PLACEHOLDER_RETURN_VALUE ;
36
+ import static org .springframework .aop .interceptor .CustomizableTraceInterceptor .PLACEHOLDER_TARGET_CLASS_NAME ;
37
+ import static org .springframework .aop .interceptor .CustomizableTraceInterceptor .PLACEHOLDER_TARGET_CLASS_SHORT_NAME ;
30
38
31
39
/**
40
+ * Tests for {@link CustomizableTraceInterceptor}.
41
+ *
32
42
* @author Rob Harrop
33
43
* @author Rick Evans
34
44
* @author Juergen Hoeller
35
45
* @author Chris Beams
46
+ * @author Sam Brannen
36
47
*/
37
- public class CustomizableTraceInterceptorTests {
48
+ class CustomizableTraceInterceptorTests {
49
+
50
+ private final CustomizableTraceInterceptor interceptor = new CustomizableTraceInterceptor ();
51
+
38
52
39
53
@ Test
40
- public void testSetEmptyEnterMessage () {
54
+ void setEmptyEnterMessage () {
41
55
// Must not be able to set empty enter message
42
- assertThatIllegalArgumentException ().isThrownBy (() ->
43
- new CustomizableTraceInterceptor ().setEnterMessage ("" ));
56
+ assertThatIllegalArgumentException ().isThrownBy (() -> interceptor .setEnterMessage ("" ));
44
57
}
45
58
46
59
@ Test
47
- public void testSetEnterMessageWithReturnValuePlaceholder () {
60
+ void setEnterMessageWithReturnValuePlaceholder () {
48
61
// Must not be able to set enter message with return value placeholder
49
- assertThatIllegalArgumentException ().isThrownBy (() ->
50
- new CustomizableTraceInterceptor ().setEnterMessage (CustomizableTraceInterceptor .PLACEHOLDER_RETURN_VALUE ));
62
+ assertThatIllegalArgumentException ().isThrownBy (() -> interceptor .setEnterMessage (PLACEHOLDER_RETURN_VALUE ));
51
63
}
52
64
53
65
@ Test
54
- public void testSetEnterMessageWithExceptionPlaceholder () {
66
+ void setEnterMessageWithExceptionPlaceholder () {
55
67
// Must not be able to set enter message with exception placeholder
56
- assertThatIllegalArgumentException ().isThrownBy (() ->
57
- new CustomizableTraceInterceptor ().setEnterMessage (CustomizableTraceInterceptor .PLACEHOLDER_EXCEPTION ));
68
+ assertThatIllegalArgumentException ().isThrownBy (() -> interceptor .setEnterMessage (PLACEHOLDER_EXCEPTION ));
58
69
}
59
70
60
71
@ Test
61
- public void testSetEnterMessageWithInvocationTimePlaceholder () {
72
+ void setEnterMessageWithInvocationTimePlaceholder () {
62
73
// Must not be able to set enter message with invocation time placeholder
63
- assertThatIllegalArgumentException ().isThrownBy (() ->
64
- new CustomizableTraceInterceptor ().setEnterMessage (CustomizableTraceInterceptor .PLACEHOLDER_INVOCATION_TIME ));
74
+ assertThatIllegalArgumentException ().isThrownBy (() -> interceptor .setEnterMessage (PLACEHOLDER_INVOCATION_TIME ));
65
75
}
66
76
67
77
@ Test
68
- public void testSetEmptyExitMessage () {
78
+ void setEmptyExitMessage () {
69
79
// Must not be able to set empty exit message
70
- assertThatIllegalArgumentException ().isThrownBy (() ->
71
- new CustomizableTraceInterceptor ().setExitMessage ("" ));
80
+ assertThatIllegalArgumentException ().isThrownBy (() -> interceptor .setExitMessage ("" ));
72
81
}
73
82
74
83
@ Test
75
- public void testSetExitMessageWithExceptionPlaceholder () {
84
+ void setExitMessageWithExceptionPlaceholder () {
76
85
// Must not be able to set exit message with exception placeholder
77
- assertThatIllegalArgumentException ().isThrownBy (() ->
78
- new CustomizableTraceInterceptor ().setExitMessage (CustomizableTraceInterceptor .PLACEHOLDER_EXCEPTION ));
86
+ assertThatIllegalArgumentException ().isThrownBy (() -> interceptor .setExitMessage (PLACEHOLDER_EXCEPTION ));
79
87
}
80
88
81
89
@ Test
82
- public void testSetEmptyExceptionMessage () {
90
+ void setEmptyExceptionMessage () {
83
91
// Must not be able to set empty exception message
84
- assertThatIllegalArgumentException ().isThrownBy (() ->
85
- new CustomizableTraceInterceptor ().setExceptionMessage ("" ));
92
+ assertThatIllegalArgumentException ().isThrownBy (() -> interceptor .setExceptionMessage ("" ));
86
93
}
87
94
88
95
@ Test
89
- public void testSetExceptionMethodWithReturnValuePlaceholder () {
96
+ void setExceptionMethodWithReturnValuePlaceholder () {
90
97
// Must not be able to set exception message with return value placeholder
91
- assertThatIllegalArgumentException ().isThrownBy (() ->
92
- new CustomizableTraceInterceptor ().setExceptionMessage (CustomizableTraceInterceptor .PLACEHOLDER_RETURN_VALUE ));
98
+ assertThatIllegalArgumentException ().isThrownBy (() -> interceptor .setExceptionMessage (PLACEHOLDER_RETURN_VALUE ));
93
99
}
94
100
95
101
@ Test
96
- public void testSunnyDayPathLogsCorrectly () throws Throwable {
102
+ void sunnyDayPathLogsCorrectly () throws Throwable {
97
103
MethodInvocation methodInvocation = mock ();
98
104
given (methodInvocation .getMethod ()).willReturn (String .class .getMethod ("toString" ));
99
105
given (methodInvocation .getThis ()).willReturn (this );
@@ -108,7 +114,7 @@ public void testSunnyDayPathLogsCorrectly() throws Throwable {
108
114
}
109
115
110
116
@ Test
111
- public void testExceptionPathLogsCorrectly () throws Throwable {
117
+ void exceptionPathLogsCorrectly () throws Throwable {
112
118
MethodInvocation methodInvocation = mock ();
113
119
114
120
IllegalArgumentException exception = new IllegalArgumentException ();
@@ -120,15 +126,14 @@ public void testExceptionPathLogsCorrectly() throws Throwable {
120
126
given (log .isTraceEnabled ()).willReturn (true );
121
127
122
128
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor (log );
123
- assertThatIllegalArgumentException ().isThrownBy (() ->
124
- interceptor .invoke (methodInvocation ));
129
+ assertThatIllegalArgumentException ().isThrownBy (() -> interceptor .invoke (methodInvocation ));
125
130
126
131
verify (log ).trace (anyString ());
127
132
verify (log ).trace (anyString (), eq (exception ));
128
133
}
129
134
130
135
@ Test
131
- public void testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching () throws Throwable {
136
+ void sunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching () throws Throwable {
132
137
MethodInvocation methodInvocation = mock ();
133
138
134
139
given (methodInvocation .getMethod ()).willReturn (String .class .getMethod ("toString" , new Class [0 ]));
@@ -141,18 +146,18 @@ public void testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching()
141
146
142
147
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor (log );
143
148
interceptor .setEnterMessage (new StringBuilder ()
144
- .append ("Entering the '" ).append (CustomizableTraceInterceptor . PLACEHOLDER_METHOD_NAME )
145
- .append ("' method of the [" ).append (CustomizableTraceInterceptor . PLACEHOLDER_TARGET_CLASS_NAME )
146
- .append ("] class with the following args (" ).append (CustomizableTraceInterceptor . PLACEHOLDER_ARGUMENTS )
147
- .append (") and arg types (" ).append (CustomizableTraceInterceptor . PLACEHOLDER_ARGUMENT_TYPES )
149
+ .append ("Entering the '" ).append (PLACEHOLDER_METHOD_NAME )
150
+ .append ("' method of the [" ).append (PLACEHOLDER_TARGET_CLASS_NAME )
151
+ .append ("] class with the following args (" ).append (PLACEHOLDER_ARGUMENTS )
152
+ .append (") and arg types (" ).append (PLACEHOLDER_ARGUMENT_TYPES )
148
153
.append (")." ).toString ());
149
154
interceptor .setExitMessage (new StringBuilder ()
150
- .append ("Exiting the '" ).append (CustomizableTraceInterceptor . PLACEHOLDER_METHOD_NAME )
151
- .append ("' method of the [" ).append (CustomizableTraceInterceptor . PLACEHOLDER_TARGET_CLASS_SHORT_NAME )
152
- .append ("] class with the following args (" ).append (CustomizableTraceInterceptor . PLACEHOLDER_ARGUMENTS )
153
- .append (") and arg types (" ).append (CustomizableTraceInterceptor . PLACEHOLDER_ARGUMENT_TYPES )
154
- .append ("), returning '" ).append (CustomizableTraceInterceptor . PLACEHOLDER_RETURN_VALUE )
155
- .append ("' and taking '" ).append (CustomizableTraceInterceptor . PLACEHOLDER_INVOCATION_TIME )
155
+ .append ("Exiting the '" ).append (PLACEHOLDER_METHOD_NAME )
156
+ .append ("' method of the [" ).append (PLACEHOLDER_TARGET_CLASS_SHORT_NAME )
157
+ .append ("] class with the following args (" ).append (PLACEHOLDER_ARGUMENTS )
158
+ .append (") and arg types (" ).append (PLACEHOLDER_ARGUMENT_TYPES )
159
+ .append ("), returning '" ).append (PLACEHOLDER_RETURN_VALUE )
160
+ .append ("' and taking '" ).append (PLACEHOLDER_INVOCATION_TIME )
156
161
.append ("' this long." ).toString ());
157
162
interceptor .invoke (methodInvocation );
158
163
@@ -165,7 +170,7 @@ private static class StubCustomizableTraceInterceptor extends CustomizableTraceI
165
170
166
171
private final Log log ;
167
172
168
- public StubCustomizableTraceInterceptor (Log log ) {
173
+ StubCustomizableTraceInterceptor (Log log ) {
169
174
super .setUseDynamicLogger (false );
170
175
this .log = log ;
171
176
}
0 commit comments