GroupAddress { byte[] asByteArray() { return new byte[] { hiByte, loByte }; } GroupAddress(String groupAddress);   GroupAddress(byte hibyte, byte lobyte); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void basicConstructor() throws InvalidGroupAddressException { GroupAddress addr = new GroupAddress("0/0/0"); byte[] b = addr.asByteArray(); Assert.assertTrue(b[1] == 0); Assert.assertTrue(b[0] == 0); addr = new GroupAddress("1/1/1"); b = addr.asByteArray(); Assert.assertTrue("Was expecting 1, got " + b[1], b[1] == 1); Assert.assertTrue("Was expecting 9, got " + b[0], b[0] == 9); addr = new GroupAddress("31/7/255"); b = addr.asByteArray(); Assert.assertTrue("Was expecting -1 [1], got " + b[1], b[1] == -1); Assert.assertTrue("Was expecting -1 [0], got " + b[0], b[0] == -1); }
@Test public void constructor2() { byte b1 = 0x00; byte b2 = 0x00; GroupAddress addr = new GroupAddress(b1, b2); byte[] bytes = addr.asByteArray(); Assert.assertTrue(bytes[0] == b1); Assert.assertTrue(bytes[1] == b2); b1 = 0x01; b2 = 0x01; addr = new GroupAddress(b1, b2); bytes = addr.asByteArray(); Assert.assertTrue(bytes[0] == b1); Assert.assertTrue(bytes[1] == b2); b1 = -128; b2 = -128; addr = new GroupAddress(b1, b2); bytes = addr.asByteArray(); Assert.assertTrue(bytes[0] == b1); Assert.assertTrue(bytes[1] == b2); b1 = -1; b2 = -1; addr = new GroupAddress(b1, b2); bytes = addr.asByteArray(); Assert.assertTrue(bytes[0] == b1); Assert.assertTrue(bytes[1] == b2); b1 = 127; b2 = 127; addr = new GroupAddress(b1, b2); bytes = addr.asByteArray(); Assert.assertTrue(bytes[0] == b1); Assert.assertTrue(bytes[1] == b2); }
@Test public void testValidRange() { for (int main = 0; main < 32; ++main) { for (int middle = 0; middle < 8; ++middle) { for (int sub = 0; sub < 256; ++sub) { byte mainmiddle = (byte)(main << 3); mainmiddle = (byte)(mainmiddle + middle); byte subbyte = (byte)sub; GroupAddress addr = new GroupAddress(mainmiddle, subbyte); byte[] bytes = addr.asByteArray(); int byte0 = bytes[0] & 0xFF; int byte1 = bytes[1] & 0xFF; int gotMain = (byte0 & 0xF8) >> 3; int gotMiddle = byte0 & 0x07; Assert.assertTrue("Was expecting main " + main + ", got " + gotMain, gotMain == main); Assert.assertTrue("Was expecting middle " + middle + ", got " + gotMiddle, gotMiddle == middle); Assert.assertTrue("Was expecting sub " + sub + ", got " + byte1, byte1 == sub); } } } }