Skip to content

Commit

Permalink
fixup! fix: use appropriate methods to convert the numbers in XML
Browse files Browse the repository at this point in the history
Add test
  • Loading branch information
emanuelaepure10 committed May 31, 2024
1 parent 3a7b521 commit 504371e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ xsi:schemaLocation="http://www.example.com shiporder.xsd">
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
<price>0E-11</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
<priceInteger>123</priceInteger>
<priceDouble>12.3</priceDouble>
<priceFloat>123.456</priceFloat>
<priceLong>1234567890123456789</priceLong>
<priceShort>12345</priceShort>
</item>
</shiporder>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
<xs:element name="priceInteger" type="xs:int"/>
<xs:element name="priceDouble" type="xs:double"/>
<xs:element name="priceFloat" type="xs:float"/>
<xs:element name="priceLong" type="xs:long"/>
<xs:element name="priceShort" type="xs:short"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URI;
import java.util.Collection;

Expand Down Expand Up @@ -162,8 +163,6 @@ public void testLoadShiporder() throws Exception {

Object[] orderid = instance.getProperty(new QName("orderid")); // attribute
// form
// not
// qualified
assertNotNull(orderid);
assertEquals(1, orderid.length);
assertEquals("889923", orderid[0]);
Expand Down Expand Up @@ -213,6 +212,11 @@ public void testLoadShiporder() throws Exception {
assertEquals(1, title1.length);
assertEquals("Empire Burlesque", title1[0]);

Object[] price1 = ((Instance) item1).getProperty(new QName(ns, "price"));
assertNotNull(price1);
BigDecimal bigDecimal = new BigDecimal("0.00000000000");
assertEquals(bigDecimal, price1[0]);

// item 2
Object item2 = items[1];
assertTrue(item2 instanceof Instance);
Expand All @@ -222,6 +226,35 @@ public void testLoadShiporder() throws Exception {
assertEquals(1, title2.length);
assertEquals("Hide your heart", title2[0]);

Object[] price2 = ((Instance) item2).getProperty(new QName(ns, "price"));
assertNotNull(price2);
bigDecimal = new BigDecimal("9.90");
assertEquals(bigDecimal, price2[0]);

Object[] priceInteger = ((Instance) item2).getProperty(new QName(ns, "priceInteger"));
int intNumber = 123;
assertEquals(intNumber, priceInteger[0]);

// Double
Object[] priceDouble = ((Instance) item2).getProperty(new QName(ns, "priceDouble"));
double doubleNumber = 12.3;
assertEquals(doubleNumber, priceDouble[0]);

// Float
Object[] priceFloat = ((Instance) item2).getProperty(new QName(ns, "priceFloat"));
float floatNumber = 123.456F;
assertEquals(floatNumber, priceFloat[0]);

// Long
Object[] priceLong = ((Instance) item2).getProperty(new QName(ns, "priceLong"));
long longNumber = 1234567890123456789L;
assertEquals(longNumber, priceLong[0]);

// short
Object[] priceShort = ((Instance) item2).getProperty(new QName(ns, "priceShort"));
short shortNumber = 12345;
assertEquals(shortNumber, priceShort[0]);

// only one object
assertFalse(it.hasNext());
} finally {
Expand Down

0 comments on commit 504371e

Please sign in to comment.