Skip to content

Commit

Permalink
Fix generation of enum implementations as a sealed class in JDK17 (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo authored Jun 18, 2024
1 parent c02ef9b commit f3051b8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/content/v1.0.x-kor/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ menu:
docs:
weight: 100
---
sectionStart
### v.1.0.20
Fix generation of enum implementations as a sealed class in JDK17.

sectionEnd

sectionStart
### v.1.0.19
Expand Down
6 changes: 6 additions & 0 deletions docs/content/v1.0.x/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ docs:
weight: 100
---

sectionStart
### v.1.0.20
Fix generation of enum implementations as a sealed class in JDK17.

sectionEnd

sectionStart
### v.1.0.19
Fix a SimpleValuePlugin "out of byte range" error when generate Byte.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class JdkVariantOptions {

public void apply(FixtureMonkeyOptionsBuilder optionsBuilder) {
optionsBuilder.insertFirstArbitraryObjectPropertyGenerator(
p -> Types.getActualType(p.getType()).isSealed(),
p -> Types.getActualType(p.getType()).isSealed() && !Types.getActualType(p.getType()).isEnum(),
SEALED_TYPE_OBJECT_PROPERTY_GENERATOR
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

import static com.navercorp.fixturemonkey.tests.TestEnvironment.TEST_COUNT;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenNoException;

import org.junit.jupiter.api.RepeatedTest;

import com.navercorp.fixturemonkey.FixtureMonkey;
import com.navercorp.fixturemonkey.jackson.plugin.JacksonPlugin;
import com.navercorp.fixturemonkey.tests.java17.RecordTestSpecs.ContainerRecord;
import com.navercorp.fixturemonkey.tests.java17.RecordTestSpecs.DateTimeRecord;
import com.navercorp.fixturemonkey.tests.java17.RecordTestSpecs.EnumClass;
import com.navercorp.fixturemonkey.tests.java17.RecordTestSpecs.JavaTypeRecord;

class JacksonRecordTest {
Expand Down Expand Up @@ -81,4 +83,9 @@ void fixedContainer() {

then(actual).isNotNull();
}

@RepeatedTest(TEST_COUNT)
void sampleEnum() {
thenNoException().isThrownBy(() -> SUT.giveMeOne(EnumClass.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,21 @@ public record CompactConstructorRecord(
string = "12345";
}
}

public enum EnumClass {
ENUM_A {
@Override
public String getString() {
return "a";
}
},
ENUM_B {
@Override
public String getString() {
return "b";
}
};

public abstract String getString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

import static com.navercorp.fixturemonkey.tests.TestEnvironment.TEST_COUNT;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenNoException;

import java.beans.ConstructorProperties;

import org.junit.jupiter.api.RepeatedTest;

import com.navercorp.fixturemonkey.FixtureMonkey;
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector;
import com.navercorp.fixturemonkey.tests.java17.RecordTestSpecs.EnumClass;

class SealedClassTest {
private static final FixtureMonkey SUT = FixtureMonkey.builder()
Expand Down Expand Up @@ -97,4 +99,9 @@ void fixedSealedClassProperty() {
then(actual.sealedInterface()).isInstanceOf(SealedInterfaceImpl.class);
then(actual.sealedClass()).isInstanceOf(SealedClassImpl.class);
}

@RepeatedTest(TEST_COUNT)
void sampleEnum() {
thenNoException().isThrownBy(() -> SUT.giveMeOne(EnumClass.class));
}
}

0 comments on commit f3051b8

Please sign in to comment.