16 package org.openkilda.messaging.model;
18 import org.junit.Assert;
19 import org.junit.Rule;
20 import org.junit.Test;
21 import org.junit.rules.ExpectedException;
26 public ExpectedException
thrown = ExpectedException.none();
30 thrown.expect(IllegalArgumentException.class);
31 thrown.expectMessage(String.format(
32 "Illegal offset value %d (expect offset > 0 and offset %% 2 == 0 and offset < hex.length)", -1));
34 new SwitchId(
"00").colonSeparatedBytes(
new char[] {
't',
'e',
's',
't'}, -1);
39 thrown.expect(IllegalArgumentException.class);
40 thrown.expectMessage(String.format(
41 "Illegal offset value %d (expect offset > 0 and offset %% 2 == 0 and offset < hex.length)", 3));
43 new SwitchId(
"00").colonSeparatedBytes(
new char[] {
't',
'e',
's',
't'}, 3);
48 thrown.expect(IllegalArgumentException.class);
49 thrown.expectMessage(String.format(
50 "Illegal offset value %d (expect offset > 0 and offset %% 2 == 0 and offset < hex.length)", 6));
52 new SwitchId(
"00").colonSeparatedBytes(
new char[] {
't',
'e',
's',
't'}, 6);
57 String switchIdString =
"fe:dc:ba:98:76:54:32:10";
60 char[] hexArray = String.format(
"%016x", switchId.
toLong()).toCharArray();
62 Assert.assertEquals(switchIdString, switchId.colonSeparatedBytes(hexArray, 0));
63 Assert.assertEquals(switchIdString.substring(3), switchId.colonSeparatedBytes(hexArray, 2));
64 Assert.assertEquals(switchIdString.substring(6), switchId.colonSeparatedBytes(hexArray, 4));
65 Assert.assertEquals(switchIdString.substring(9), switchId.colonSeparatedBytes(hexArray, 6));
66 Assert.assertEquals(switchIdString.substring(12), switchId.colonSeparatedBytes(hexArray, 8));
67 Assert.assertEquals(switchIdString.substring(15), switchId.colonSeparatedBytes(hexArray, 10));
68 Assert.assertEquals(switchIdString.substring(18), switchId.colonSeparatedBytes(hexArray, 12));
69 Assert.assertEquals(switchIdString.substring(21), switchId.colonSeparatedBytes(hexArray, 14));
void colonSeparatedBytesIllegalArgumentExceptionMoreThenHexLength()
void colonSeparatedBytesIllegalArgumentExceptionOddOffset()
void colonSeparatedBytesPositive()
void colonSeparatedBytesIllegalArgumentExceptionNegativeOffset()