Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. package com.seebo;
  2.  
  3. import org.junit.Test;
  4. import org.junit.runner.RunWith;
  5. import org.mockito.runners.MockitoJUnitRunner;
  6.  
  7. import java.util.Arrays;
  8. import java.util.List;
  9. import java.util.UUID;
  10.  
  11. import static junit.framework.Assert.assertEquals;
  12. import static org.hamcrest.CoreMatchers.is;
  13. import static org.junit.Assert.assertThat;
  14.  
  15. @RunWith(MockitoJUnitRunner.class)
  16. public class AdvertisementDataTest {
  17.  
  18. @Test
  19. public void testParseListOfServices() throws Exception {
  20.  
  21. byte[] advData = {
  22. 49, //Length
  23. 0x07, // AD Type SERVICE_UUIDS_128_BIT_COMPLETE
  24. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  25. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x0E, 0x1F,
  26. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x0E, 0x2F,
  27. 9, //Length
  28. (byte)0xFF, // AD Type Manufacturer specific
  29. 0x55, 0x057, 0x58, 0x59, // Unique id
  30. 0x60, 0x61, 0x62, 0x63 // Product id
  31. };
  32.  
  33. AdvertisementData data = AdvertisementData.parse(advData);
  34.  
  35. List<UUID> expected = Arrays.asList(
  36. UUID.fromString("0f0e0d0c-0b0a-0908-0706-050403020100"),
  37. UUID.fromString("1f0e1d1c-1b1a-1918-1716-151413121110"),
  38. UUID.fromString("2f0e2d2c-2b2a-2928-2726-252423222120"));
  39.  
  40. List<UUID> actual = data.getListOfServices();
  41.  
  42. assertThat(expected, is(actual));
  43. }
  44.  
  45. @Test
  46. public void testParseManufacturerSpecific() throws Exception {
  47.  
  48. byte[] advData = {
  49. 49, // Length
  50. 0x07, // AD Type SERVICE_UUIDS_128_BIT_COMPLETE
  51. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  52. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x0E, 0x1F,
  53. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x0E, 0x2F,
  54. 9, // Length
  55. (byte)0xFF, // AD Type Manufacturer specific
  56. 0x55, 0x057, 0x58, 0x59, // Unique id
  57. 0x60, 0x61, 0x62, 0x63 // Product id
  58. };
  59.  
  60. AdvertisementData data = AdvertisementData.parse(advData);
  61.  
  62. int uniqueId = data.getUniqueId();
  63. assertEquals(0x55575859, uniqueId);
  64.  
  65. int productId = data.getProductId();
  66. assertEquals(0x60616263, productId);
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement