Beacon implements BeaconInterface, Parcelable { public static Builder newBuilder() { return new Builder(); } private  Beacon(); private  Beacon(final Builder builder); @NonNull @Override UUID getUUID(); @Override int getMajor(); @Override int getMinor(); @Override int hashCode(); @Override boolean equals(final Object o); @Override int describeContents(); @Override void writeToParcel(final Parcel dest, final int flags); static Builder newBuilder(); static final Parcelable.Creator<Beacon> CREATOR; }
@Test public void testAllMajors() { int major = 1; while (major <= 65535) { final Beacon beacon = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(major) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); assertNotNull(beacon); major++; } }
@Test public void testNotEqualBeaconsByUUID() { final Beacon beacon1 = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); final Beacon beacon2 = Beacon.newBuilder() .setUUID(UUID.randomUUID()) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); Assert.assertNotSame(beacon1, beacon2); }
@Test public void testNotEqualBeaconsByMajor() { final Beacon beacon1 = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); final Beacon beacon2 = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(EXAMPLE_BEACON_1_MINOR + 1) .build(); Assert.assertNotSame(beacon1, beacon2); }
@Test public void testAllMinors() { int minor = 1; while (minor <= 65535) { final Beacon beacon = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(minor) .build(); assertNotNull(beacon); minor++; } }
@Test public void testWithRandomUUID() { final UUID uuid = UUID.randomUUID(); final Beacon beacon = Beacon.newBuilder() .setUUID(uuid) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); assertNotNull(beacon); }
@Test(expected = IllegalUUIDException.class) public void testWithoutUUID() { final Beacon beacon = Beacon.newBuilder() .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); }
@Test(expected = IllegalArgumentException.class) public void testWrongUUIDString() { final Beacon beacon = Beacon.newBuilder() .setUUID("") .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); }
@Test(expected = IllegalMajorException.class) public void testNegativeMajor() throws Exception { final Beacon beacon = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(-1) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); }
@Test(expected = IllegalMinorException.class) public void testNegativeMinor() throws Exception { final Beacon beacon = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(-1) .build(); }
@Test(expected = IllegalMajorException.class) public void testToHighMajor() throws Exception { final Beacon beacon = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(MAJOR_MINOR_MAX_VALUE + 1) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); }
@Test(expected = IllegalMinorException.class) public void testToHighMinor() throws Exception { final Beacon beacon = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(MAJOR_MINOR_MAX_VALUE + 1) .build(); }
@Test public void testEqualBeacons() { final Beacon beacon1 = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); final Beacon beacon2 = Beacon.newBuilder() .setUUID(EXAMPLE_BEACON_1_UUID) .setMajor(EXAMPLE_BEACON_1_MAJOR) .setMinor(EXAMPLE_BEACON_1_MINOR) .build(); Assert.assertEquals(beacon1, beacon2); }