Changeset 18394 in josm for trunk/test
- Timestamp:
- 2022-03-12T08:18:43+01:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java
r18393 r18394 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse;6 5 import static org.junit.jupiter.api.Assertions.assertNull; 7 6 import static org.junit.jupiter.api.Assertions.assertSame; 8 7 import static org.junit.jupiter.api.Assertions.assertTrue; 8 9 import java.util.ArrayList; 9 10 import java.util.Arrays; 11 import java.util.List; 12 import java.util.logging.Handler; 13 import java.util.logging.LogRecord; 10 14 11 15 import org.junit.jupiter.api.BeforeAll; … … 54 58 return LayerPositionStrategy.afterLast(o -> true); 55 59 } 60 } 61 62 protected static class LoggingHandler extends Handler { 63 64 private List<LogRecord> records = new ArrayList<>(); 65 66 @Override 67 public void publish(LogRecord record) { 68 records.add(record); 69 } 70 71 @Override 72 public void flush() {} 73 74 @Override 75 public void close() throws SecurityException {} 76 77 public List<LogRecord> getRecords() { 78 return records; 79 } 80 56 81 } 57 82 … … 146 171 void testAddActiveLayerChangeListenerTwice() { 147 172 CapturingActiveLayerChangeListener listener = new CapturingActiveLayerChangeListener(); 173 LoggingHandler handler = new LoggingHandler(); 174 Logging.getLogger().addHandler(handler); 175 148 176 layerManagerWithActive.addActiveLayerChangeListener(listener); 149 Logging.clearLastErrorAndWarnings(); 177 assertTrue(handler.getRecords().isEmpty()); 178 150 179 layerManagerWithActive.addActiveLayerChangeListener(listener); 151 assertFalse(Logging.getLastErrorAndWarnings().isEmpty()); 180 assertTrue(handler.getRecords().get(1).getMessage().startsWith("Attempted to add listener that was already in list")); 181 182 Logging.getLogger().removeHandler(handler); 152 183 } 153 184 … … 175 206 @Test 176 207 void testRemoveActiveLayerChangeListenerNotInList() { 177 Logging.clearLastErrorAndWarnings(); 208 LoggingHandler handler = new LoggingHandler(); 209 Logging.getLogger().addHandler(handler); 210 178 211 layerManagerWithActive.removeActiveLayerChangeListener(new CapturingActiveLayerChangeListener()); 179 assertFalse(Logging.getLastErrorAndWarnings().isEmpty()); 212 assertTrue(handler.getRecords().get(1).getMessage().startsWith("Attempted to remove listener that was not in list")); 213 214 Logging.getLogger().removeHandler(handler); 180 215 } 181 216
Note:
See TracChangeset
for help on using the changeset viewer.