Skip to content

Commit 6ad8c08

Browse files
committed
add basic test
1 parent dd112ce commit 6ad8c08

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/util/ProgressTest.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import static org.mockito.ArgumentMatchers.anyString;
4343
import static org.mockito.ArgumentMatchers.same;
4444
import static org.mockito.Mockito.atLeast;
45+
import static org.mockito.Mockito.never;
4546
import static org.mockito.Mockito.times;
4647

4748
public class ProgressTest {
@@ -51,12 +52,32 @@ public static void setup() {
5152
RuntimeEnvironment.getInstance().setPrintProgress(true);
5253
}
5354

55+
/**
56+
* Very rudimentary test for log level shifting.
57+
*/
5458
@Test
55-
void testShifting() {
59+
void testShifting() throws InterruptedException {
60+
Level logLevel = Level.FINE;
61+
final int totalCount = 100;
62+
5663
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+
}
5975
}
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());
6081
}
6182

6283
@Test

0 commit comments

Comments
 (0)