Skip to content

Commit beab008

Browse files
committed
Tests for empty elements, see highsource/jsonix#71.
1 parent 8c1d619 commit beab008

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.hisrc.jsonix.xml.bind.tests;
2+
3+
import java.util.Date;
4+
5+
import javax.xml.bind.annotation.XmlAccessType;
6+
import javax.xml.bind.annotation.XmlAccessorType;
7+
import javax.xml.bind.annotation.XmlElement;
8+
import javax.xml.bind.annotation.XmlRootElement;
9+
10+
@XmlRootElement
11+
@XmlAccessorType(XmlAccessType.FIELD)
12+
public class BType {
13+
14+
@XmlElement
15+
public Integer one;
16+
17+
@XmlElement(defaultValue = "2")
18+
public Integer two;
19+
20+
@XmlElement(nillable = true)
21+
public Integer three;
22+
23+
@XmlElement(nillable = true, defaultValue = "4")
24+
public Integer four;
25+
26+
@XmlElement
27+
public Date five;
28+
29+
@XmlElement
30+
public Date six;
31+
}

compiler/src/test/java/org/hisrc/jsonix/xml/bind/tests/EmptyXmlElementTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.hisrc.jsonix.xml.bind.tests;
22

3+
import java.io.StringReader;
34
import java.io.StringWriter;
45

56
import javax.xml.bind.JAXBContext;
67
import javax.xml.bind.JAXBException;
78
import javax.xml.bind.Marshaller;
9+
import javax.xml.bind.Unmarshaller;
810

911
import org.junit.Assert;
1012
import org.junit.Test;
@@ -49,4 +51,17 @@ public void checksDefault() throws JAXBException {
4951
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><aType><one></one><two>two</two><three></three><four>four</four></aType>", sw.toString());
5052

5153
}
54+
55+
@Test
56+
public void checksInteger() throws JAXBException {
57+
final JAXBContext context = JAXBContext.newInstance(BType.class);
58+
final Unmarshaller unmarshaller = context.createUnmarshaller();
59+
final String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><bType><one></one><two></two><three></three><four></four><five></five></bType>";
60+
final BType bType = (BType) unmarshaller.unmarshal(new StringReader(str));
61+
Assert.assertEquals(0, bType.one.intValue());
62+
Assert.assertEquals(2, bType.two.intValue());
63+
Assert.assertEquals(0, bType.three.intValue());
64+
Assert.assertEquals(4, bType.four.intValue());
65+
66+
}
5267
}

0 commit comments

Comments
 (0)