package jmri.jmrit.beantable.signalmast; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import jmri.util.JUnitUtil; import java.util.*; import org.junit.jupiter.api.*; /** * Tests the overall operation of {@link SignalMastAddPane} services. *

* See {@link AbstractSignalMastAddPaneTestBase} for the base-class of the * tests of individual implementations of {@link SignalMastAddPane} subclasses. * of * @author Bob Jacobsen Copyright 2018 */ public class SignalMastAddPaneTest { @Test public void testLoad() { // group these in a single test, as the services can only be loaded once. assertNotNull(SignalMastAddPane.SignalMastAddPaneProvider.getInstancesCollection()); assertNotNull(SignalMastAddPane.SignalMastAddPaneProvider.getInstancesMap()); assertFalse(SignalMastAddPane.SignalMastAddPaneProvider.getInstancesMap().isEmpty()); // found at least one service assertEquals(SignalMastAddPane.SignalMastAddPaneProvider.getInstancesMap().size(), SignalMastAddPane.SignalMastAddPaneProvider.getInstancesCollection().size()); // same size // check map is in sorted order; also check lookup works Map map = SignalMastAddPane.SignalMastAddPaneProvider.getInstancesMap(); Collection collection = SignalMastAddPane.SignalMastAddPaneProvider.getInstancesCollection(); String last = ""; for ( Map.Entry entry : map.entrySet() ) { String name = entry.getKey(); assertTrue(name.compareTo(last) > 0); // no identical ones assertTrue(collection.contains(map.get(name))); last = name; } // check collection in in sorted order last = ""; for (SignalMastAddPane.SignalMastAddPaneProvider pane : collection) { assertTrue(pane.getPaneName().compareTo(last) > 0); // no identical ones last = pane.getPaneName(); } // partial check that results are unmodifiable UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class, () -> { SignalMastAddPane.SignalMastAddPaneProvider.getInstancesMap().put("Foo", null); fail("Should have thrown"); }); assertNotNull(e); e = assertThrows(UnsupportedOperationException.class, () -> { SignalMastAddPane.SignalMastAddPaneProvider.getInstancesCollection().add(null); fail("Should have thrown"); }); assertNotNull(e); // check all the classes for (SignalMastAddPane.SignalMastAddPaneProvider pane : collection) { assertFalse( pane.getPaneName().isBlank()); if (pane.isAvailable()) { assertFalse(pane.getPaneName().isBlank()); } } } @BeforeEach public void setUp() { JUnitUtil.setUp(); JUnitUtil.initDefaultUserMessagePreferences(); } @AfterEach public void tearDown() { JUnitUtil.tearDown(); } }