### Question:
ProtobufCodec implements Codec<Cdr, byte[]> { @Override public byte[] encode(Cdr cdr) throws EtiqetException { try { Message message = protocolConfig.getMessage(cdr.getType()); if (message == null) { throw new EtiqetException("Could not find message class for type " + cdr.getType()); } URL schemaURL = getClass().getClassLoader().getResource(message.getImplementation()); ProtobufMapper protobufMapper = new ProtobufMapper(); ProtobufSchema schema = protobufMapper.schemaLoader().load(schemaURL); ProtobufSchema typeSchema = schema.withRootType(cdr.getType()); correctCdrTypes(cdr, typeSchema); String cdrString = JsonUtils.cdrToJson(cdr); return protobufMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) .writer(typeSchema) .writeValueAsBytes(new ObjectMapper().readTree(cdrString)); } catch (Exception e) { throw new EtiqetException(e); } }  @Override byte[] encode(Cdr cdr); @Override Cdr decode(byte[] message); @Override void setProtocolConfig(ProtocolConfig protocolConfig);  }### Answer:
@Test public void testInvalidClass() { Cdr cdr = aCdr("InvalidClass").build(); try { codec.encode(cdr); fail("Should have thrown exception when marshalling to invalid class"); } catch (EtiqetException e) { assertTrue(e.getMessage() .contains( "has no message type with name 'InvalidClass': known types: [Person, AddressBook, PersonWithRequiredAddress, PersonWithMultipleFieldTypes]")); } }