42
42
import static org .mockito .ArgumentMatchers .anyString ;
43
43
import static org .mockito .ArgumentMatchers .same ;
44
44
import static org .mockito .Mockito .atLeast ;
45
+ import static org .mockito .Mockito .never ;
45
46
import static org .mockito .Mockito .times ;
46
47
47
48
public class ProgressTest {
@@ -51,12 +52,32 @@ public static void setup() {
51
52
RuntimeEnvironment .getInstance ().setPrintProgress (true );
52
53
}
53
54
55
+ /**
56
+ * Very rudimentary test for log level shifting.
57
+ */
54
58
@ Test
55
- void testShifting () {
59
+ void testShifting () throws InterruptedException {
60
+ Level logLevel = Level .FINE ;
61
+ final int totalCount = 100 ;
62
+
56
63
final Logger logger = Mockito .mock (Logger .class );
57
- try (Progress progress = new Progress (logger , "xxx" )) {
58
- assertNotNull (progress );
64
+ Mockito .when (logger .isLoggable (same (Level .INFO ))).thenReturn (false );
65
+ Mockito .when (logger .isLoggable (same (Level .FINE ))).thenReturn (true );
66
+ Mockito .when (logger .isLoggable (same (Level .FINER ))).thenReturn (true );
67
+ Mockito .when (logger .isLoggable (same (Level .FINEST ))).thenReturn (true );
68
+
69
+ try (Progress progress = new Progress (logger , "shifting" , logLevel )) {
70
+ for (int i = 0 ; i < totalCount ; i ++) {
71
+ progress .increment ();
72
+ // Give the logger thread some time to log.
73
+ TimeUnit .MILLISECONDS .sleep (10 );
74
+ }
59
75
}
76
+
77
+ Mockito .verify (logger , never ()).log (same (Level .INFO ), anyString ());
78
+ Mockito .verify (logger , atLeast (1 )).log (same (Level .FINE ), anyString ());
79
+ Mockito .verify (logger , atLeast (1 )).log (same (Level .FINER ), anyString ());
80
+ Mockito .verify (logger , atLeast (1 )).log (same (Level .FINEST ), anyString ());
60
81
}
61
82
62
83
@ Test
0 commit comments