### Question:
AttributeConverter implements Mapper<Attribute, AttributeSer> { @Override public AttributeSer map(Attribute attribute) { AttributeSer attributeSer = new AttributeSer() .withName(attribute.getName()); Object value = attribute.getValue(); Type type = attribute.getType(); if (type == null) { return convertUndefinedType(attributeSer, value); } if (isSimpleValue(type)) { return convertSimpleValue(attributeSer, type, value); } return convertCustomValue(attributeSer, type, value); } AttributeConverter(TypeConverter typeConverter); @Override AttributeSer map(Attribute attribute);  }### Answer:
@Test void shouldConvertWhenAttributeWithSimpleValue() { Attribute attribute = new Attribute("attribute", String.class, "Test"); AttributeSer actual = attributeConverter.map(attribute); AttributeSer expected = new AttributeSer() .withName("attribute") .withValue(new ValueSer() .withType("String") .withValue("Test")); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); }
@Test void shouldConvertAttributeWithCustomValue() { Attribute attribute = new Attribute("attribute", CustomTestValue.class, new CustomTestValue("testValue")); AttributeSer actual = attributeConverter.map(attribute); AttributeSer expected = new AttributeSer() .withName("attribute") .withCustomValue(new CustomValueSer() .withType(CustomTestValue.class.getName()) .withAny(new CustomTestValue("testValue"))); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); }
@Test void shouldConvertToNullLiteralWhenAttributeWithNullValue() { Attribute attribute = new Attribute("attribute", String.class, null); AttributeSer actual = attributeConverter.map(attribute); AttributeSer expected = new AttributeSer() .withName("attribute") .withValue(new ValueSer() .withType("String") .withValue(StringTypeConverter.NULL_LITERAL)); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); }
@Test void shouldConvertToNullWhenAttributeWithoutValueAndWithoutType() { Attribute attribute = new Attribute("attribute", null, null); AttributeSer actual = attributeConverter.map(attribute); AttributeSer expected = new AttributeSer() .withName("attribute") .withValue(new ValueSer() .withType(Expression.Undefined.class.getName()) .withValue(StringTypeConverter.NULL_LITERAL)); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); }
@Test void shouldConvertToNullWhenAttributeWithCustomValue() { Attribute attribute = new Attribute("attribute", CustomTestValue.class, null); AttributeSer actual = attributeConverter.map(attribute); AttributeSer expected = new AttributeSer() .withName("attribute") .withCustomValue(new CustomValueSer() .withType(CustomTestValue.class.getName()) .withAny(null)); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); }
@Test void shouldConvertToUndefinedSimpleValueWhenAttributeWithSimpleValueAndWithoutType() { Attribute attribute = new Attribute("attribute", null, true); AttributeSer actual = attributeConverter.map(attribute); AttributeSer expected = new AttributeSer() .withName("attribute") .withValue(new ValueSer() .withType(Expression.Undefined.class.getName()) .withValue("true")); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); }
@Test void shouldConvertToCustomValueWhenAttributeWithCustomValueAndWithoutType() { Attribute attribute = new Attribute("attribute", null, new CustomTestValue("test")); AttributeSer actual = attributeConverter.map(attribute); AttributeSer expected = new AttributeSer() .withName("attribute") .withCustomValue(new CustomValueSer() .withType(Expression.Undefined.class.getName()) .withAny(new CustomTestValue("test"))); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); }