@Test
public void testBroadcastAddress() {

    String broadcast = NetUtil.getIpv4NetBroadcastAddress("192.168.0.1", (short) 24);
    assertThat(broadcast, is("192.168.0.255"));
    broadcast = NetUtil.getIpv4NetBroadcastAddress("192.168.23.5", (short) 24);
    assertThat(broadcast, is("192.168.23.255"));
    broadcast = NetUtil.getIpv4NetBroadcastAddress("172.16.42.23", (short) 16);
    assertThat(broadcast, is("172.16.255.255"));
    broadcast = NetUtil.getIpv4NetBroadcastAddress("10.8.13.5", (short) 8);
    assertThat(broadcast, is("10.255.255.255"));
    broadcast = NetUtil.getIpv4NetBroadcastAddress("192.168.5.8", (short) 23);
    assertThat(broadcast, is("192.168.5.255"));
    broadcast = NetUtil.getIpv4NetBroadcastAddress("192.168.5.8", (short) 27);
    assertThat(broadcast, is("192.168.5.31"));
    broadcast = NetUtil.getIpv4NetBroadcastAddress("192.168.5.8", (short) 29);
    assertThat(broadcast, is("192.168.5.15"));
    try {
        broadcast = NetUtil.getIpv4NetBroadcastAddress("192.168.5.8", (short) 33);
    } catch (IllegalArgumentException iae) {
        assertThat(iae.getMessage(), is("Prefix '33' is out of bounds (1-32)"));
    }
    try {
        broadcast = NetUtil.getIpv4NetBroadcastAddress("192.168.58", (short) 24);
    } catch (IllegalArgumentException iae) {
        assertThat(iae.getMessage(), is("IP '192.168.58' is not a valid IPv4 address"));
    }
    try {
        broadcast = NetUtil.getIpv4NetBroadcastAddress("192.168.58", (short) 24);
    } catch (IllegalArgumentException iae) {
        assertThat(iae.getMessage(), is("IP '192.168.58' is not a valid IPv4 address"));
    }
    try {
        broadcast = NetUtil.getIpv4NetBroadcastAddress("SOME_TEXT", (short) 42);
    } catch (IllegalArgumentException iae) {
        assertThat(iae.getMessage(), is("IP 'SOME_TEXT' is not a valid IPv4 address"));
    }
}