Skip to content

Commit

Permalink
ImmutableProxy: Add support for File, Path and URI
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaldvogel committed Dec 9, 2019
1 parent 7798809 commit 08354bd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import static net.bytebuddy.matcher.ElementMatchers.*;

import java.io.File;
import java.lang.annotation.Annotation;
import java.net.URI;
import java.nio.file.Path;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAmount;
import java.util.Collection;
Expand Down Expand Up @@ -93,6 +96,12 @@ static boolean isImmutable(Object value) {
return true;
} else if (value instanceof UUID) {
return true;
} else if (value instanceof File) {
return true;
} else if (value instanceof Path) {
return true;
} else if (value instanceof URI) {
return true;
} else if (isEnumValue(value)) {
return true;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/de/cronn/reflection/util/PropertyUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ public void testGetPropertyDescriptorsOfTestEntityClass() throws Exception {
"propertyWithoutField",
"someArrayList",
"someCollection",
"someFile",
"someInstant",
"someIterable",
"someList",
"someMap",
"someObject",
"somePath",
"someSet",
"someTreeMap",
"someUri",
"someUuid",
"string"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static org.assertj.core.api.Assertions.*;

import java.io.File;
import java.net.URI;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
Expand Down Expand Up @@ -85,6 +88,9 @@ public void testImmutableProxy_TestEntity() throws Exception {
TestEntity original = new TestEntity(123);
original.setSomeInstant(Instant.parse("2018-07-12T13:38:56Z"));
original.setSomeUuid(UUID.fromString("28e93b24-7252-43d8-a223-ca0b3270bd7f"));
original.setSomeFile(new File("some-file"));
original.setSomePath(Paths.get("some path"));
original.setSomeUri(new URI("file://some-path"));
original.setSomeList(Arrays.asList(new OtherTestEntity("one"), new OtherTestEntity("other")));
original.setSomeSet(new LinkedHashSet<>(Arrays.asList("a", "b", "c")));

Expand Down Expand Up @@ -120,6 +126,9 @@ public void testImmutableProxy_TestEntity() throws Exception {
assertThat(immutableProxy.asMyself()).isInstanceOf(Immutable.class);
assertThat(immutableProxy.asMyself().getSomeInstant()).isSameAs(original.getSomeInstant());
assertThat(immutableProxy.asMyself().getSomeUuid()).isSameAs(original.getSomeUuid());
assertThat(immutableProxy.asMyself().getSomeFile()).isSameAs(original.getSomeFile());
assertThat(immutableProxy.asMyself().getSomePath()).isSameAs(original.getSomePath());
assertThat(immutableProxy.asMyself().getSomeUri()).isSameAs(original.getSomeUri());
}

@Test
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/de/cronn/reflection/util/testclasses/TestEntity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package de.cronn.reflection.util.testclasses;

import java.io.File;
import java.io.Serializable;
import java.net.URI;
import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -35,6 +38,12 @@ public class TestEntity extends AbstractClassWithAnnotatedMethods implements Int

private UUID someUuid;

private File someFile;

private Path somePath;

private URI someUri;

private OtherTestEntity otherTestEntity;

private List<OtherTestEntity> someList;
Expand Down Expand Up @@ -115,6 +124,30 @@ public void setSomeUuid(UUID someUuid) {
this.someUuid = someUuid;
}

public File getSomeFile() {
return someFile;
}

public void setSomeFile(File someFile) {
this.someFile = someFile;
}

public Path getSomePath() {
return somePath;
}

public void setSomePath(Path somePath) {
this.somePath = somePath;
}

public URI getSomeUri() {
return someUri;
}

public void setSomeUri(URI someUri) {
this.someUri = someUri;
}

public OtherTestEntity getOtherTestEntity() {
return otherTestEntity;
}
Expand Down

0 comments on commit 08354bd

Please sign in to comment.