### Question:
TLVDeserializer { public static List<LWM2MResource> deserializeResources (byte[] tlv) { if (!isResource(tlv) && !isMultipleResource(tlv)) { throw new IllegalArgumentException("Resource or multiple resource not found."); } return deserializeResources (tlv, 0, new ArrayList<LWM2MResource>() ); }  static boolean isObjectInstance(byte[] tlv); static boolean isResource(byte[] tlv); static boolean isMultipleResource(byte[] tlv); static boolean isResourceInstance(byte[] tlv); static List<LWM2MObjectInstance> deserialiseObjectInstances(byte[] tlv); static List<LWM2MResource> deserializeResources(byte[] tlv);  }### Answer:
@Test public void deserializeResourceWithZeroLength() throws Exception { byte[] tlv = new byte[]{ (byte) 0b11_0_00_000, (byte) 0 }; List<LWM2MResource> resources = TLVDeserializer.deserializeResources(tlv); assertThat(resources, hasSize(1)); assertThat(resources.get(0).getId().intValue(), equalTo(0)); assertThat(resources.get(0).getStringValue(), equalTo("")); }
@Test(expected = IllegalArgumentException.class) public void deserializeResourceWhereLengthFieldIsLess() throws Exception { byte[] tlv = new byte[]{ (byte) 0b11_0_00_010, (byte) 0, 'A', 'R', 'M'}; TLVDeserializer.deserializeResources(tlv); }
@Test public void deserializeResourceWhereLengthFieldIsGreater() throws Exception { byte[] tlv = new byte[]{ (byte) 0b11_0_00_011, (byte) 0, 'A', 'R'}; List<LWM2MResource> resources = TLVDeserializer.deserializeResources(tlv); assertThat(resources, hasSize(1)); assertThat(resources.get(0).getId().intValue(), equalTo(0)); assertArrayEquals("AR\0".getBytes(), resources.get(0).getValue()); assertFalse(resources.get(0).hasNestedInstances()); }
@Test(expected = IllegalArgumentException.class) public void serializeObjectInstanceAsResource() throws Exception { TLVDeserializer.deserializeResources(createObjectInstanceTLV()); }