Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Swap assertion parameters #1102

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/src/test/java/org/altbeacon/beacon/BeaconManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ public void startRangingBeaconsInRegionMultipleInvocationsTest() throws Exceptio
Region region2 = new Region(id, "00:11:22:33:FF:EE");

beaconManager.startRangingBeaconsInRegion(region1);
assertEquals(beaconManager.getRangedRegions().size(), 1);
assertSame(beaconManager.getRangedRegions().iterator().next(), region1);
assertNotSame(beaconManager.getRangedRegions().iterator().next(), region2);
assertEquals(1, beaconManager.getRangedRegions().size());
assertSame(region1, beaconManager.getRangedRegions().iterator().next());
assertNotSame(region2, beaconManager.getRangedRegions().iterator().next());

beaconManager.startRangingBeaconsInRegion(region2);
assertEquals(beaconManager.getRangedRegions().size(), 1);
assertNotSame(beaconManager.getRangedRegions().iterator().next(), region1);
assertSame(beaconManager.getRangedRegions().iterator().next(), region2);
assertEquals(1, beaconManager.getRangedRegions().size(), 1);
assertNotSame(region1, beaconManager.getRangedRegions().iterator().next());
assertSame(region2, beaconManager.getRangedRegions().iterator().next());

Region region3 = new Region(id + "-other", Collections.<Identifier>emptyList());
beaconManager.startRangingBeaconsInRegion(region3);
assertEquals(beaconManager.getRangedRegions().size(), 2);
assertEquals(2, beaconManager.getRangedRegions().size());
}

@Test
Expand All @@ -70,13 +70,13 @@ public void stopRangingBeaconsInRegionTest() throws Exception {
beaconManager.startRangingBeaconsInRegion(region1);
beaconManager.startRangingBeaconsInRegion(region2);
beaconManager.startRangingBeaconsInRegion(region3);
assertEquals(beaconManager.getRangedRegions().size(), 2);
assertEquals(2, beaconManager.getRangedRegions().size());

beaconManager.stopRangingBeaconsInRegion(region1);
assertEquals(beaconManager.getRangedRegions().size(), 1);
assertEquals(1, beaconManager.getRangedRegions().size());

beaconManager.stopRangingBeaconsInRegion(region3);
assertEquals(beaconManager.getRangedRegions().size(), 0);
assertEquals(0, beaconManager.getRangedRegions().size());
}

}
12 changes: 6 additions & 6 deletions lib/src/test/java/org/altbeacon/beacon/BeaconTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public void testAccessBeaconIdentifiers() {
Beacon beacon = new AltBeacon.Builder().setMfgReserved(7).setId1("1").setId2("2").setId3("3").setRssi(4)
.setBeaconTypeCode(5).setTxPower(6)
.setBluetoothAddress("1:2:3:4:5:6").build();
assertEquals("First beacon id should be 1", beacon.getIdentifier(0).toString(), "1");
assertEquals("Second beacon id should be 1", beacon.getIdentifier(1).toString(), "2");
assertEquals("Third beacon id should be 1", beacon.getIdentifier(2).toString(), "3");
assertEquals("First beacon id should be 1", beacon.getId1().toString(), "1");
assertEquals("Second beacon id should be 1", beacon.getId2().toString(), "2");
assertEquals("Third beacon id should be 1", beacon.getId3().toString(), "3");
assertEquals("First beacon id should be 1", "1", beacon.getIdentifier(0).toString());
assertEquals("Second beacon id should be 1", "2", beacon.getIdentifier(1).toString());
assertEquals("Third beacon id should be 1", "3", beacon.getIdentifier(2).toString());
assertEquals("First beacon id should be 1", "1", beacon.getId1().toString());
assertEquals("Second beacon id should be 1", "2", beacon.getId2().toString());
assertEquals("Third beacon id should be 1", "3", beacon.getId3().toString());

}

Expand Down
44 changes: 23 additions & 21 deletions lib/src/test/java/org/altbeacon/beacon/IdentifierTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package org.altbeacon.beacon;

import android.os.Parcel;

import static android.test.MoreAsserts.assertNotEqual;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;

import org.robolectric.RobolectricTestRunner;

import org.junit.runner.RunWith;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.util.Arrays;
Expand Down Expand Up @@ -64,7 +60,7 @@ public void testToUuidEqualsToUuidString() {
public void testToByteArrayConvertsUuids() {
Identifier identifier1 = Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6");
byte[] bytes = identifier1.toByteArrayOfSpecifiedEndianness(true);
assertEquals("byte array is correct length", bytes.length, 16);
assertEquals("byte array is correct length", 16, bytes.length);
assertEquals("first byte of uuid converted properly", 0x2f, bytes[0] & 0xFF);
assertEquals("second byte of uuid converted properly", 0x23, bytes[1] & 0xFF);
assertEquals("last byte of uuid converted properly", 0xa6, bytes[15] & 0xFF);
Expand All @@ -74,7 +70,7 @@ public void testToByteArrayConvertsUuids() {
public void testToByteArrayConvertsUuidsAsLittleEndian() {
Identifier identifier1 = Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6");
byte[] bytes = identifier1.toByteArrayOfSpecifiedEndianness(false);
assertEquals("byte array is correct length", bytes.length, 16);
assertEquals("byte array is correct length", 16, bytes.length);
assertEquals("first byte of uuid converted properly", 0xa6, bytes[0] & 0xFF);
assertEquals("last byte of uuid converted properly", 0x2f, bytes[15] & 0xFF);
}
Expand All @@ -83,16 +79,17 @@ public void testToByteArrayConvertsUuidsAsLittleEndian() {
public void testToByteArrayConvertsHex() {
Identifier identifier1 = Identifier.parse("0x010203040506");
byte[] bytes = identifier1.toByteArrayOfSpecifiedEndianness(true);
assertEquals("byte array is correct length", bytes.length, 6);
assertEquals("byte array is correct length", 6, bytes.length);
assertEquals("first byte of hex is converted properly", 0x01, bytes[0] & 0xFF);
assertEquals("last byte of hex is converted properly", 0x06, bytes[5] & 0xFF);
}

@Test
public void testToByteArrayConvertsDecimal() {
Identifier identifier1 = Identifier.parse("65534");
byte[] bytes = identifier1.toByteArrayOfSpecifiedEndianness(true);
assertEquals("byte array is correct length", bytes.length, 2);
assertEquals("reported byte array is correct length", identifier1.getByteCount(), 2);
assertEquals("byte array is correct length", 2, bytes.length);
assertEquals("reported byte array is correct length", 2, identifier1.getByteCount());
assertEquals("first byte of decimal converted properly", 0xff, bytes[0] & 0xFF);
assertEquals("last byte of decimal converted properly", 0xfe, bytes[1] & 0xFF);
}
Expand All @@ -101,9 +98,9 @@ public void testToByteArrayConvertsDecimal() {
public void testToByteArrayConvertsInt() {
Identifier identifier1 = Identifier.fromInt(65534);
byte[] bytes = identifier1.toByteArrayOfSpecifiedEndianness(true);
assertEquals("byte array is correct length", bytes.length, 2);
assertEquals("reported byte array is correct length", identifier1.getByteCount(), 2);
assertEquals("conversion back equals original value", identifier1.toInt(), 65534);
assertEquals("byte array is correct length", 2, bytes.length);
assertEquals("reported byte array is correct length", 2, identifier1.getByteCount());
assertEquals("conversion back equals original value", 65534, identifier1.toInt());
assertEquals("first byte of decimal converted properly", 0xff, bytes[0] & 0xFF);
assertEquals("last byte of decimal converted properly", 0xfe, bytes[1] & 0xFF);
}
Expand All @@ -127,8 +124,8 @@ public void testComparableDifferentLength() {
byte[] value2 = new byte[] {(byte) 0xFF, (byte) 0xAB, 0x12, 0x25, 0x11, 0x11};
Identifier identifier2 = Identifier.fromBytes(value2, 0, value2.length, false);

assertEquals("identifier1 is smaller than identifier2", identifier1.compareTo(identifier2), -1);
assertEquals("identifier2 is larger than identifier1", identifier2.compareTo(identifier1), 1);
assertEquals("identifier1 is smaller than identifier2", -1, identifier1.compareTo(identifier2));
assertEquals("identifier2 is larger than identifier1", 1, identifier2.compareTo(identifier1));
}

@Test
Expand All @@ -138,9 +135,9 @@ public void testComparableSameLength() {
byte[] value2 = new byte[] {(byte) 0xFF, (byte) 0xAB, 0x12, 0x25, 0x11, 0x11};
Identifier identifier2 = Identifier.fromBytes(value2, 0, value2.length, false);

assertEquals("identifier1 is equal to identifier2", identifier1.compareTo(identifier1), 0);
assertEquals("identifier1 is larger than identifier2", identifier1.compareTo(identifier2), 1);
assertEquals("identifier2 is smaller than identifier1", identifier2.compareTo(identifier1), -1);
assertEquals("identifier1 is equal to identifier2", 0, identifier1.compareTo(identifier1));
assertEquals("identifier1 is larger than identifier2", 1, identifier1.compareTo(identifier2));
assertEquals("identifier2 is smaller than identifier1", -1, identifier2.compareTo(identifier1));
}

@Test
Expand Down Expand Up @@ -176,7 +173,7 @@ public void testParseIntegerWayTooBig() {
public void testParseInvalidUuid() {
UUID ref = UUID.fromString("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6");
Identifier id = Identifier.parse("2f234454cf6d4a0fadf2f4911ba9ffa6");
assertEquals("Malformed UUID was parsed as expected.", id.toUuid(), ref);
assertEquals("Malformed UUID was parsed as expected.", ref, id.toUuid());
}

@Test
Expand All @@ -190,39 +187,44 @@ public void testParseBigHexWithNoPrefix() {
Identifier id = Identifier.parse("123456789abcdef");
assertEquals("Should parse and get prefixed hex value for big numbers", "0x0123456789abcdef", id.toString());
}

@Test
public void testParseZeroPrefixedDecimalNumberAsHex() {
Identifier id = Identifier.parse("0010");
assertEquals("Should be treated as hex in parse, but converted back to decimal because it is small", "16", id.toString());
}

@Test
public void testParseNonZeroPrefixedDecimalNumberAsDecimal() {
Identifier id = Identifier.parse("10");
assertEquals("Should be treated as decimal", "10", id.toString());
}

@Test
public void testParseDecimalNumberWithSpecifiedLength() {
Identifier id = Identifier.parse("10", 8);
assertEquals("Should be treated as hex because it is long", "0x000000000000000a", id.toString());
assertEquals("Byte count should be as specified", 8, id.getByteCount());
}

@Test
public void testParseDecimalNumberWithSpecifiedShortLength() {
Identifier id = Identifier.parse("10", 2);
assertEquals("Should be treated as decimal because it is short", "10", id.toString());
assertEquals("Byte count should be as specified", 2, id.getByteCount());
}

@Test
public void testParseHexNumberWithSpecifiedLength() {
Identifier id = Identifier.parse("2fffffffffffffffffff", 10);
assertEquals("Should be treated as hex because it is long", "0x2fffffffffffffffffff", id.toString());
assertEquals("Byte count should be as specified", 10, id.getByteCount());
}

@Test
public void testParseZeroAsInteger() {
Identifier id = Identifier.parse("0");
assertEquals("Should be treated as int because it is a common integer", "0", id.toString());
assertEquals("Byte count should be 2 for integers", 2, id.getByteCount());
}

}