Add unit test for Instructions class and improve Criteria toString() test
Change-Id: Ie1ffb4ca0c0bcd168625213fecbdb3818a61704e
Showing
5 changed files
with
13 additions
and
10 deletions
... | @@ -119,7 +119,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -119,7 +119,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
119 | */ | 119 | */ |
120 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { | 120 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { |
121 | 121 | ||
122 | - public final VlanId vlanId; | 122 | + private final VlanId vlanId; |
123 | 123 | ||
124 | public ModVlanIdInstruction(VlanId vlanId) { | 124 | public ModVlanIdInstruction(VlanId vlanId) { |
125 | this.vlanId = vlanId; | 125 | this.vlanId = vlanId; |
... | @@ -168,7 +168,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -168,7 +168,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
168 | */ | 168 | */ |
169 | public static final class ModVlanPcpInstruction extends L2ModificationInstruction { | 169 | public static final class ModVlanPcpInstruction extends L2ModificationInstruction { |
170 | 170 | ||
171 | - public final Byte vlanPcp; | 171 | + private final Byte vlanPcp; |
172 | 172 | ||
173 | public ModVlanPcpInstruction(Byte vlanPcp) { | 173 | public ModVlanPcpInstruction(Byte vlanPcp) { |
174 | this.vlanPcp = vlanPcp; | 174 | this.vlanPcp = vlanPcp; | ... | ... |
... | @@ -116,7 +116,7 @@ public class CriteriaTest { | ... | @@ -116,7 +116,7 @@ public class CriteriaTest { |
116 | private <T> T checkAndConvert(Criterion criterion, Criterion.Type type, Class clazz) { | 116 | private <T> T checkAndConvert(Criterion criterion, Criterion.Type type, Class clazz) { |
117 | assertThat(criterion, is(notNullValue())); | 117 | assertThat(criterion, is(notNullValue())); |
118 | assertThat(criterion.type(), is(equalTo(type))); | 118 | assertThat(criterion.type(), is(equalTo(type))); |
119 | - assertThat(criterion, is(instanceOf(clazz))); | 119 | + assertThat(criterion, instanceOf(clazz)); |
120 | return (T) criterion; | 120 | return (T) criterion; |
121 | } | 121 | } |
122 | 122 | ||
... | @@ -131,16 +131,19 @@ public class CriteriaTest { | ... | @@ -131,16 +131,19 @@ public class CriteriaTest { |
131 | */ | 131 | */ |
132 | private <T extends Criterion> void checkEqualsAndToString(T c1, T c1match, | 132 | private <T extends Criterion> void checkEqualsAndToString(T c1, T c1match, |
133 | T c2, Class clazz) { | 133 | T c2, Class clazz) { |
134 | - assertThat(c1, is(instanceOf(clazz))); | 134 | + assertThat(c1, instanceOf(clazz)); |
135 | - assertThat(c1match, is(instanceOf(clazz))); | 135 | + assertThat(c1match, instanceOf(clazz)); |
136 | - assertThat(c2, is(instanceOf(clazz))); | 136 | + assertThat(c2, instanceOf(clazz)); |
137 | 137 | ||
138 | assertThat(c1, is(equalTo(c1match))); | 138 | assertThat(c1, is(equalTo(c1match))); |
139 | assertThat(c1, is(not(equalTo(c2)))); | 139 | assertThat(c1, is(not(equalTo(c2)))); |
140 | assertThat(c1, is(not(equalTo(new Object())))); | 140 | assertThat(c1, is(not(equalTo(new Object())))); |
141 | 141 | ||
142 | - // Make sure the enumerated type appears in the toString() output. | 142 | + // Make sure the enumerated type appears in the toString() output and |
143 | + // the toString output is unique. | ||
143 | assertThat(c1.toString(), containsString(c1.type().toString())); | 144 | assertThat(c1.toString(), containsString(c1.type().toString())); |
145 | + assertThat(c1.toString(), equalTo(c1match.toString())); | ||
146 | + assertThat(c1.toString(), not(equalTo(c2.toString()))); | ||
144 | } | 147 | } |
145 | 148 | ||
146 | 149 | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -192,7 +192,7 @@ public class FlowModBuilderVer10 extends FlowModBuilder { | ... | @@ -192,7 +192,7 @@ public class FlowModBuilderVer10 extends FlowModBuilder { |
192 | return factory().actions().setDlSrc(MacAddress.of(eth.mac().toLong())); | 192 | return factory().actions().setDlSrc(MacAddress.of(eth.mac().toLong())); |
193 | case VLAN_ID: | 193 | case VLAN_ID: |
194 | ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; | 194 | ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; |
195 | - return factory().actions().setVlanVid(VlanVid.ofVlan(vlanId.vlanId.toShort())); | 195 | + return factory().actions().setVlanVid(VlanVid.ofVlan(vlanId.vlanId().toShort())); |
196 | case VLAN_PCP: | 196 | case VLAN_PCP: |
197 | ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; | 197 | ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; |
198 | return factory().actions().setVlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); | 198 | return factory().actions().setVlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); | ... | ... |
... | @@ -210,11 +210,11 @@ public class FlowModBuilderVer13 extends FlowModBuilder { | ... | @@ -210,11 +210,11 @@ public class FlowModBuilderVer13 extends FlowModBuilder { |
210 | break; | 210 | break; |
211 | case VLAN_ID: | 211 | case VLAN_ID: |
212 | ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; | 212 | ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; |
213 | - oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId.toShort())); | 213 | + oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort())); |
214 | break; | 214 | break; |
215 | case VLAN_PCP: | 215 | case VLAN_PCP: |
216 | ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; | 216 | ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; |
217 | - oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp)); | 217 | + oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); |
218 | break; | 218 | break; |
219 | default: | 219 | default: |
220 | log.warn("Unimplemented action type {}.", l2m.subtype()); | 220 | log.warn("Unimplemented action type {}.", l2m.subtype()); | ... | ... |
-
Please register or login to post a comment