From 64d37e7181926b923702767d1374256ddc3a981e Mon Sep 17 00:00:00 2001 From: Rawvoid Date: Tue, 3 Feb 2026 22:12:03 +0800 Subject: [PATCH] test(normalize-class): add tests and schema for class normalization --- .../jaxb/plugin/NormalizeClassPluginTest.java | 54 ++++++++++++++++++ .../test/resources/schema/normalize-class.xsd | 55 +++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 plugins/src/test/java/io/github/rawvoid/jaxb/plugin/NormalizeClassPluginTest.java create mode 100644 plugins/src/test/resources/schema/normalize-class.xsd diff --git a/plugins/src/test/java/io/github/rawvoid/jaxb/plugin/NormalizeClassPluginTest.java b/plugins/src/test/java/io/github/rawvoid/jaxb/plugin/NormalizeClassPluginTest.java new file mode 100644 index 0000000..ff0546b --- /dev/null +++ b/plugins/src/test/java/io/github/rawvoid/jaxb/plugin/NormalizeClassPluginTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2026 Rawvoid(https://github.com/rawvoid) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.github.rawvoid.jaxb.plugin; + +import io.github.rawvoid.jaxb.AbstractXJCMojoTestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +public class NormalizeClassPluginTest extends AbstractXJCMojoTestCase { + + @BeforeEach + void setSchema() { + schemaIncludes = List.of("normalize-class.xsd"); + } + + @Test + void testNormalizeDuplicateClasses() throws Exception { + var args = List.of( + "-Xnormalize-class" + ); + var classes = testExecute(args, ".*", null); + var classBySimpleName = classes.stream() + .collect(Collectors.groupingBy(Class::getSimpleName)); + + assertThat(classBySimpleName).containsKeys("NormalizeRoot", "Group", "AnotherGroup", "Entry"); + assertThat(classBySimpleName.get("Entry")).hasSize(1); + + var groupClass = classBySimpleName.get("Group").getFirst(); + var anotherGroupClass = classBySimpleName.get("AnotherGroup").getFirst(); + var entryClass = classBySimpleName.get("Entry").getFirst(); + + assertThat(groupClass.getDeclaredField("entry").getType()).isEqualTo(entryClass); + assertThat(anotherGroupClass.getDeclaredField("entry").getType()).isEqualTo(entryClass); + } +} diff --git a/plugins/src/test/resources/schema/normalize-class.xsd b/plugins/src/test/resources/schema/normalize-class.xsd new file mode 100644 index 0000000..1be182a --- /dev/null +++ b/plugins/src/test/resources/schema/normalize-class.xsd @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +