Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.seebo;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.mockito.runners.MockitoJUnitRunner;
- import java.util.Arrays;
- import java.util.List;
- import java.util.UUID;
- import static junit.framework.Assert.assertEquals;
- import static org.hamcrest.CoreMatchers.is;
- import static org.junit.Assert.assertThat;
- @RunWith(MockitoJUnitRunner.class)
- public class AdvertisementDataTest {
- @Test
- public void testParseListOfServices() throws Exception {
- byte[] advData = {
- 49, //Length
- 0x07, // AD Type SERVICE_UUIDS_128_BIT_COMPLETE
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x0E, 0x1F,
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x0E, 0x2F,
- 9, //Length
- (byte)0xFF, // AD Type Manufacturer specific
- 0x55, 0x057, 0x58, 0x59, // Unique id
- 0x60, 0x61, 0x62, 0x63 // Product id
- };
- AdvertisementData data = AdvertisementData.parse(advData);
- List<UUID> expected = Arrays.asList(
- UUID.fromString("0f0e0d0c-0b0a-0908-0706-050403020100"),
- UUID.fromString("1f0e1d1c-1b1a-1918-1716-151413121110"),
- UUID.fromString("2f0e2d2c-2b2a-2928-2726-252423222120"));
- List<UUID> actual = data.getListOfServices();
- assertThat(expected, is(actual));
- }
- @Test
- public void testParseManufacturerSpecific() throws Exception {
- byte[] advData = {
- 49, // Length
- 0x07, // AD Type SERVICE_UUIDS_128_BIT_COMPLETE
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x0E, 0x1F,
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x0E, 0x2F,
- 9, // Length
- (byte)0xFF, // AD Type Manufacturer specific
- 0x55, 0x057, 0x58, 0x59, // Unique id
- 0x60, 0x61, 0x62, 0x63 // Product id
- };
- AdvertisementData data = AdvertisementData.parse(advData);
- int uniqueId = data.getUniqueId();
- assertEquals(0x55575859, uniqueId);
- int productId = data.getProductId();
- assertEquals(0x60616263, productId);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement