### Question:
AttributeConverter { Attribute convert(com.sabre.oss.yare.serializer.json.model.Attribute attribute) { if (attribute == null) { return null; } return new Attribute( attribute.getName(), typeConverter.fromString(Type.class, attribute.getType()), attribute.getValue()); } AttributeConverter(TypeConverter typeConverter);   }### Answer:
@Test void shouldThrowExceptionWhenUnknownTypeUsed() { com.sabre.oss.yare.serializer.json.model.Attribute toConvert = new com.sabre.oss.yare.serializer.json.model.Attribute() .withName("attribute-name") .withType("unknown") .withValue("attribute-value"); assertThatThrownBy(() -> attributeConverter.convert(toConvert)) .isExactlyInstanceOf(IllegalArgumentException.class); }
@Test void shouldConvertToAttribute() { com.sabre.oss.yare.serializer.json.model.Attribute toConvert = new com.sabre.oss.yare.serializer.json.model.Attribute() .withName("attribute-name") .withType("String") .withValue("attribute-value"); Attribute attribute = attributeConverter.convert(toConvert); Attribute expected = new Attribute("attribute-name", String.class, "attribute-value"); assertThat(attribute).isEqualTo(expected); }
@Test void shouldConvertToAttributeWhenTypeIsNull() { com.sabre.oss.yare.serializer.json.model.Attribute toConvert = new com.sabre.oss.yare.serializer.json.model.Attribute() .withName("attribute-name") .withType(null) .withValue("attribute-value"); Attribute attribute = attributeConverter.convert(toConvert); Attribute expected = new Attribute("attribute-name", Expression.Undefined.class, "attribute-value"); assertThat(attribute).isEqualTo(expected); }
@Test void shouldConvertNullAttribute() { Attribute attribute = attributeConverter.convert(null); assertThat(attribute).isNull(); }