Skip to content

Commit af2e2d9

Browse files
committed
LogFormatterTest: improve the settings test
We make it reproducible by clearing previously persisted values first. Then check that indeed, the persistence applies (only) where it should.
1 parent a1f1552 commit af2e2d9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/test/java/org/scijava/ui/swing/console/LogFormatterTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,24 @@ public class LogFormatterTest {
1717
@Test
1818
public void testSettings() {
1919
Context context = new Context(PrefService.class);
20-
LogFormatter formatter1 = new LogFormatter(context, "abc");
20+
final String usedKey = "LogFormatterTest-key";
21+
final String nonMatchingKey = "LogFormatterTest-nonmatching";
22+
context.service(PrefService.class).remove(LogFormatter.class, usedKey);
23+
context.service(PrefService.class).remove(LogFormatter.class, nonMatchingKey);
24+
25+
// Assign some settings to a particular key.
26+
LogFormatter formatter1 = new LogFormatter(context, usedKey);
2127
formatter1.setVisible(LogFormatter.Field.ATTACHMENT, true);
2228
formatter1.setVisible(LogFormatter.Field.LEVEL, false);
23-
LogFormatter formatter2 = new LogFormatter(context, "abc");
29+
30+
// Check that matching key does share these settings.
31+
LogFormatter formatter2 = new LogFormatter(context, usedKey);
2432
assertTrue(formatter2.isVisible(LogFormatter.Field.ATTACHMENT));
2533
assertFalse(formatter2.isVisible(LogFormatter.Field.LEVEL));
34+
35+
// Check that non-matching key does not share these settings.
36+
LogFormatter formatter3 = new LogFormatter(context, nonMatchingKey);
37+
assertFalse(formatter3.isVisible(LogFormatter.Field.ATTACHMENT));
38+
assertTrue(formatter3.isVisible(LogFormatter.Field.LEVEL));
2639
}
2740
}

0 commit comments

Comments
 (0)