19
19
20
20
import static org .apache .hop .core .logging .LogLevel .BASIC ;
21
21
import static org .apache .hop .core .logging .LogLevel .ERROR ;
22
+ import static org .mockito .Mockito .lenient ;
22
23
import static org .mockito .Mockito .verify ;
23
24
import static org .mockito .Mockito .verifyNoInteractions ;
24
25
import static org .mockito .Mockito .when ;
25
26
26
27
import java .util .function .Function ;
27
- import org .junit .Before ;
28
- import org .junit .Test ;
29
- import org .junit .runner . RunWith ;
28
+ import org .junit .jupiter . api . BeforeEach ;
29
+ import org .junit .jupiter . api . Test ;
30
+ import org .junit .jupiter . api . extension . ExtendWith ;
30
31
import org .mockito .Mock ;
31
- import org .mockito .junit .MockitoJUnitRunner ;
32
+ import org .mockito .junit .jupiter . MockitoExtension ;
32
33
import org .slf4j .Logger ;
33
34
34
- @ RunWith ( MockitoJUnitRunner .class )
35
- public class Slf4jLoggingEventListenerTest {
35
+ @ ExtendWith ( MockitoExtension .class )
36
+ class Slf4jLoggingEventListenerTest {
36
37
37
- @ Mock private Logger pipelineLogger , jobLogger , diLogger ;
38
+ @ Mock private Logger pipelineLogger , workflowLogger , hopLogger ;
38
39
@ Mock private HopLoggingEvent logEvent ;
39
40
@ Mock private ILoggingObject loggingObject ;
40
41
@ Mock private LogMessage message ;
@@ -47,61 +48,61 @@ public class Slf4jLoggingEventListenerTest {
47
48
48
49
private Slf4jLoggingEventListener listener = new Slf4jLoggingEventListener ();
49
50
50
- @ Before
51
- public void before () {
51
+ @ BeforeEach
52
+ void before () {
52
53
listener .pipelineLogger = pipelineLogger ;
53
- listener .jobLogger = jobLogger ;
54
- listener .diLogger = diLogger ;
54
+ listener .workflowLogger = workflowLogger ;
55
+ listener .hopLogger = hopLogger ;
55
56
listener .logObjProvider = logObjProvider ;
56
- when (logEvent .getMessage ()).thenReturn (message );
57
- when (message .getLogChannelId ()).thenReturn (logChannelId );
58
- when (message .getLevel ()).thenReturn (logLevel );
59
- when (message .getMessage ()).thenReturn (msgText );
60
- when (message .getSubject ()).thenReturn (messageSub );
57
+ lenient (). when (logEvent .getMessage ()).thenReturn (message );
58
+ lenient (). when (message .getLogChannelId ()).thenReturn (logChannelId );
59
+ lenient (). when (message .getLevel ()).thenReturn (logLevel );
60
+ lenient (). when (message .getMessage ()).thenReturn (msgText );
61
+ lenient (). when (message .getSubject ()).thenReturn (messageSub );
61
62
}
62
63
63
64
@ Test
64
- public void testAddLogEventNoRegisteredLogObject () {
65
+ void testAddLogEventNoRegisteredLogObject () {
65
66
listener .eventAdded (logEvent );
66
- verify (diLogger ).info (messageSub + " " + msgText );
67
+ verify (hopLogger ).info (String . format ( "%s %s" , messageSub , msgText ) );
67
68
68
69
when (message .getLevel ()).thenReturn (ERROR );
69
70
listener .eventAdded (logEvent );
70
- verify (diLogger ).error (messageSub + " " + msgText );
71
+ verify (hopLogger ).error (String . format ( "%s %s" , messageSub , msgText ) );
71
72
verifyNoInteractions (pipelineLogger );
72
- verifyNoInteractions (jobLogger );
73
+ verifyNoInteractions (workflowLogger );
73
74
}
74
75
75
76
@ Test
76
- public void testAddLogEventPipeline () {
77
+ void testAddLogEventPipeline () {
77
78
when (logObjProvider .apply (logChannelId )).thenReturn (loggingObject );
78
79
when (loggingObject .getObjectType ()).thenReturn (LoggingObjectType .PIPELINE );
79
80
when (loggingObject .getFilename ()).thenReturn ("filename" );
80
81
when (message .getLevel ()).thenReturn (LogLevel .BASIC );
81
82
listener .eventAdded (logEvent );
82
83
83
- verify (pipelineLogger ).info ("[filename] " + msgText );
84
+ verify (pipelineLogger ).info (String . format ( "[filename] %s" , msgText ) );
84
85
when (message .getLevel ()).thenReturn (LogLevel .ERROR );
85
86
listener .eventAdded (logEvent );
86
- verify (pipelineLogger ).error ("[filename] " + msgText );
87
- verifyNoInteractions (diLogger );
88
- verifyNoInteractions (jobLogger );
87
+ verify (pipelineLogger ).error (String . format ( "[filename] %s" , msgText ) );
88
+ verifyNoInteractions (hopLogger );
89
+ verifyNoInteractions (workflowLogger );
89
90
}
90
91
91
92
@ Test
92
- public void testAddLogEventJob () {
93
+ void testAddLogEventJob () {
93
94
when (logObjProvider .apply (logChannelId )).thenReturn (loggingObject );
94
95
when (loggingObject .getObjectType ()).thenReturn (LoggingObjectType .WORKFLOW );
95
96
when (loggingObject .getFilename ()).thenReturn ("filename" );
96
97
when (message .getLevel ()).thenReturn (LogLevel .BASIC );
97
98
listener .eventAdded (logEvent );
98
99
99
- verify (jobLogger ).info ("[filename] " + msgText );
100
+ verify (workflowLogger ).info (String . format ( "[filename] %s" , msgText ) );
100
101
101
102
when (message .getLevel ()).thenReturn (LogLevel .ERROR );
102
103
listener .eventAdded (logEvent );
103
- verify (jobLogger ).error ("[filename] " + msgText );
104
- verifyNoInteractions (diLogger );
104
+ verify (workflowLogger ).error (String . format ( "[filename] %s" , msgText ) );
105
+ verifyNoInteractions (hopLogger );
105
106
verifyNoInteractions (pipelineLogger );
106
107
}
107
108
}
0 commit comments