Committed by
Gerrit Code Review
Use VlanId.vlanId(short) to validate the value
Also update the unit test - VlanId.vlanId("5000") should throw IllegalArgumentException Change-Id: I374532080dc2a51da8f2c0a46ea92df6f8abbe56
Showing
2 changed files
with
7 additions
and
4 deletions
... | @@ -92,7 +92,7 @@ public final class VlanId extends Identifier<Short> { | ... | @@ -92,7 +92,7 @@ public final class VlanId extends Identifier<Short> { |
92 | return new VlanId(ANY_VALUE); | 92 | return new VlanId(ANY_VALUE); |
93 | } | 93 | } |
94 | try { | 94 | try { |
95 | - return new VlanId(Short.parseShort(value)); | 95 | + return VlanId.vlanId(Short.parseShort(value)); |
96 | } catch (NumberFormatException e) { | 96 | } catch (NumberFormatException e) { |
97 | throw new IllegalArgumentException(e); | 97 | throw new IllegalArgumentException(e); |
98 | } | 98 | } | ... | ... |
... | @@ -25,7 +25,6 @@ public class VlanIdTest { | ... | @@ -25,7 +25,6 @@ public class VlanIdTest { |
25 | 25 | ||
26 | @Test | 26 | @Test |
27 | public void testEquality() { | 27 | public void testEquality() { |
28 | - | ||
29 | VlanId vlan1 = VlanId.vlanId("None"); | 28 | VlanId vlan1 = VlanId.vlanId("None"); |
30 | VlanId vlan2 = VlanId.vlanId((short) -1); | 29 | VlanId vlan2 = VlanId.vlanId((short) -1); |
31 | VlanId vlan3 = VlanId.vlanId((short) 100); | 30 | VlanId vlan3 = VlanId.vlanId((short) 100); |
... | @@ -48,11 +47,15 @@ public class VlanIdTest { | ... | @@ -48,11 +47,15 @@ public class VlanIdTest { |
48 | assertEquals("incorrect VLAN value", 10, vlan1.toShort()); | 47 | assertEquals("incorrect VLAN value", 10, vlan1.toShort()); |
49 | assertEquals("invalid untagged value", VlanId.UNTAGGED, | 48 | assertEquals("invalid untagged value", VlanId.UNTAGGED, |
50 | vlan2.toShort(), vlan3.toShort()); | 49 | vlan2.toShort(), vlan3.toShort()); |
51 | - | ||
52 | } | 50 | } |
53 | 51 | ||
54 | @Test(expected = IllegalArgumentException.class) | 52 | @Test(expected = IllegalArgumentException.class) |
55 | - public void testIllicitVLAN() { | 53 | + public void testIllicitVlan() { |
56 | VlanId.vlanId((short) 5000); | 54 | VlanId.vlanId((short) 5000); |
57 | } | 55 | } |
56 | + | ||
57 | + @Test(expected = IllegalArgumentException.class) | ||
58 | + public void testIllicitVlanString() { | ||
59 | + VlanId.vlanId("5000"); | ||
60 | + } | ||
58 | } | 61 | } | ... | ... |
-
Please register or login to post a comment