Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
55 changes: 55 additions & 0 deletions plugins/src/test/resources/schema/normalize-class.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.github.com/rawvoid/xjc-plugins/normalize"
xmlns:tns="https://www.github.com/rawvoid/xjc-plugins/normalize"
elementFormDefault="qualified">

<xs:complexType name="NormalizeRoot">
<xs:sequence>
<xs:element name="group">
<xs:complexType>
<xs:sequence>
<xs:element name="entry">
<xs:complexType>
<xs:sequence>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="anotherGroup">
<xs:complexType>
<xs:sequence>
<xs:element name="entry">
<xs:complexType>
<xs:sequence>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>

<xs:element name="normalizeRoot" type="tns:NormalizeRoot"/>
</xs:schema>