Skip to content

Commit bd99c9e

Browse files
committed
xjc:javaType test.
1 parent 99d3c97 commit bd99c9e

File tree

8 files changed

+104
-5
lines changed

8 files changed

+104
-5
lines changed

tests/one/.classpath

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="src" output="target/classes" path="src/main/resources"/>
4-
<classpathentry kind="src" output="target/classes" path="target/generated-sources/xjc"/>
5-
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
6-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
7-
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
3+
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/resources"/>
4+
<classpathentry including="**/*.java" kind="src" output="target/classes" path="target/generated-sources/xjc">
5+
<attributes>
6+
<attribute name="optional" value="true"/>
7+
<attribute name="maven.pomderived" value="true"/>
8+
</attributes>
9+
</classpathentry>
10+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
11+
<attributes>
12+
<attribute name="optional" value="true"/>
13+
<attribute name="maven.pomderived" value="true"/>
14+
</attributes>
15+
</classpathentry>
16+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
17+
<attributes>
18+
<attribute name="maven.pomderived" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="src" output="target/classes" path="src/main/java">
22+
<attributes>
23+
<attribute name="optional" value="true"/>
24+
<attribute name="maven.pomderived" value="true"/>
25+
</attributes>
26+
</classpathentry>
27+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
28+
<attributes>
29+
<attribute name="maven.pomderived" value="true"/>
30+
</attributes>
31+
</classpathentry>
32+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
33+
<attributes>
34+
<attribute name="maven.pomderived" value="true"/>
35+
</attributes>
36+
</classpathentry>
837
<classpathentry kind="output" path="target/classes"/>
938
</classpath>

tests/one/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

tests/one/.project

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<arguments>
1111
</arguments>
1212
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
1318
</buildSpec>
1419
<natures>
1520
<nature>org.eclipse.jdt.core.javanature</nature>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
eclipse.preferences.version=1
2+
encoding//src/main/java=UTF-8
3+
encoding//src/main/resources=UTF-8
4+
encoding//src/test/java=UTF-8
5+
encoding//src/test/resources=UTF-8
6+
encoding//target/generated-sources/xjc=UTF-8
7+
encoding/<project>=UTF-8
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3+
org.eclipse.jdt.core.compiler.compliance=1.6
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.source=1.6
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.jvnet.jaxb2_commons.tests.one;
2+
3+
import javax.xml.bind.annotation.adapters.XmlAdapter;
4+
5+
public class CustomBooleanAdapter extends XmlAdapter<String, Boolean> {
6+
@Override
7+
public Boolean unmarshal(String s) {
8+
if("true".equals(s) || "false".equals(s)){
9+
return Boolean.valueOf(s);
10+
}
11+
return null;
12+
13+
}
14+
15+
@Override
16+
public String marshal(Boolean c) {
17+
return c == null ? null : c.toString();
18+
}
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.jvnet.jaxb2_commons.tests.one;
2+
3+
import java.io.StringWriter;
4+
5+
import javax.xml.bind.JAXBContext;
6+
import javax.xml.bind.JAXBElement;
7+
import javax.xml.bind.JAXBException;
8+
import javax.xml.namespace.QName;
9+
10+
import org.junit.Assert;
11+
import org.junit.Test;
12+
13+
public class JavaTypeExampleTest {
14+
15+
@Test
16+
public void rountripsBoolean() throws JAXBException {
17+
final JAXBContext context = JAXBContext
18+
.newInstance(JavaTypeExample.class);
19+
20+
final JavaTypeExample value = new JavaTypeExample();
21+
value.setCustomBooleanProperty(true);
22+
final StringWriter sw = new StringWriter();
23+
context.createMarshaller().marshal(
24+
new JAXBElement<JavaTypeExample>(new QName("test"),
25+
JavaTypeExample.class, value), sw);
26+
Assert.assertTrue(sw.toString().contains(">true<"));
27+
// System.out.println(sw.toString());
28+
}
29+
}

0 commit comments

Comments
 (0)