NdefMessageDecoder { public NdefMessage decode(byte[] ndefMessage) { return decode(ndefMessage, 0, ndefMessage.length); } NdefMessageDecoder(NdefRecordDecoder ndefRecordDecoder); List<Record> decodeToRecords(byte[] payload); List<Record> decodeToRecords(InputStream in); List<Record> decodeToRecords(NdefMessage ndefMessage); T decodeToRecord(byte[] ndefMessage); @SuppressWarnings("unchecked") T decodeToRecord(byte[] ndefMessage, int offset, int length); NdefMessage decode(byte[] ndefMessage); NdefMessage decode(byte[] ndefMessage, int offset, int length); NdefMessage decode(InputStream bais); List<Record> decodeToRecords(byte[] payload, int offset, int length);  }
@Test public void testEmptyRecord() throws Exception { byte[] data = NfcUtils.convertASCIIToBin(emptyRecord); NdefMessage ndefMessage = decoder.decode(data); assertTrue(ndefMessage.getNdefRecords().length == 1); }
@Test(expected = IllegalArgumentException.class) public void testMixedUpRecords() throws Exception { byte[] data = NfcUtils.convertASCIIToBin(twoEmptyRecordsMixedUp); decoder.decode(data); }
@Test(expected = IllegalArgumentException.class) public void testEmptyRecordWithBeginingOnly() throws Exception { byte[] data = NfcUtils.convertASCIIToBin(emptyRecordWithBeginingOnly); decoder.decode(data); }
@Test public void testTwoEmptyRecords() throws Exception { byte[] data = NfcUtils.convertASCIIToBin(twoEmptyRecords); NdefMessage ndefMessage = decoder.decode(data); assertTrue(ndefMessage.getNdefRecords().length == 2); }
@Test public void testMimeMediaRecordWithLongPayloadAndId() throws Exception { byte[] data = NfcUtils.convertASCIIToBin(mimeMediaRecordWithLongPayloadAndId); NdefMessage ndefMessage = decoder.decode(data); assertTrue(ndefMessage.getNdefRecords().length == 1); NdefRecord ndefRecord = ndefMessage.getNdefRecords()[0]; assertArrayEquals("image/png".getBytes(), ndefRecord.getType()); assertArrayEquals("my_id".getBytes(), ndefRecord.getId()); }
@Test public void testDecodeExternalType() throws Exception { byte[] data = NfcUtils.convertASCIIToBin("D40F13616E64726F69642E636F6D3A706B67" + "64652E6772756E6469642E7465737431323334"); NdefMessage ndefMessage = decoder.decode(data); assertTrue(ndefMessage.getNdefRecords().length == 1); NdefRecord ndefRecord = ndefMessage.getNdefRecords()[0]; assertEquals("android.com:pkg", new String(ndefRecord.getType())); assertEquals("de.grundid.test1234", new String(ndefRecord.getPayload())); }