Skip to content

Commit c5a67ca

Browse files
authored
Merge pull request #54
test(normalize-class): add tests and schema for class normalization
2 parents d6d674d + 64d37e7 commit c5a67ca

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2026 Rawvoid(https://github.com/rawvoid)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.github.rawvoid.jaxb.plugin;
18+
19+
import io.github.rawvoid.jaxb.AbstractXJCMojoTestCase;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
22+
23+
import java.util.List;
24+
import java.util.stream.Collectors;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
public class NormalizeClassPluginTest extends AbstractXJCMojoTestCase {
29+
30+
@BeforeEach
31+
void setSchema() {
32+
schemaIncludes = List.of("normalize-class.xsd");
33+
}
34+
35+
@Test
36+
void testNormalizeDuplicateClasses() throws Exception {
37+
var args = List.of(
38+
"-Xnormalize-class"
39+
);
40+
var classes = testExecute(args, ".*", null);
41+
var classBySimpleName = classes.stream()
42+
.collect(Collectors.groupingBy(Class::getSimpleName));
43+
44+
assertThat(classBySimpleName).containsKeys("NormalizeRoot", "Group", "AnotherGroup", "Entry");
45+
assertThat(classBySimpleName.get("Entry")).hasSize(1);
46+
47+
var groupClass = classBySimpleName.get("Group").getFirst();
48+
var anotherGroupClass = classBySimpleName.get("AnotherGroup").getFirst();
49+
var entryClass = classBySimpleName.get("Entry").getFirst();
50+
51+
assertThat(groupClass.getDeclaredField("entry").getType()).isEqualTo(entryClass);
52+
assertThat(anotherGroupClass.getDeclaredField("entry").getType()).isEqualTo(entryClass);
53+
}
54+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2026 Rawvoid(https://github.com/rawvoid)
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
19+
targetNamespace="https://www.github.com/rawvoid/xjc-plugins/normalize"
20+
xmlns:tns="https://www.github.com/rawvoid/xjc-plugins/normalize"
21+
elementFormDefault="qualified">
22+
23+
<xs:complexType name="NormalizeRoot">
24+
<xs:sequence>
25+
<xs:element name="group">
26+
<xs:complexType>
27+
<xs:sequence>
28+
<xs:element name="entry">
29+
<xs:complexType>
30+
<xs:sequence>
31+
<xs:element name="value" type="xs:string"/>
32+
</xs:sequence>
33+
</xs:complexType>
34+
</xs:element>
35+
</xs:sequence>
36+
</xs:complexType>
37+
</xs:element>
38+
<xs:element name="anotherGroup">
39+
<xs:complexType>
40+
<xs:sequence>
41+
<xs:element name="entry">
42+
<xs:complexType>
43+
<xs:sequence>
44+
<xs:element name="value" type="xs:string"/>
45+
</xs:sequence>
46+
</xs:complexType>
47+
</xs:element>
48+
</xs:sequence>
49+
</xs:complexType>
50+
</xs:element>
51+
</xs:sequence>
52+
</xs:complexType>
53+
54+
<xs:element name="normalizeRoot" type="tns:NormalizeRoot"/>
55+
</xs:schema>

0 commit comments

Comments
 (0)