diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 570e4bc5..4f39adb7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - java: [ '8', '11', '17' ] + java: [ '8', '11', '17', '21' ] os: [ 'ubuntu-latest' ] runs-on: ${{ matrix.os }} steps: diff --git a/.gitignore b/.gitignore index cba934ab..3c7a5f1d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ release.properties .settings/ _site/ user-manual/ -*.iml \ No newline at end of file +*.iml +.idea/ diff --git a/CHANGES.md b/CHANGES.md index 6157b977..60ebb24c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +# 3.2.0 + +* Bump asm and byte-buddy for JDK 21 support + # 3.1.0 * Migrates optional converters from modelmapper-module-java8 diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index 92f2f216..b901d1c6 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -5,7 +5,7 @@ modelmapper-parent org.modelmapper - 3.1.0 + 3.2.1-SNAPSHOT benchmarks diff --git a/core/pom.xml b/core/pom.xml index 14c9b1e5..ef19fef2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ org.modelmapper modelmapper-parent - 3.1.0 + 3.2.1-SNAPSHOT modelmapper diff --git a/core/src/main/java/org/modelmapper/ModelMapper.java b/core/src/main/java/org/modelmapper/ModelMapper.java index 4c3a6f86..e60f895a 100644 --- a/core/src/main/java/org/modelmapper/ModelMapper.java +++ b/core/src/main/java/org/modelmapper/ModelMapper.java @@ -379,6 +379,22 @@ public TypeMap emptyTypeMap(Class sourceType, Class destinati return config.typeMapStore.createEmptyTypeMap(sourceType, destinationType, null, config, engine); } + /** + * Creates an empty TypeMap for the {@code sourceType}, {@code destinationType}. + * + * @param source type + * @param destination type + * @throws IllegalArgumentException is {@code sourceType} or {@code destinationType} are null, or {@code TypeMap TypeMap emptyTypeMap(Class sourceType, Class destinationType, String typeMapName) { + Assert.notNull(sourceType, "sourceType"); + Assert.notNull(destinationType, "destinationType"); + Assert.notNull(typeMapName, "typeMapName"); + Assert.isNull(config.typeMapStore.get(sourceType, destinationType, typeMapName), "TypeMap already defined"); + return config.typeMapStore.createEmptyTypeMap(sourceType, destinationType, typeMapName, config, engine); + } + /** * Returns all TypeMaps for the ModelMapper. */ diff --git a/core/src/main/java/org/modelmapper/internal/Errors.java b/core/src/main/java/org/modelmapper/internal/Errors.java index ee4df925..6b714897 100644 --- a/core/src/main/java/org/modelmapper/internal/Errors.java +++ b/core/src/main/java/org/modelmapper/internal/Errors.java @@ -26,7 +26,6 @@ import java.util.Collections; import java.util.Formatter; import java.util.List; - import org.modelmapper.ConfigurationException; import org.modelmapper.MappingException; import org.modelmapper.TypeMap; @@ -375,6 +374,13 @@ Errors sourceOutsideOfMap() { return addMessage("'source' cannot be used outside of a map statement."); } + Errors skipConflict(String skip, List paths) { + return addMessage("Not able to skip %s, because there are already nested properties are mapped: [%s]. " + + "Do you skip the property after the implicit mappings mapped? " + + "We recommended you to create an empty type map, and followed by addMappings and implicitMappings calls", + skip, String.join(" ", paths)); + } + void throwMappingExceptionIfErrorsExist() { if (hasErrors()) throw new MappingException(getMessages()); diff --git a/core/src/main/java/org/modelmapper/internal/InheritingConfiguration.java b/core/src/main/java/org/modelmapper/internal/InheritingConfiguration.java index ba3cec66..8c8c8078 100644 --- a/core/src/main/java/org/modelmapper/internal/InheritingConfiguration.java +++ b/core/src/main/java/org/modelmapper/internal/InheritingConfiguration.java @@ -172,6 +172,10 @@ public boolean equals(Object obj) { return false; if (isFieldMatchingEnabled() != other.isFieldMatchingEnabled()) return false; + if (!getSourceNamingConvention().equals(other.getSourceNamingConvention())) + return false; + if (!getDestinationNamingConvention().equals(other.getDestinationNamingConvention())) + return false; return true; } @@ -283,6 +287,8 @@ public int hashCode() { result = prime * result + getDestinationNameTransformer().hashCode(); result = prime * result + getFieldAccessLevel().hashCode(); result = prime * result + getMethodAccessLevel().hashCode(); + result = prime * result + getSourceNamingConvention().hashCode(); + result = prime * result + getDestinationNamingConvention().hashCode(); result = prime * result + (isFieldMatchingEnabled() ? 1231 : 1237); return result; } diff --git a/core/src/main/java/org/modelmapper/internal/ReferenceMapExpressionImpl.java b/core/src/main/java/org/modelmapper/internal/ReferenceMapExpressionImpl.java index f73c006b..42166bdc 100644 --- a/core/src/main/java/org/modelmapper/internal/ReferenceMapExpressionImpl.java +++ b/core/src/main/java/org/modelmapper/internal/ReferenceMapExpressionImpl.java @@ -15,13 +15,16 @@ */ package org.modelmapper.internal; +import static java.util.stream.Collectors.toList; import static org.modelmapper.internal.ExplicitMappingBuilder.MappingOptions; import static org.modelmapper.internal.util.Assert.notNull; +import java.util.List; import net.jodah.typetools.TypeResolver; import org.modelmapper.builder.ReferenceMapExpression; import org.modelmapper.internal.util.Primitives; import org.modelmapper.spi.DestinationSetter; +import org.modelmapper.spi.Mapping; import org.modelmapper.spi.SourceGetter; /** @@ -62,7 +65,7 @@ class ReferenceMapExpressionImpl implements ReferenceMapExpression { public void map(SourceGetter sourceGetter, DestinationSetter destinationSetter) { visitSource(sourceGetter); visitDestination(destinationSetter); - typeMap.addMapping(collector.collect()); + skipMapping(collector.collect()); collector.reset(); } @@ -70,16 +73,30 @@ public void map(SourceGetter sourceGetter, DestinationSetter destin public void skip(DestinationSetter destinationSetter) { options.skipType = 1; visitDestination(destinationSetter); - typeMap.addMapping(collector.collect()); + skipMapping(collector.collect()); collector.reset(); } + private void skipMapping(MappingImpl skipMapping) { + String prefix = skipMapping.getPath(); + List conflictPaths = typeMap.getMappings().stream() + .map(Mapping::getPath) + .filter(path -> path.startsWith(prefix) && !path.equals(prefix)) + .collect(toList()); + if (conflictPaths.isEmpty()) { + typeMap.addMapping(skipMapping); + } else { + collector.getErrors().skipConflict(skipMapping.getPath(), conflictPaths); + collector.getErrors().throwConfigurationExceptionIfErrorsExist(); + } + } + @Override public void skip(SourceGetter sourceGetter, DestinationSetter destinationSetter) { options.skipType = 1; visitSource(sourceGetter); visitDestination(destinationSetter); - typeMap.addMapping(collector.collect()); + skipMapping(collector.collect()); collector.reset(); } diff --git a/core/src/main/java/org/modelmapper/internal/converter/ConverterStore.java b/core/src/main/java/org/modelmapper/internal/converter/ConverterStore.java index a947d87a..e5e15407 100644 --- a/core/src/main/java/org/modelmapper/internal/converter/ConverterStore.java +++ b/core/src/main/java/org/modelmapper/internal/converter/ConverterStore.java @@ -30,7 +30,7 @@ public final class ConverterStore { new FromOptionalConverter(),new OptionalConverter(), new ToOptionalConverter(), new AssignableConverter(), new StringConverter(), new EnumConverter(), new NumberConverter(), new BooleanConverter(), new CharacterConverter(), new DateConverter(), - new CalendarConverter(), + new CalendarConverter(), new UuidConverter(), }; private final List> converters; diff --git a/core/src/main/java/org/modelmapper/internal/converter/UuidConverter.java b/core/src/main/java/org/modelmapper/internal/converter/UuidConverter.java new file mode 100644 index 00000000..f8b0f90c --- /dev/null +++ b/core/src/main/java/org/modelmapper/internal/converter/UuidConverter.java @@ -0,0 +1,37 @@ +package org.modelmapper.internal.converter; + +import java.util.UUID; +import org.modelmapper.spi.ConditionalConverter; +import org.modelmapper.spi.MappingContext; + +/** + * Converts objects to UUID. + */ +class UuidConverter implements ConditionalConverter { + + public UUID convert(MappingContext context) { + Object source = context.getSource(); + if (source == null) { + return null; + } + + Class sourceType = context.getSourceType(); + if (isCharArray(sourceType)) { + return UUID.fromString(new String((char[]) source)); + } + return UUID.fromString(source.toString()); + } + + public MatchResult match(Class sourceType, Class destinationType) { + boolean destMatch = destinationType == UUID.class; + return destMatch ? isCharArray(sourceType) || sourceType == String.class + ? MatchResult.FULL + : MatchResult.PARTIAL + : MatchResult.NONE; + } + + private boolean isCharArray(Class sourceType) { + return sourceType.isArray() && (sourceType.getComponentType() == Character.TYPE + || sourceType.getComponentType() == Character.class); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/modelmapper/internal/util/Types.java b/core/src/main/java/org/modelmapper/internal/util/Types.java index f1cce4d6..b0a20858 100644 --- a/core/src/main/java/org/modelmapper/internal/util/Types.java +++ b/core/src/main/java/org/modelmapper/internal/util/Types.java @@ -80,6 +80,8 @@ public static boolean isProxied(Class type) { return true; if (type.getName().contains("$MockitoMock$")) return true; + if (type.getName().contains("$$Permazen")) + return true; if (Proxy.isProxyClass(type)) return true; return isProxiedByJavassist(type); diff --git a/core/src/test/java/org/modelmapper/ModelMapperTest.java b/core/src/test/java/org/modelmapper/ModelMapperTest.java index d4eb0253..7753e2e8 100644 --- a/core/src/test/java/org/modelmapper/ModelMapperTest.java +++ b/core/src/test/java/org/modelmapper/ModelMapperTest.java @@ -1,9 +1,13 @@ package org.modelmapper; -import static org.testng.Assert.*; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNotSame; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import java.util.Map; - import org.modelmapper.config.Configuration.AccessLevel; import org.modelmapper.spi.Mapping; import org.testng.annotations.Test; @@ -130,4 +134,12 @@ public void shouldTypeMapCreateOrGet() { assertNotSame(typeMapWithDifferentName, typeMapWithName); assertSame(modelMapper.typeMap(Person.class, PersonDTO.class, "bar"), typeMapWithDifferentName); } + + public void shouldCreateNamedEmptyTypeMap() { + TypeMap unnamed = modelMapper.emptyTypeMap(Person.class, PersonDTO.class); + TypeMap foo = modelMapper.emptyTypeMap(Person.class, PersonDTO.class, "foo"); + TypeMap bar = modelMapper.emptyTypeMap(Person.class, PersonDTO.class, "bar"); + assertNotSame(unnamed, foo); + assertNotSame(foo, bar); + } } diff --git a/core/src/test/java/org/modelmapper/bugs/GH109.java b/core/src/test/java/org/modelmapper/bugs/GH109.java index a730c12e..aa3246e6 100644 --- a/core/src/test/java/org/modelmapper/bugs/GH109.java +++ b/core/src/test/java/org/modelmapper/bugs/GH109.java @@ -36,6 +36,6 @@ protected void configure() { Source s = new Source(); s.value = Integer.valueOf(42); Destination dest = modelMapper.map(s, Destination.class); - assertEquals(42, dest.value); + assertEquals(dest.value, 42); } } diff --git a/core/src/test/java/org/modelmapper/bugs/GH204.java b/core/src/test/java/org/modelmapper/bugs/GH204.java index 205b2a6c..6ffdc5af 100644 --- a/core/src/test/java/org/modelmapper/bugs/GH204.java +++ b/core/src/test/java/org/modelmapper/bugs/GH204.java @@ -64,10 +64,8 @@ protected void configure() { modelMapper.validate(); - assertEquals("foo", - modelMapper.map(new SomeDto("foo"), SomeEntity.class).otherValue); - assertEquals("bar", - modelMapper.map(new SomeEntity("bar"), SomeDto.class).someValue); + assertEquals(modelMapper.map(new SomeDto("foo"), SomeEntity.class).otherValue, "foo"); + assertEquals(modelMapper.map(new SomeEntity("bar"), SomeDto.class).someValue, "bar"); } public void shouldMappingMethod2() { @@ -86,10 +84,8 @@ protected void configure() { modelMapper.validate(); - assertEquals("foo", - modelMapper.map(new SomeDto("foo"), SomeEntity.class).otherValue); - assertEquals("bar", - modelMapper.map(new SomeEntity("bar"), SomeDto.class).someValue); + assertEquals(modelMapper.map(new SomeDto("foo"), SomeEntity.class).otherValue, "foo"); + assertEquals(modelMapper.map(new SomeEntity("bar"), SomeDto.class).someValue, "bar"); } public void shouldMappingMethod3() { @@ -108,9 +104,7 @@ protected void configure() { modelMapper.validate(); - assertEquals("foo", - modelMapper.map(new SomeDto("foo"), SomeEntity.class).otherValue); - assertEquals("bar", - modelMapper.map(new SomeEntity("bar"), SomeDto.class).someValue); + assertEquals(modelMapper.map(new SomeDto("foo"), SomeEntity.class).otherValue, "foo"); + assertEquals(modelMapper.map(new SomeEntity("bar"), SomeDto.class).someValue, "bar"); } } diff --git a/core/src/test/java/org/modelmapper/bugs/GH249.java b/core/src/test/java/org/modelmapper/bugs/GH249.java index 71a92728..8de98b94 100644 --- a/core/src/test/java/org/modelmapper/bugs/GH249.java +++ b/core/src/test/java/org/modelmapper/bugs/GH249.java @@ -71,7 +71,7 @@ public void shouldMap() { pojoAgent.setRoles(new HashSet(Arrays.asList(new Role("foo"), new Role("bar")))); DomainAgent domainAgent = modelMapper.map(pojoAgent, DomainAgent.class); - assertEquals(2, domainAgent.getRoles().size()); + assertEquals(domainAgent.getRoles().size(), 2); } public void shouldMapExistDestination() { @@ -83,6 +83,6 @@ public void shouldMapExistDestination() { modelMapper.map(pojoAgent, domainAgent); - assertEquals(2, domainAgent.getRoles().size()); + assertEquals(domainAgent.getRoles().size(), 2); } } diff --git a/core/src/test/java/org/modelmapper/bugs/GH379.java b/core/src/test/java/org/modelmapper/bugs/GH379.java index 32670118..2cd7353b 100644 --- a/core/src/test/java/org/modelmapper/bugs/GH379.java +++ b/core/src/test/java/org/modelmapper/bugs/GH379.java @@ -41,7 +41,7 @@ public void shouldMapGeneric() { Type destinationType = new TypeToken>(){}.getType(); PageModel destination = modelMapper.map(page, destinationType); - assertEquals(2, destination.items.size()); + assertEquals(destination.items.size(), 2); assertEquals(SubjectModel.class, destination.items.get(0).getClass()); } } diff --git a/core/src/test/java/org/modelmapper/bugs/GH38.java b/core/src/test/java/org/modelmapper/bugs/GH38.java index de4a15e8..8bd79b71 100644 --- a/core/src/test/java/org/modelmapper/bugs/GH38.java +++ b/core/src/test/java/org/modelmapper/bugs/GH38.java @@ -47,6 +47,6 @@ protected void configure() { Mockito.when(a.getName()).thenReturn("hello"); B b = modelMapper.map(a, B.class); - Assert.assertEquals("hello", b.getNameProp()); + Assert.assertEquals(b.getNameProp(), "hello"); } } diff --git a/core/src/test/java/org/modelmapper/bugs/GH386.java b/core/src/test/java/org/modelmapper/bugs/GH386.java index 3301913d..3c0d0bbd 100644 --- a/core/src/test/java/org/modelmapper/bugs/GH386.java +++ b/core/src/test/java/org/modelmapper/bugs/GH386.java @@ -70,10 +70,10 @@ public void map() { OuterDto outerDto = new OuterDto(2L,"dto", Arrays.asList(innerDto)); modelMapper.map(outer, outerDto); - assertEquals(2L, (long) outerDto.id); - assertEquals(1, outerDto.inners.size()); - assertEquals(1L, (long) outerDto.inners.get(0).id); - assertEquals("domain", outerDto.inners.get(0).description); - assertEquals("domain", outerDto.inners.get(0).name); + assertEquals((long) outerDto.id, 2L); + assertEquals(outerDto.inners.size(), 1); + assertEquals((long) outerDto.inners.get(0).id, 1L); + assertEquals(outerDto.inners.get(0).description, "domain"); + assertEquals(outerDto.inners.get(0).name, "domain"); } } diff --git a/core/src/test/java/org/modelmapper/bugs/GH578.java b/core/src/test/java/org/modelmapper/bugs/GH578.java new file mode 100644 index 00000000..af991d0f --- /dev/null +++ b/core/src/test/java/org/modelmapper/bugs/GH578.java @@ -0,0 +1,98 @@ +package org.modelmapper.bugs; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + +import org.modelmapper.AbstractTest; +import org.modelmapper.ConfigurationException; +import org.modelmapper.ModelMapper; +import org.testng.annotations.Test; + +@Test +public class GH578 extends AbstractTest { + + enum CLASSIFIER { + AAA, + BBB; + } + + class TypeA { + + TypeABox box; + + public void setBox(TypeABox box) { + this.box = box; + } + + public TypeABox getBox() { + return box; + } + } + + class TypeABox { + + CLASSIFIER param; + + public CLASSIFIER getParam() { + return param; + } + + public void setParam(CLASSIFIER param) { + this.param = param; + } + } + + class TypeB { + + TypeBBox box; + + public TypeBBox getBox() { + return box; + } + + public void setBox(TypeBBox box) { + this.box = box; + } + } + + class TypeBBox { + + CLASSIFIER param; + + public CLASSIFIER getParam() { + return param; + } + + public void setParam(CLASSIFIER param) { + this.param = param; + } + } + + public void testBoxMapping() { + + TypeA typeA = new TypeA(); + TypeABox typeABox = new TypeABox(); + + typeABox.setParam(CLASSIFIER.AAA); + typeA.setBox(typeABox); + + TypeB typeB = new TypeB(); + TypeBBox typeBBox = new TypeBBox(); + + typeBBox.setParam(CLASSIFIER.BBB); + typeB.setBox(typeBBox); + ModelMapper modelMapper = new ModelMapper(); + try { + modelMapper.createTypeMap(TypeA.class, TypeB.class) + .addMappings(mapper -> mapper.skip(TypeA::getBox, TypeB::setBox)); + fail(); + } catch (ConfigurationException e) { + assertEquals(e.getErrorMessages().size(), 1); + assertEquals(e.getErrorMessages().iterator().next().getMessage(), + "Not able to skip box., because there are already nested properties are mapped: [box.param.]. " + + "Do you skip the property after the implicit mappings mapped? " + + "We recommended you to create an empty type map, and followed by addMappings and implicitMappings calls"); + } + modelMapper.map(typeA, typeB); + } +} diff --git a/core/src/test/java/org/modelmapper/bugs/GH654.java b/core/src/test/java/org/modelmapper/bugs/GH654.java new file mode 100644 index 00000000..fd365622 --- /dev/null +++ b/core/src/test/java/org/modelmapper/bugs/GH654.java @@ -0,0 +1,130 @@ +package org.modelmapper.bugs; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import org.modelmapper.AbstractTest; +import org.modelmapper.ConfigurationException; +import org.modelmapper.spi.ErrorMessage; +import org.testng.annotations.Test; + +@Test +public class GH654 extends AbstractTest { + + static class A { + private String field1; + private String field2; + private B b; + + public String getField1() { + return field1; + } + + public void setField1(String field1) { + this.field1 = field1; + } + + public String getField2() { + return field2; + } + + public void setField2(String field2) { + this.field2 = field2; + } + + public B getB() { + return b; + } + + public void setB(B b) { + this.b = b; + } + } + + static class B { + private String field1; + private String field2; + + public String getField1() { + return field1; + } + + public void setField1(String field1) { + this.field1 = field1; + } + + public String getField2() { + return field2; + } + + public void setField2(String field2) { + this.field2 = field2; + } + } + + private static class ADto { + private String field1; + private String field2; + private BDto b; + + public String getField1() { + return field1; + } + + public void setField1(String field1) { + this.field1 = field1; + } + + public String getField2() { + return field2; + } + + public void setField2(String field2) { + this.field2 = field2; + } + + public BDto getB() { + return b; + } + + public void setB(BDto b) { + this.b = b; + } + } + + static class BDto { + private String field1; + private String field2; + + public String getField1() { + return field1; + } + + public void setField1(String field1) { + this.field1 = field1; + } + + public String getField2() { + return field2; + } + + public void setField2(String field2) { + this.field2 = field2; + } + } + + public void testSkipConflict() { + try { + modelMapper.typeMap(A.class, ADto.class) + .addMappings(mapper -> mapper.skip(ADto::setB)); + fail(); + } catch (ConfigurationException e) { + assertEquals(e.getErrorMessages().size(), 1); + assertEquals(e.getErrorMessages().iterator().next().getMessage(), + "Not able to skip b., because there are already nested properties are mapped: [b.field1. b.field2.]. " + + "Do you skip the property after the implicit mappings mapped? " + + "We recommended you to create an empty type map, and followed by addMappings and implicitMappings calls"); + } + } +} diff --git a/core/src/test/java/org/modelmapper/functional/builder/BuilderTest.java b/core/src/test/java/org/modelmapper/functional/builder/BuilderTest.java index 5c1425d2..ccc0f52c 100644 --- a/core/src/test/java/org/modelmapper/functional/builder/BuilderTest.java +++ b/core/src/test/java/org/modelmapper/functional/builder/BuilderTest.java @@ -100,8 +100,8 @@ public void shouldMap() { Source source = new Source("foo", "bar"); Destination destination = modelMapper.map(source, Destination.Builder.class).build(); - assertEquals("foo", destination.foo); - assertEquals("bar", destination.bar); + assertEquals(destination.foo, "foo"); + assertEquals(destination.bar, "bar"); } public void shouldMapWithDifferentPrefix() { @@ -112,7 +112,7 @@ public void shouldMapWithDifferentPrefix() { Source source = new Source("foo", "bar"); Destination destination = modelMapper.map(source, Destination.BuilderWith.class).build(); - assertEquals("foo", destination.foo); - assertEquals("bar", destination.bar); + assertEquals(destination.foo, "foo"); + assertEquals(destination.bar, "bar"); } } diff --git a/core/src/test/java/org/modelmapper/internal/converter/BooleanConverterTest.java b/core/src/test/java/org/modelmapper/internal/converter/BooleanConverterTest.java index 42f35aad..1ed97f74 100644 --- a/core/src/test/java/org/modelmapper/internal/converter/BooleanConverterTest.java +++ b/core/src/test/java/org/modelmapper/internal/converter/BooleanConverterTest.java @@ -47,9 +47,9 @@ public void shouldThrowOnInvalidString() { protected void testConversionValues(String[] trueValues, String[] falseValues) { for (int i = 0; i < trueValues.length; i++) - assertEquals(Boolean.TRUE, convert(trueValues[i])); + assertEquals(convert(trueValues[i]), Boolean.TRUE); for (int i = 0; i < falseValues.length; i++) - assertEquals(Boolean.FALSE, convert(falseValues[i])); + assertEquals(convert(falseValues[i]), Boolean.FALSE); } public void testSupported() { diff --git a/core/src/test/java/org/modelmapper/internal/converter/NumberConverterTest.java b/core/src/test/java/org/modelmapper/internal/converter/NumberConverterTest.java index f7ae94c7..1bc5e19a 100644 --- a/core/src/test/java/org/modelmapper/internal/converter/NumberConverterTest.java +++ b/core/src/test/java/org/modelmapper/internal/converter/NumberConverterTest.java @@ -239,8 +239,8 @@ public void shouldThrowOnNotANumber() { @Test(dataProvider = "typesProvider") public void testBooleanToNumber(Class type) { - assertEquals(0, ((Number) convert(Boolean.FALSE, type)).intValue()); - assertEquals(1, ((Number) convert(Boolean.TRUE, type)).intValue()); + assertEquals(((Number) convert(Boolean.FALSE, type)).intValue(), 0); + assertEquals(((Number) convert(Boolean.TRUE, type)).intValue(), 1); } public void testInvalidByteAmount() { @@ -253,13 +253,13 @@ public void testInvalidByteAmount() { assertEquals(new Byte(Byte.MAX_VALUE), convert(max, Byte.class)); try { - assertEquals(null, convert(minMinusOne, Byte.class)); + assertEquals(convert(minMinusOne, Byte.class), null); fail(); } catch (Exception e) { } try { - assertEquals(null, convert(maxPlusOne, Byte.class)); + assertEquals(convert(maxPlusOne, Byte.class), null); fail(); } catch (Exception e) { } @@ -272,7 +272,7 @@ public void testInvalidFloatAmount() { assertEquals(new Float(Float.MAX_VALUE), convert(max, Float.class)); try { - assertEquals(null, convert(tooBig, Float.class)); + assertEquals(convert(tooBig, Float.class), null); fail("More than maximum, expected ConversionException"); } catch (Exception expected) { } @@ -288,13 +288,13 @@ public void testInvalidIntegerAmount() { assertEquals(new Integer(Integer.MAX_VALUE), convert(max, Integer.class)); try { - assertEquals(null, convert(minMinusOne, Integer.class)); + assertEquals(convert(minMinusOne, Integer.class), null); fail("Less than minimum, expected ConversionException"); } catch (Exception expected) { } try { - assertEquals(null, convert(maxPlusOne, Integer.class)); + assertEquals(convert(maxPlusOne, Integer.class), null); fail("More than maximum, expected ConversionException"); } catch (Exception expected) { } @@ -310,13 +310,13 @@ public void testInvalidShortAmount() { assertEquals(new Short(Short.MAX_VALUE), convert(max, Short.class)); try { - assertEquals(null, convert(minMinusOne, Short.class)); + assertEquals(convert(minMinusOne, Short.class), null); fail("Less than minimum, expected ConversionException"); } catch (Exception expected) { } try { - assertEquals(null, convert(maxPlusOne, Short.class)); + assertEquals(convert(maxPlusOne, Short.class), null); fail("More than maximum, expected ConversionException"); } catch (Exception expected) { } diff --git a/core/src/test/java/org/modelmapper/internal/converter/UuidConverterTest.java b/core/src/test/java/org/modelmapper/internal/converter/UuidConverterTest.java new file mode 100644 index 00000000..75719b9a --- /dev/null +++ b/core/src/test/java/org/modelmapper/internal/converter/UuidConverterTest.java @@ -0,0 +1,27 @@ +package org.modelmapper.internal.converter; + +import static org.testng.Assert.assertEquals; + +import java.util.UUID; +import org.modelmapper.spi.ConditionalConverter.MatchResult; +import org.testng.annotations.Test; + +@Test +public class UuidConverterTest extends AbstractConverterTest { + UuidConverterTest() { + super(new UuidConverter()); + } + + public void testConvert() { + UUID uuid = UUID.randomUUID(); + assertEquals(convert(uuid.toString()), uuid); + assertEquals(convert(uuid.toString().toCharArray()), uuid); + } + + public void testSupported() { + assertEquals(converter.match(char[].class, UUID.class), MatchResult.FULL); + assertEquals(converter.match(String.class, UUID.class), MatchResult.FULL); + assertEquals(converter.match(byte[].class, UUID.class), MatchResult.PARTIAL); + assertEquals(converter.match(String.class, String.class), MatchResult.NONE); + } +} diff --git a/examples/pom.xml b/examples/pom.xml index 90abb571..94951933 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -4,7 +4,7 @@ org.modelmapper modelmapper-parent - 3.1.0 + 3.2.1-SNAPSHOT modelmapper-examples diff --git a/extensions/dagger/pom.xml b/extensions/dagger/pom.xml index 5a31862c..14243e09 100644 --- a/extensions/dagger/pom.xml +++ b/extensions/dagger/pom.xml @@ -5,7 +5,7 @@ org.modelmapper.extensions modelmapper-extensions - 3.1.0 + 3.2.1-SNAPSHOT modelmapper-dagger diff --git a/extensions/gson/pom.xml b/extensions/gson/pom.xml index 1c78359b..52ded1c6 100644 --- a/extensions/gson/pom.xml +++ b/extensions/gson/pom.xml @@ -5,7 +5,7 @@ org.modelmapper.extensions modelmapper-extensions - 3.1.0 + 3.2.1-SNAPSHOT modelmapper-gson diff --git a/extensions/guice/pom.xml b/extensions/guice/pom.xml index b74eedcc..b213ff4e 100644 --- a/extensions/guice/pom.xml +++ b/extensions/guice/pom.xml @@ -5,7 +5,7 @@ org.modelmapper.extensions modelmapper-extensions - 3.1.0 + 3.2.1-SNAPSHOT modelmapper-guice diff --git a/extensions/jackson/pom.xml b/extensions/jackson/pom.xml index 3313755d..fbc014f2 100644 --- a/extensions/jackson/pom.xml +++ b/extensions/jackson/pom.xml @@ -5,7 +5,7 @@ org.modelmapper.extensions modelmapper-extensions - 3.1.0 + 3.2.1-SNAPSHOT modelmapper-jackson diff --git a/extensions/jooq/pom.xml b/extensions/jooq/pom.xml index 272a8336..4859b08b 100644 --- a/extensions/jooq/pom.xml +++ b/extensions/jooq/pom.xml @@ -5,7 +5,7 @@ org.modelmapper.extensions modelmapper-extensions - 3.1.0 + 3.2.1-SNAPSHOT modelmapper-jooq diff --git a/extensions/pom.xml b/extensions/pom.xml index ff2fb674..c784f926 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -5,7 +5,7 @@ org.modelmapper modelmapper-parent - 3.1.0 + 3.2.1-SNAPSHOT pom diff --git a/extensions/protobuf/pom.xml b/extensions/protobuf/pom.xml index 3ffafde0..71816a2a 100644 --- a/extensions/protobuf/pom.xml +++ b/extensions/protobuf/pom.xml @@ -3,7 +3,7 @@ modelmapper-extensions org.modelmapper.extensions - 3.1.0 + 3.2.1-SNAPSHOT 4.0.0 modelmapper-protobuf diff --git a/extensions/spring/pom.xml b/extensions/spring/pom.xml index 534eb090..5796b021 100644 --- a/extensions/spring/pom.xml +++ b/extensions/spring/pom.xml @@ -5,7 +5,7 @@ org.modelmapper.extensions modelmapper-extensions - 3.1.0 + 3.2.1-SNAPSHOT modelmapper-spring diff --git a/pom.xml b/pom.xml index 6391b8f0..a84b702b 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ pom org.modelmapper modelmapper-parent - 3.1.0 + 3.2.1-SNAPSHOT ModelMapper Parent Simple, Intelligent, Object Mapping http://modelmapper.org @@ -21,10 +21,10 @@ 1.8 1.8 3.3.0 - 9.2 + 9.6 3.2 0.6.3 - 1.12.3 + 1.14.9 3.12.1.GA 2.0.206 5.6.3.Final