diff options
Diffstat (limited to 'framework/src/onos/core/api/src/test')
18 files changed, 135 insertions, 41 deletions
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java index d31cc268..34c593c4 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java @@ -33,7 +33,7 @@ public class ApplicationEventTest extends AbstractEventTest { private Application createApp() { return new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); } @Test diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java b/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java index 479cc59a..96324a91 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java @@ -51,6 +51,10 @@ public class ApplicationServiceAdapter implements ApplicationService { } @Override + public void registerDeactivateHook(ApplicationId appId, Runnable hook) { + } + + @Override public void addListener(ApplicationListener listener) { } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java index d40d3fea..0e93c1fe 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java @@ -46,12 +46,13 @@ public class DefaultApplicationDescriptionTest { new Permission(AppPermission.class.getName(), "FLOWRULE_READ")); public static final URI FURL = URI.create("mvn:org.foo-features/1.2a/xml/features"); public static final List<String> FEATURES = ImmutableList.of("foo", "bar"); + public static final List<String> APPS = ImmutableList.of("fifi"); @Test public void basics() { ApplicationDescription app = new DefaultApplicationDescription(APP_NAME, VER, DESC, ORIGIN, - ROLE, PERMS, FURL, FEATURES); + ROLE, PERMS, FURL, FEATURES, APPS); assertEquals("incorrect id", APP_NAME, app.name()); assertEquals("incorrect version", VER, app.version()); assertEquals("incorrect description", DESC, app.description()); @@ -60,6 +61,7 @@ public class DefaultApplicationDescriptionTest { assertEquals("incorrect permissions", PERMS, app.permissions()); assertEquals("incorrect features repo", FURL, app.featuresRepo().get()); assertEquals("incorrect features", FEATURES, app.features()); + assertEquals("incorrect apps", APPS, app.requiredApps()); assertTrue("incorrect toString", app.toString().contains(APP_NAME)); } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/core/CoreServiceAdapter.java b/framework/src/onos/core/api/src/test/java/org/onosproject/core/CoreServiceAdapter.java index 0f6abd68..6d45e8c5 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/core/CoreServiceAdapter.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/core/CoreServiceAdapter.java @@ -43,7 +43,12 @@ public class CoreServiceAdapter implements CoreService { } @Override - public ApplicationId registerApplication(String identifier) { + public ApplicationId registerApplication(String name) { + return null; + } + + @Override + public ApplicationId registerApplication(String name, Runnable preDeactivate) { return null; } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java index cbedb79c..77b3812b 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java @@ -34,7 +34,7 @@ public class DefaultApplicationTest { @Test public void basics() { Application app = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); assertEquals("incorrect id", APP_ID, app.id()); assertEquals("incorrect version", VER, app.version()); assertEquals("incorrect description", DESC, app.description()); @@ -43,19 +43,20 @@ public class DefaultApplicationTest { assertEquals("incorrect permissions", PERMS, app.permissions()); assertEquals("incorrect features repo", FURL, app.featuresRepo().get()); assertEquals("incorrect features", FEATURES, app.features()); + assertEquals("incorrect apps", APPS, app.requiredApps()); assertTrue("incorrect toString", app.toString().contains(APP_NAME)); } @Test public void testEquality() { Application a1 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); Application a2 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); Application a3 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.empty(), FEATURES); + PERMS, Optional.empty(), FEATURES, APPS); Application a4 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN + "asd", ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); new EqualsTester().addEqualityGroup(a1, a2) .addEqualityGroup(a3).addEqualityGroup(a4).testEquals(); } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/PortNumberTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/PortNumberTest.java index 6f7b2c2d..de153dc2 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/PortNumberTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/PortNumberTest.java @@ -15,12 +15,17 @@ */ package org.onosproject.net; +import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; import org.junit.Test; +import org.onosproject.net.PortNumber.Logical; +import static java.util.stream.Collectors.toList; import static org.junit.Assert.assertEquals; import static org.onosproject.net.PortNumber.portNumber; +import java.util.List; + /** * Test of the port number. */ @@ -39,5 +44,37 @@ public class PortNumberTest { assertEquals("incorrect long value", 12345, portNumber(12345).toLong()); } + @Test + public void decimalPortNumberIsReconstructableFromString() { + List<PortNumber> ps = ImmutableList.<PortNumber>builder() + .add(portNumber(0)) + .add(portNumber(1)) + .add(portNumber(6653)) + .add(portNumber(PortNumber.MAX_NUMBER)) + .build(); + ps.forEach(p -> assertEquals(p, PortNumber.fromString(p.toString()))); + } + + @Test + public void logicalPortNumberIsReconstructableFromString() { + List<PortNumber> ps = ImmutableList.copyOf(Logical.values()) + .stream().map(Logical::instance).collect(toList()); + + ps.forEach(p -> assertEquals(p, PortNumber.fromString(p.toString()))); + + PortNumber unknown = portNumber(-42); + assertEquals(unknown, PortNumber.fromString(unknown.toString())); + } + + @Test + public void namedPortNumberIsReconstructableFromString() { + List<PortNumber> ps = ImmutableList.<PortNumber>builder() + .add(portNumber(0, "Zero")) + .add(portNumber(1, "[ONE]")) + .add(portNumber(6653, "OpenFlow (1.3+)")) + .add(portNumber(PortNumber.MAX_NUMBER, "(大)")) + .build(); + ps.forEach(p -> assertEquals(p, PortNumber.fromString(p.toString()))); + } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java index 3dcdc22d..c00a6de0 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java @@ -41,7 +41,7 @@ public class DefaultDeviceDescriptionTest { public void basics() { DeviceDescription device = new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN, CID); - assertEquals("incorrect uri", DURI, device.deviceURI()); + assertEquals("incorrect uri", DURI, device.deviceUri()); assertEquals("incorrect type", SWITCH, device.type()); assertEquals("incorrect manufacturer", MFR, device.manufacturer()); assertEquals("incorrect hw", HW, device.hwVersion()); diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java index f54e7411..15abc2bf 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java @@ -57,7 +57,7 @@ public class XmlDriverLoaderTest { } @Test(expected = IOException.class) - public void badXML() throws IOException { + public void badXml() throws IOException { XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader()); loader.loadDrivers(getClass().getResourceAsStream("drivers.bad.xml"), null); } @@ -77,4 +77,4 @@ public class XmlDriverLoaderTest { driver.createBehaviour(new DefaultDriverData(driver, DEVICE_ID), TestBehaviour.class); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java index e03ed850..c510b60a 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java @@ -33,6 +33,7 @@ import org.onosproject.net.flow.TrafficTreatment; public abstract class ConnectivityIntentTest extends IntentTest { public static final ApplicationId APPID = new TestApplicationId("foo"); + public static final Key KEY = Key.of(1L, APPID); public static final IntentId IID = new IntentId(123); public static final TrafficSelector MATCH = DefaultTrafficSelector.emptySelector(); diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java index d42e22fa..14201472 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java @@ -192,14 +192,17 @@ public class IntentTestsMocks { new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); } + @Override public IntentId intentId() { return null; } + @Override public Collection<Link> links() { return null; } + @Override public Set<ResourceRequest> resources() { return null; } @@ -408,7 +411,7 @@ public class IntentTestsMocks { @Override public int hashCode() { - return Objects.hash(priority); + return priority; } @Override diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java index 196d6ad4..7fbdf232 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java @@ -112,6 +112,5 @@ public class MplsIntentTest extends AbstractIntentTest { assertThat(intent1.selector(), equalTo(intent2.selector())); assertThat(intent1.treatment(), equalTo(intent2.treatment())); assertThat(intent1.priority(), is(PRIORITY)); - } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java index 551f19eb..64528cb9 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java @@ -47,6 +47,7 @@ public class MplsPathIntentTest extends AbstractIntentTest { Optional<MplsLabel> label2; TrafficSelector selector; TrafficTreatment treatment; + static final Key KEY1 = Key.of(5L, APP_ID); @Before public void mplsPathIntentTestSetUp() { @@ -58,6 +59,7 @@ public class MplsPathIntentTest extends AbstractIntentTest { label2 = Optional.of(MplsLabel.mplsLabel(2)); intent1 = MplsPathIntent.builder() .appId(APP_ID) + .key(KEY1) .ingressLabel(label1) .egressLabel(label2) .path(defaultPath) @@ -105,6 +107,7 @@ public class MplsPathIntentTest extends AbstractIntentTest { assertThat(intent1.treatment(), equalTo(intent2.treatment())); assertThat(intent1.priority(), is(PRIORITY)); assertThat(intent1.path(), is(defaultPath)); + assertThat(intent1.key(), equalTo(KEY1)); } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java index dfbc1846..9e675347 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java @@ -62,12 +62,14 @@ public class PathIntentTest extends ConnectivityIntentTest { assertEquals("incorrect match", MATCH, intent.selector()); assertEquals("incorrect action", NOP, intent.treatment()); assertEquals("incorrect path", PATH1, intent.path()); + assertEquals("incorrect key", KEY, intent.key()); } @Override protected PathIntent createOne() { return PathIntent.builder() .appId(APPID) + .key(KEY) .selector(MATCH) .treatment(NOP) .path(PATH1) diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java index a84927a0..5f448221 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java @@ -38,9 +38,9 @@ public class ResourceAllocationTest { @Test public void testEquals() { - ResourceAllocation alloc1 = new ResourceAllocation(new ResourcePath(LK1, VLAN1), IID1); - ResourceAllocation sameAsAlloc1 = new ResourceAllocation(new ResourcePath(LK1, VLAN1), IID1); - ResourceAllocation alloc2 = new ResourceAllocation(new ResourcePath(LK2, VLAN1), IID1); + ResourceAllocation alloc1 = new ResourceAllocation(ResourcePath.discrete(LK1, VLAN1), IID1); + ResourceAllocation sameAsAlloc1 = new ResourceAllocation(ResourcePath.discrete(LK1, VLAN1), IID1); + ResourceAllocation alloc2 = new ResourceAllocation(ResourcePath.discrete(LK2, VLAN1), IID1); new EqualsTester() .addEqualityGroup(alloc1, sameAsAlloc1) diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java index 4a8886a4..35dcf1ec 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java @@ -18,6 +18,7 @@ package org.onosproject.net.newresource; import com.google.common.testing.EqualsTester; import org.junit.Test; import org.onlab.packet.VlanId; +import org.onlab.util.Bandwidth; import org.onosproject.net.ConnectPoint; import org.onosproject.net.DeviceId; import org.onosproject.net.LinkKey; @@ -25,6 +26,7 @@ import org.onosproject.net.PortNumber; import java.util.Optional; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -36,37 +38,49 @@ public class ResourcePathTest { private static final ConnectPoint CP1_1 = new ConnectPoint(D1, P1); private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1); private static final VlanId VLAN1 = VlanId.vlanId((short) 100); + private static final Bandwidth BW1 = Bandwidth.gbps(2); + private static final Bandwidth BW2 = Bandwidth.gbps(1); @Test public void testEquals() { - ResourcePath resource1 = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); - ResourcePath sameAsResource1 = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); - ResourcePath resource2 = new ResourcePath(LinkKey.linkKey(CP2_1, CP1_1), VLAN1); + ResourcePath resource1 = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); + ResourcePath sameAsResource1 = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); + ResourcePath resource2 = ResourcePath.discrete(LinkKey.linkKey(CP2_1, CP1_1), VLAN1); + ResourcePath resource3 = ResourcePath.continuous(BW1.bps(), LinkKey.linkKey(CP1_1, CP2_1), BW1); + ResourcePath sameAsResource3 = ResourcePath.continuous(BW2.bps(), LinkKey.linkKey(CP1_1, CP2_1), BW1); new EqualsTester() .addEqualityGroup(resource1, sameAsResource1) .addEqualityGroup(resource2) + .addEqualityGroup(resource3, sameAsResource3) // this is intentional .testEquals(); } @Test public void testCreateWithZeroComponent() { - ResourcePath path = new ResourcePath(); + ResourcePath path = ResourcePath.discrete(); assertThat(path, is(ResourcePath.ROOT)); } @Test + public void testComponents() { + ResourcePath port = ResourcePath.discrete(D1, P1); + + assertThat(port.components(), contains(D1, P1)); + } + + @Test public void testThereIsParent() { - ResourcePath path = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); - ResourcePath parent = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1)); + ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); + ResourcePath parent = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1)); assertThat(path.parent(), is(Optional.of(parent))); } @Test public void testNoParent() { - ResourcePath path = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1)); + ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1)); assertThat(path.parent(), is(Optional.of(ResourcePath.ROOT))); } @@ -74,9 +88,9 @@ public class ResourcePathTest { @Test public void testBase() { LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1); - ResourcePath path = new ResourcePath(linkKey); + ResourcePath path = ResourcePath.discrete(linkKey); - LinkKey child = (LinkKey) path.lastComponent(); + LinkKey child = (LinkKey) path.last(); assertThat(child, is(linkKey)); } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/store/service/TestEventuallyConsistentMap.java b/framework/src/onos/core/api/src/test/java/org/onosproject/store/service/TestEventuallyConsistentMap.java index 4f612de2..02462e85 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/store/service/TestEventuallyConsistentMap.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/store/service/TestEventuallyConsistentMap.java @@ -30,7 +30,8 @@ import org.onlab.util.KryoNamespace; import org.onosproject.cluster.NodeId; import org.onosproject.store.Timestamp; -import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.*; +import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; +import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE; /** * Testing version of an Eventually Consistent Map. diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java index d77c1b2b..b870d483 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java @@ -115,19 +115,19 @@ public class DefaultCellComparatorTest { } @Test - public void swEpisodeII() { + public void swEpisodeIi() { assertTrue("r2d2 c3po", cmp.compare(SmallStarWars.R2D2, SmallStarWars.C3PO) > 0); } @Test - public void swEpisodeIII() { + public void swEpisodeIii() { assertTrue("luke c3po", cmp.compare(SmallStarWars.LUKE, SmallStarWars.C3PO) > 0); } @Test - public void swEpisodeIV() { + public void swEpisodeIv() { assertTrue("c3po luke", cmp.compare(SmallStarWars.C3PO, SmallStarWars.LUKE) < 0); } @@ -139,7 +139,7 @@ public class DefaultCellComparatorTest { } @Test - public void swEpisodeVI() { + public void swEpisodeVi() { assertTrue("r2d2 luke", cmp.compare(SmallStarWars.R2D2, SmallStarWars.LUKE) < 0); } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java index 7e6cc227..b6d32bed 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java @@ -20,17 +20,38 @@ import org.junit.BeforeClass; import org.junit.Test; import org.onosproject.ui.topo.PropertyPanel.Prop; +import java.text.NumberFormat; import java.util.HashMap; import java.util.Iterator; +import java.util.Locale; import java.util.Map; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; /** * Unit tests for {@link PropertyPanel}. */ public class PropertyPanelTest { + // Modified property panel subclass to use ENGLISH locale formatter so + // we know formatted numbers will use comma for the thousand separator. + private static final class EnglishPropertyPanel extends PropertyPanel { + private static final NumberFormat ENGLISH_FORMATTER = + NumberFormat.getInstance(Locale.ENGLISH); + + public EnglishPropertyPanel(String title, String typeId) { + super(title, typeId); + } + + @Override + protected NumberFormat formatter() { + return ENGLISH_FORMATTER; + } + } + private static final String TITLE_ORIG = "Original Title"; private static final String TYPE_ORIG = "Original type ID"; private static final String TITLE_NEW = "New Title"; @@ -42,6 +63,7 @@ public class PropertyPanelTest { private static final String KEY_C = "C"; private static final String SEP = "-"; private static final String KEY_Z = "Z"; + private static final String VALUE_A = "Hay"; private static final String VALUE_B = "Bee"; private static final String VALUE_C = "Sea"; @@ -76,7 +98,7 @@ public class PropertyPanelTest { @Test public void basic() { - pp = new PropertyPanel(TITLE_ORIG, TYPE_ORIG); + pp = new EnglishPropertyPanel(TITLE_ORIG, TYPE_ORIG); assertEquals("wrong title", TITLE_ORIG, pp.title()); assertEquals("wrong type", TYPE_ORIG, pp.typeId()); assertNull("id?", pp.id()); @@ -134,8 +156,8 @@ public class PropertyPanelTest { public void props() { basic(); pp.addProp(KEY_A, VALUE_A) - .addProp(KEY_B, VALUE_B) - .addProp(KEY_C, VALUE_C); + .addProp(KEY_B, VALUE_B) + .addProp(KEY_C, VALUE_C); assertEquals("bad props", 3, pp.properties().size()); validateProps(KEY_A, KEY_B, KEY_C); } @@ -144,7 +166,7 @@ public class PropertyPanelTest { public void separator() { props(); pp.addSeparator() - .addProp(KEY_Z, VALUE_Z); + .addProp(KEY_Z, VALUE_Z); assertEquals("bad props", 5, pp.properties().size()); validateProps(KEY_A, KEY_B, KEY_C, SEP, KEY_Z); @@ -170,8 +192,8 @@ public class PropertyPanelTest { public void intValues() { basic(); pp.addProp(KEY_A, 200) - .addProp(KEY_B, 2000) - .addProp(KEY_C, 1234567); + .addProp(KEY_B, 2000) + .addProp(KEY_C, 1234567); validateProp(KEY_A, "200"); validateProp(KEY_B, "2,000"); @@ -182,9 +204,9 @@ public class PropertyPanelTest { public void longValues() { basic(); pp.addProp(KEY_A, 200L) - .addProp(KEY_B, 2000L) - .addProp(KEY_C, 1234567L) - .addProp(KEY_Z, Long.MAX_VALUE); + .addProp(KEY_B, 2000L) + .addProp(KEY_C, 1234567L) + .addProp(KEY_Z, Long.MAX_VALUE); validateProp(KEY_A, "200"); validateProp(KEY_B, "2,000"); @@ -196,7 +218,7 @@ public class PropertyPanelTest { public void objectValue() { basic(); pp.addProp(KEY_A, new FooClass("a")) - .addProp(KEY_B, new FooClass("bxyyzy"), "[xz]"); + .addProp(KEY_B, new FooClass("bxyyzy"), "[xz]"); validateProp(KEY_A, ">a<"); validateProp(KEY_B, ">byyy<"); |