Modified: xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/methodNameCollision/checkin/NameCollisionTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/methodNameCollision/checkin/NameCollisionTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/methodNameCollision/checkin/NameCollisionTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/methodNameCollision/checkin/NameCollisionTest.java Sun Feb 6 01:51:55 2022 @@ -19,16 +19,16 @@ import interfaceFeature.xbean.methodName import interfaceFeature.xbean.methodNameCollision.company.ConsultantType; import interfaceFeature.xbean.methodNameCollision.company.DepartmentType; import org.apache.xmlbeans.XmlString; -import org.junit.Test; +import org.junit.jupiter.api.Test; import xmlobject.extensions.interfaceFeature.methodNameCollision.existing.IFoo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class NameCollisionTest { @Test - public void test() { + void test() { CompanyDocument poDoc; poDoc = CompanyDocument.Factory.newInstance();
Modified: xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/multInterfaces/checkin/MultInterfacesTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/multInterfaces/checkin/MultInterfacesTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/multInterfaces/checkin/MultInterfacesTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/multInterfaces/checkin/MultInterfacesTest.java Sun Feb 6 01:51:55 2022 @@ -19,16 +19,16 @@ import interfaceFeature.xbean.multInterf import interfaceFeature.xbean.multInterfaces.purchaseOrder.PurchaseOrderDocument; import interfaceFeature.xbean.multInterfaces.purchaseOrder.PurchaseOrderType; import org.apache.xmlbeans.XmlObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MultInterfacesTest { @Test - public void test() { + void test() { PurchaseOrderDocument poDoc = null; poDoc = PurchaseOrderDocument.Factory.newInstance(); @@ -45,50 +45,49 @@ public class MultInterfacesTest { po.setItems(items); StringBuilder sb = new StringBuilder(); - sb.append( - "<pur:purchaseOrder xmlns:pur=\"http://xbean.interface_feature/multInterfaces/PurchaseOrder\">"); - + sb.append("<pur:purchaseOrder xmlns:pur=\"http://xbean.interface_feature/multInterfaces/PurchaseOrder\">"); sb.append("<pur:items>"); StringBuilder sbContent = new StringBuilder(); - for (int i = 0; i < LEN; i++) - sbContent.append("<pur:item><pur:USPrice>"+i+"</pur:USPrice></pur:item>"); + for (int i = 0; i < LEN; i++) { + sbContent.append("<pur:item><pur:USPrice>" + i + "</pur:USPrice></pur:item>"); + } int pos = sb.length(); sb.append("</pur:items></pur:purchaseOrder>"); - String sExpected = sb.subSequence(0, pos) + - sbContent.toString() + - sb.subSequence(pos, sb.length()); + String sExpected = sb.subSequence(0, pos) + sbContent.toString() + sb.subSequence(pos, sb.length()); assertEquals(sExpected, poDoc.xmlText()); assertEquals(0, poDoc.getMinPrice()); - int price=10; + int price = 10; - poDoc.setMinPrice((double)price); + poDoc.setMinPrice((double) price); sbContent = new StringBuilder(); - for (int i = 0; i < LEN; i++) - if( i< price ) - sbContent.append("<pur:item><pur:USPrice>"+price+"</pur:USPrice></pur:item>"); - else - sbContent.append("<pur:item><pur:USPrice>"+i+"</pur:USPrice></pur:item>"); + for (int i = 0; i < LEN; i++) { + if (i < price) { + sbContent.append("<pur:item><pur:USPrice>" + price + "</pur:USPrice></pur:item>"); + } else { + sbContent.append("<pur:item><pur:USPrice>" + i + "</pur:USPrice></pur:item>"); + } + } sExpected = sb.subSequence(0, pos) + - sbContent.toString() + - sb.subSequence(pos, sb.length()); + sbContent.toString() + + sb.subSequence(pos, sb.length()); assertEquals(sExpected, poDoc.xmlText()); assertEquals(price, poDoc.getMinPrice()); - int expTotal=(price-1)*price+(price+1+LEN) * (LEN-price) / 2; - assertEquals(expTotal,poDoc.getTotal()); + int expTotal = (price - 1) * price + (price + 1 + LEN) * (LEN - price) / 2; + assertEquals(expTotal, poDoc.getTotal()); XmlObject item = poDoc.getCheapestItem(); - Item expected=it[0]; + Item expected = it[0]; expected.setUSPrice(new BigDecimal(30d)); - // assertEquals(expected, item ); + // assertEquals(expected, item ); } } Modified: xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/readOnlyBean/checkin/ReadOnlyTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/readOnlyBean/checkin/ReadOnlyTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/readOnlyBean/checkin/ReadOnlyTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/extensions/interfaceFeature/readOnlyBean/checkin/ReadOnlyTest.java Sun Feb 6 01:51:55 2022 @@ -18,16 +18,16 @@ package xmlobject.extensions.interfaceFe import interfaceFeature.xbean.readOnlyBean.purchaseOrder.Items; import interfaceFeature.xbean.readOnlyBean.purchaseOrder.PurchaseOrderDocument; import interfaceFeature.xbean.readOnlyBean.purchaseOrder.PurchaseOrderType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; public class ReadOnlyTest { @Test - public void test() { + void test() { PurchaseOrderDocument poDoc; @@ -45,32 +45,23 @@ public class ReadOnlyTest { po.setItems(items); StringBuilder sb = new StringBuilder(); - sb.append( - "<pur:purchaseOrder xmlns:pur=\"http://xbean.interface_feature/readOnlyBean/PurchaseOrder\">"); - + sb.append("<pur:purchaseOrder xmlns:pur=\"http://xbean.interface_feature/readOnlyBean/PurchaseOrder\">"); sb.append("<pur:items>"); StringBuilder sbContent = new StringBuilder(); - for (int i = 0; i < LEN; i++) + for (int i = 0; i < LEN; i++) { sbContent.append("<pur:item><pur:USPrice>4</pur:USPrice></pur:item>"); + } int pos = sb.length(); sb.append("</pur:items></pur:purchaseOrder>"); - String sExpected = sb.subSequence(0, pos) + - sbContent.toString() + - sb.subSequence(pos, sb.length()); + String sExpected = sb.subSequence(0, pos) + sbContent.toString() + sb.subSequence(pos, sb.length()); assertEquals(sExpected, poDoc.xmlText()); - try { - poDoc.setPrice(10); - - } catch (Exception t) { - t.printStackTrace(System.err); - System.exit(-1); - } + poDoc.setPrice(10); - assertTrue(!poDoc.validate()); + assertFalse(poDoc.validate()); } } Modified: xmlbeans/trunk/src/test/java/xmlobject/extensions/prePostFeature/ValueRestriction/checkin/ValueRestrictionTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/extensions/prePostFeature/ValueRestriction/checkin/ValueRestrictionTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/extensions/prePostFeature/ValueRestriction/checkin/ValueRestrictionTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/extensions/prePostFeature/ValueRestriction/checkin/ValueRestrictionTest.java Sun Feb 6 01:51:55 2022 @@ -15,20 +15,20 @@ package xmlobject.extensions.prePostFeature.ValueRestriction.checkin; import org.apache.xmlbeans.XmlString; -import org.junit.Test; +import org.junit.jupiter.api.Test; import prePostFeature.xbean.valueRestriction.company.CompanyDocument; import prePostFeature.xbean.valueRestriction.company.CompanyType; import prePostFeature.xbean.valueRestriction.company.ConsultantType; import prePostFeature.xbean.valueRestriction.company.DepartmentType; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ValueRestrictionTest { @Test - public void test() throws Exception { + void test() throws Exception { CompanyDocument poDoc; @@ -68,7 +68,7 @@ public class ValueRestrictionTest { for (int i = 0; i < LEN; i++) { it[i].setEmployeeAge(150); } - assertTrue(sExpected.toString().equals(poDoc.xmlText())); + assertEquals(sExpected.toString(), poDoc.xmlText()); assertTrue(poDoc.validate()); } Modified: xmlbeans/trunk/src/test/java/xmlobject/extensions/prePostFeature/readOnlyBean/checkin/ReadOnlyTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/extensions/prePostFeature/readOnlyBean/checkin/ReadOnlyTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/extensions/prePostFeature/readOnlyBean/checkin/ReadOnlyTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/extensions/prePostFeature/readOnlyBean/checkin/ReadOnlyTest.java Sun Feb 6 01:51:55 2022 @@ -15,49 +15,48 @@ package xmlobject.extensions.prePostFeature.readOnlyBean.checkin; -import org.junit.Test; +import org.junit.jupiter.api.Test; import prePostFeature.xbean.readOnlyBean.purchaseOrder.Items; import prePostFeature.xbean.readOnlyBean.purchaseOrder.PurchaseOrderDocument; import prePostFeature.xbean.readOnlyBean.purchaseOrder.PurchaseOrderType; import java.math.BigDecimal; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; public class ReadOnlyTest { @Test - public void test(){ + void test() { - PurchaseOrderDocument poDoc ; + PurchaseOrderDocument poDoc; - poDoc= PurchaseOrderDocument.Factory.newInstance(); - PurchaseOrderType po=poDoc.addNewPurchaseOrder(); + poDoc = PurchaseOrderDocument.Factory.newInstance(); + PurchaseOrderType po = poDoc.addNewPurchaseOrder(); - int LEN=20; + int LEN = 20; - Items.Item[] it= new Items.Item[LEN]; - for (int i=0; i< LEN; i++){ - it[i]=Items.Item.Factory.newInstance(); - it[i].setUSPrice(new BigDecimal(""+ 4 )); - } - Items items= Items.Factory.newInstance(); - items.setItemArray(it); - po.setItems(items); + Items.Item[] it = new Items.Item[LEN]; + for (int i = 0; i < LEN; i++) { + it[i] = Items.Item.Factory.newInstance(); + it[i].setUSPrice(new BigDecimal("" + 4)); + } + Items items = Items.Factory.newInstance(); + items.setItemArray(it); + po.setItems(items); - String sExpected = - "<pur:purchaseOrder xmlns:pur=\"http://xbean.prePost_feature/readOnlyBean/PurchaseOrder\"/>"; + String sExpected = + "<pur:purchaseOrder xmlns:pur=\"http://xbean.prePost_feature/readOnlyBean/PurchaseOrder\"/>"; - it[0].setPrice(10); + it[0].setPrice(10); - assertEquals( sExpected, poDoc.xmlText()); + assertEquals(sExpected, poDoc.xmlText()); - - assertTrue ( !poDoc.validate() ); + assertFalse(poDoc.validate()); } } Modified: xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/EnumTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/EnumTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/EnumTests.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/EnumTests.java Sun Feb 6 01:51:55 2022 @@ -23,19 +23,17 @@ import com.enumtest.StatusreportDocument import org.apache.xmlbeans.XmlBeans; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; -import org.junit.Test; -import tools.util.JarUtil; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static xmlcursor.common.BasicCursorTestCase.jobj; public class EnumTests { @Test - public void testReport1() throws Exception { - StatusreportDocument doc = (StatusreportDocument) - XmlObject.Factory.parse( - JarUtil.getResourceFromJarasFile( - "xbean/xmlobject/enumtest.xml")); + void testReport1() throws Exception { + StatusreportDocument doc = (StatusreportDocument) jobj("xbean/xmlobject/enumtest.xml"); Quantity.Enum[] contents = { Quantity.ALL, @@ -57,7 +55,7 @@ public class EnumTests { } @Test - public void testReport2() { + void testReport2() { StatusreportDocument doc = StatusreportDocument.Factory.newInstance(); StatusreportDocument.Statusreport report = doc.addNewStatusreport(); @@ -97,7 +95,7 @@ public class EnumTests { } @Test - public void testReport3() { + void testReport3() { SalesreportDocument doc = SalesreportDocument.Factory.newInstance(); SalesreportDocument.Salesreport report = doc.addNewSalesreport(); @@ -124,8 +122,8 @@ public class EnumTests { } } - @Test(expected = XmlException.class) - public void testEnumRestriction() throws Exception { + @Test + void testEnumRestriction() throws Exception { String schema = "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + " xmlns:tns=\"foo\" targetNamespace=\"foo\">\n" + @@ -149,8 +147,7 @@ public class EnumTests { "</xs:schema>\n"; XmlObject xobj = XmlObject.Factory.parse(schema); - - XmlBeans.loadXsd(new XmlObject[]{xobj}); + assertThrows(XmlException.class, () -> XmlBeans.loadXsd(xobj)); } } Modified: xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/GDateTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/GDateTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/GDateTests.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/GDateTests.java Sun Feb 6 01:51:55 2022 @@ -16,19 +16,18 @@ package xmlobject.schematypes.checkin; import org.apache.xmlbeans.*; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class GDateTests { - private static String[] validDurations = { + private static final String[] validDurations = { "PT0S", "P1Y", "P1M", @@ -77,7 +76,7 @@ public class GDateTests { }; - private static String[] invalidDurations = { + private static final String[] invalidDurations = { "P1Y-364D", "P1Y-365D", "P1Y-366D", @@ -111,7 +110,7 @@ public class GDateTests { "-PT-0.1415926S", }; - private static String[] invalidDates = { + private static final String[] invalidDates = { "+14:01", // tz "-14:01", // tz "+15:00", // tz @@ -182,7 +181,7 @@ public class GDateTests { "00:00:00-15:00", // tz }; - private static String[] validDates = { + private static final String[] validDates = { "", "Z", // timezone only "-14:00", // timezone only @@ -269,7 +268,7 @@ public class GDateTests { } @Test - public void testGregorianCalendar() { + void testGregorianCalendar() { // this is a check of DST offsets Date date = new GDate("2002-04-18T23:59:59Z").getDate(); GregorianCalendar gcal = new XmlCalendar(date); @@ -309,11 +308,11 @@ public class GDateTests { assertEquals(0, gd.getHour()); assertEquals(0, gd.getMinute()); assertEquals(0, gd.getSecond()); - assertEquals(new java.math.BigDecimal(0.0), gd.getFraction()); + assertEquals(BigDecimal.ZERO, gd.getFraction()); } @Test - public void testEmptyDuration() { + void testEmptyDuration() { GDuration gd = new GDuration(); _testEmptyDuration(gd); GDuration gdCopy = new GDuration(gd); @@ -321,26 +320,14 @@ public class GDateTests { } @Test - public void testValidDuration() { - for (int i = 0; i < validDurations.length; i++) { - GDuration gd = null; - String str = validDurations[i]; - try { - gd = new GDuration(str); - } catch (IllegalArgumentException e) { - Assert.fail("Problem with " + str + ": " + e.getMessage()); - } + void testValidDuration() { + for (String str : validDurations) { + GDuration gd = new GDuration(str); assertEquals(str, gd.toString()); - for (int j = 0; j < validDurations.length; j++) { - GDuration gd2 = null; - String str2 = validDurations[j]; - try { - gd2 = new GDuration(str2); - } catch (IllegalArgumentException e) { - Assert.fail("Problem with " + str2 + ": " + e.getMessage()); - } + for (String validDuration : validDurations) { + GDuration gd2 = new GDuration(validDuration); // subtracting two ways works GDuration diff = gd.subtract(gd2); @@ -352,32 +339,34 @@ public class GDateTests { gdb.normalize(); GDurationBuilder gdb1 = new GDurationBuilder(diff); gdb1.normalize(); - assertEquals("Problem: " + gd + " and " + gd2, gdb.toString(), gdb1.toString()); + assertEquals(gdb.toString(), gdb1.toString(), "Problem: " + gd + " and " + gd2); // comparing is reversible int comp1 = gd.compareToGDuration(gd2); int comp2 = gd2.compareToGDuration(gd); - if (comp1 == 2) + if (comp1 == 2) { assertEquals(2, comp2); - else + } else { assertEquals(-comp1, comp2); + } // comparing translates to addition to dates boolean[] seen = new boolean[3]; - for (int k = 0; k < validDates.length; k++) { - GDate date = new GDate(validDates[k]); - if (!date.hasDate() || date.getYear() > 99999 || date.getYear() < -4000) + for (String validDate : validDates) { + GDate date = new GDate(validDate); + if (!date.hasDate() || date.getYear() > 99999 || date.getYear() < -4000) { continue; - if ((hasTime(gd) || hasTime(gd2)) && !date.hasTime()) + } + if ((hasTime(gd) || hasTime(gd2)) && !date.hasTime()) { continue; - // System.out.println("Adding " + gd + " and " + gd2 + " to " + date + ", expecting " + comp1); + } GDate date1 = date.add(gd); GDate date2 = date.add(gd2); comp2 = date1.compareToGDate(date2); if (comp1 != 2) { - assertEquals("Adding " + date + " + " + gd + " -> " + date1 + ", " + gd2 + " -> " + date2 + ", expecting " + comp1, comp1, comp2); + assertEquals(comp1, comp2, "Adding " + date + " + " + gd + " -> " + date1 + ", " + gd2 + " -> " + date2 + ", expecting " + comp1); } else { assertTrue(comp2 != 2); seen[comp2 + 1] = true; @@ -392,10 +381,12 @@ public class GDateTests { if (comp1 == 2) { int seencount = 0; - for (int k = 0; k < seen.length; k++) - if (seen[k]) + for (boolean b : seen) { + if (b) { seencount += 1; - assertTrue("Not ambiguous as advertised" /* + gd + ", " + gd2 + " d: " + diff */, seencount > 1); + } + } + assertTrue(seencount > 1, "Not ambiguous as advertised"); } } } @@ -407,10 +398,8 @@ public class GDateTests { GDate gd2 = new GDate(date2); GDuration gdur = new GDuration(duration); GDate gd = gd1.add(gdur); - System.out.println(date1 + " + " + duration + " = " + gd.toString()); assertEquals(gd2, gd); gd = gd2.subtract(gdur); - System.out.println(date2 + " - " + duration + " = " + gd.toString()); assertEquals(gd1, gd); } @@ -419,7 +408,6 @@ public class GDateTests { GDate gd2 = new GDate(date2); GDuration gdur = new GDuration(duration); GDate gd = gd1.add(gdur); - System.out.println(date1 + " + " + duration + " = " + gd.toString()); assertEquals(gd2, gd); } @@ -428,12 +416,11 @@ public class GDateTests { GDate gd2 = new GDate(date2); GDuration gdur = new GDuration(duration); GDate gd = gd2.subtract(gdur); - System.out.println(date2 + " - " + duration + " = " + gd.toString()); assertEquals(gd1, gd); } @Test - public void testAddAndSubtractDuration() { + void testAddAndSubtractDuration() { _testAddAndSubtract("1970-01-01", "1973-01-01", "P3Y"); _testAddAndSubtract("0001-01-01", "0004-01-01", "P3Y"); // there is no year 0, so 1 BCE + 3Y = 3 CE @@ -461,7 +448,7 @@ public class GDateTests { } @Test - public void testOrder() { + void testOrder() { assertEquals(-1, new GDate("1998-08-26").compareToGDate(new GDate("2001-08-06"))); assertEquals(-1, new GDate("1970-12-20T04:14:22Z").compareToGDate(new GDate("1971-04-18T12:51:41Z"))); assertEquals(2, new GDate("2001-08-06").compareToGDate(new GDate("2001-08-06Z"))); @@ -519,7 +506,7 @@ public class GDateTests { } @Test - public void testAPI() throws Exception { + void testAPI() throws Exception { GDateBuilder builder = new GDateBuilder("1970-12-20T04:14:22Z"); builder.normalizeToTimeZone(1, 0, 0); assertEquals("1970-12-20T04:14:22+00:00", builder.toString()); @@ -532,50 +519,33 @@ public class GDateTests { } @Test - public void testFailure() throws Exception { - for (int i = 0; i < invalidDurations.length; i++) { - String str = invalidDurations[i]; - try { - new GDuration(str); - } catch (IllegalArgumentException e) { - continue; - } - Assert.fail("Missing exception for GDuration: " + str); + void testFailure() throws Exception { + for (String str : invalidDurations) { + assertThrows(IllegalArgumentException.class, () -> new GDuration(str)); } - for (int i = 0; i < invalidDates.length; i++) { - String str = invalidDates[i]; - try { - new GDate(str); - } catch (IllegalArgumentException e) { - continue; - } - Assert.fail("Missing exception for GDate " + str); + for (String str : invalidDates) { + assertThrows(IllegalArgumentException.class, () -> new GDate(str)); } } @Test - public void testSuccess() throws Exception { - for (int i = 0; i < validDates.length; i++) { - String str = validDates[i]; - GDate gdate = null; - try { - gdate = new GDate(str); - } catch (IllegalArgumentException e) { - Assert.fail("Problem with " + str + ": " + e.getMessage()); - } + void testSuccess() throws Exception { + for (String str : validDates) { + GDate gdate = new GDate(str); // for 24h if hasDay must be normalized, else has the same representation if (str.contains("24:00:00") && gdate.hasDay()) { - assertTrue(str + " " + gdate.toString(), gdate.hasDay() && gdate.toString().contains("00:00:00")); - } else + assertTrue(gdate.hasDay() && gdate.toString().contains("00:00:00"), str + " " + gdate.toString()); + } else { // must round-trip to string assertEquals(str, gdate.toString()); + } // must round-trip to GregorianCalendar if fractions-of-seconds <=3 digits if (gdate.getFraction() == null || gdate.getFraction().scale() <= 3) - if (!gdate.toString().equals("--02-29")) // bug in gcal -> 03-01 - { + /* bug in gcal -> 03-01*/ + if (!gdate.toString().equals("--02-29")) { GregorianCalendar gcal = gdate.getCalendar(); GDate gdate2 = new GDate(gcal); assertEquals(gdate, gdate2); @@ -604,7 +574,7 @@ public class GDateTests { // double-check XmlCalendar constructor gcal = new XmlCalendar(date); - assertEquals("Doing " + gdate, date, gcal.getTime()); + assertEquals(date, gcal.getTime(), "Doing " + gdate); } else if (gdate.hasDate() && (gdate.getFraction() == null || gdate.getFraction().scale() <= 3)) { // must be able to get a date if time+timezone is unset (midnight, ltz are assumed) Date date = gdate.getDate(); @@ -615,85 +585,60 @@ public class GDateTests { // verify that going through gcal gives us the same thing GregorianCalendar gcal = gdate.getCalendar(); - assertEquals("Comparing " + gdate + " and " + gcal, date, gcal.getTime()); + assertEquals(date, gcal.getTime(), "Comparing " + gdate + " and " + gcal); } } } @Test - public void test24hDates() { + void test24hDates() { GDate d1 = new GDate("2004-03-31T24:00:00"); assertEquals("2004-04-01T00:00:00", d1.toString()); GDateBuilder b = new GDateBuilder(); b.setTime(24, 0, 0, new BigDecimal("0.00")); - System.out.println("hour 24: " + b.getCalendar()); assertEquals("24:00:00.000", b.getCalendar().toString()); b.setDay(10); b.setMonth(1); - System.out.println("hour 24: " + b.getCalendar()); assertEquals("--01-10T24:00:00.000", b.getCalendar().toString()); b.setYear(2010); - System.out.println("hour 24: " + b.getCalendar()); assertEquals("2010-01-10T24:00:00.000", b.getCalendar().toString()); b.setDay(31); - b.setMonth(03); + b.setMonth(Calendar.APRIL); b.setYear(2004); - System.out.println("hour 24: canonical str: " + b.canonicalString()); assertEquals("2004-04-01T00:00:00", b.canonicalString()); - System.out.println("hour 24: toString: " + b.toString()); assertEquals("2004-03-31T24:00:00.00", b.toString()); - System.out.println("hour 24: toGDate: " + b.toGDate()); assertEquals("2004-03-31T24:00:00.00", b.toGDate().toString()); - System.out.println("hour 24: toGDate().canonicalStr: " + b.toGDate().canonicalString()); assertEquals("2004-04-01T00:00:00", b.toGDate().canonicalString()); - System.out.println("hour 24: toGDate().getCal: " + b.toGDate().getCalendar()); assertEquals("2004-03-31T24:00:00.000", b.toGDate().getCalendar().toString()); GDateBuilder gdb = new GDateBuilder("24:00:00+01:00"); - System.out.println("gdb: " + gdb); assertEquals("24:00:00+01:00", gdb.toString()); gdb.normalize(); - System.out.println("gdb.normalize(): " + gdb); assertEquals("23:00:00Z", gdb.toString()); } @Test - public void testYearStartingWith0() { + void testYearStartingWith0() { GDate gdate = new GDate("0004-08-01"); // 00004-08-01 must fail - System.out.println("year starting with 0: " + gdate.getCalendar()); assertEquals("0004-08-01", gdate.toString()); String txt = "-9999-06"; GDate d = new GDate(txt); - System.out.println(" gdate(" + txt + ") = " + d); assertEquals("-9999-06", d.toString()); txt = "-12345-06"; d = new GDate(txt); - System.out.println(" gdate(" + txt + ") = " + d); assertEquals(txt, d.toString()); - - try { - txt = "00004-08-01"; - d = new GDate(txt); // 00004-08-01 must fail - fail("Year starting with 0 of five digits: " + txt); - } catch (IllegalArgumentException e) { - } - - try { - txt = "-012340-08-01"; - d = new GDate(txt); - fail("Year starting with 0 of six digits: " + txt); - } catch (IllegalArgumentException e) { - } + assertThrows(IllegalArgumentException.class, () -> new GDate("00004-08-01")); + assertThrows(IllegalArgumentException.class, () -> new GDate("-012340-08-01")); } } Modified: xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/IntTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/IntTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/IntTests.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/IntTests.java Sun Feb 6 01:51:55 2022 @@ -17,14 +17,14 @@ package xmlobject.schematypes.checkin; import org.apache.xmlbeans.XmlException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import xint.test.PositionDocument; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class IntTests { @Test - public void testLatLong() throws XmlException { + void testLatLong() throws XmlException { PositionDocument doc = PositionDocument.Factory.parse( "<p:position xmlns:p='java:int.test'><p:lat>43</p:lat><p:lon>020</p:lon></p:position>"); assertEquals(43, doc.getPosition().getLat()); Modified: xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/NumeralsTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/NumeralsTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/NumeralsTests.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/NumeralsTests.java Sun Feb 6 01:51:55 2022 @@ -19,229 +19,120 @@ package xmlobject.schematypes.checkin; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openuri.testNumerals.DocDocument; import java.math.BigDecimal; import java.math.BigInteger; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class NumeralsTests { - private static DocDocument.Doc doc; - - @BeforeClass - public static void initDoc() throws XmlException { - String inst = - "<doc xmlns='http://openuri.org/testNumerals'>\n" + - " <string> this is a long string \n" + - " ... </string>\n" + - " <int>\n" + - " +5\n" + - " </int>\n" + - " <int>\n" + - " -6\n" + - " </int>\n" + - " <int>\n" + - " +00000000015\n" + - " </int>\n" + - " <int>7<!--this has to be a 77 int value-->7</int>\n" + - " <boolean>\n" + - " true\n" + - " </boolean>\n" + - " <boolean>\n" + - " false\n" + - " </boolean>\n" + - " <boolean>\n" + - " 0\n" + - " </boolean>\n" + - " <boolean>\n" + - " 1\n" + - " </boolean>\n" + - " <boolean>\n" + - " true is not\n" + - " </boolean>\n" + - " <short>\n" + - " +03\n" + - " </short>\n" + - " <byte>\n" + - " +001\n" + - " </byte>\n" + - " <long>-0500000</long>\n" + - " <long>\n" + - " 001\n" + - " </long>\n" + - " <long>\n" + - " +002\n" + - " </long>\n" + - " <double>\n" + - " +001\n" + - " </double>\n" + - " <double>\n" + - " -002.007000\n" + - " </double>\n" + - " <double>\n" + - " INF\n" + - " </double>\n" + - " <double>\n" + - " -INF\n" + - " </double>\n" + - " <double>\n" + - " NaN\n" + - " </double>\n" + - " <float>\n" + - " +12.325\n" + - " </float>\n" + - " <float>\n" + - " NaN\n" + - " </float>\n" + - " <float>\n" + - " INF\n" + - " </float>\n" + - " <float>\n" + - " -INF\n" + - " </float>\n" + - " <decimal>\n" + - " +001.001\n" + - " </decimal>\n" + - " <integer>\n" + - " +001<!--comments-->000000000\n" + - " </integer>\n" + - "</doc>"; - - doc = DocDocument.Factory.parse(inst).getDoc(); - } - - @Test - public void test1() { - String s = " this is a long string \n" + " ... "; - assertEquals("String expected:\n'" + s + "' actual:\n'" + - doc.getStringArray()[0] + "'", s, doc.getStringArray()[0]); - } - - @Test - public void test2() { - assertEquals("int expected:" + 5 + " actual:" + doc.getIntArray()[0], 5, doc.getIntArray()[0]); - } - - @Test - public void test3() { - assertEquals("int expected:" + (-6) + " actual:" + doc.getIntArray()[1], doc.getIntArray()[1], -6); - } - - @Test - public void test4() { - assertEquals("int expected:" + 15 + " actual:" + doc.getIntArray()[2], 15, doc.getIntArray()[2]); - } - - @Test - public void test5() { - assertEquals("int expected:" + 77 + " actual:" + doc.getIntArray()[3], 77, doc.getIntArray()[3]); - } - - @Test - public void test6() { + private static final String XML = + "<doc xmlns='http://openuri.org/testNumerals'>\n" + + " <string> this is a long string \n" + + " ... </string>\n" + + " <int>\n" + + " +5\n" + + " </int>\n" + + " <int>\n" + + " -6\n" + + " </int>\n" + + " <int>\n" + + " +00000000015\n" + + " </int>\n" + + " <int>7<!--this has to be a 77 int value-->7</int>\n" + + " <boolean>\n" + + " true\n" + + " </boolean>\n" + + " <boolean>\n" + + " false\n" + + " </boolean>\n" + + " <boolean>\n" + + " 0\n" + + " </boolean>\n" + + " <boolean>\n" + + " 1\n" + + " </boolean>\n" + + " <boolean>\n" + + " true is not\n" + + " </boolean>\n" + + " <short>\n" + + " +03\n" + + " </short>\n" + + " <byte>\n" + + " +001\n" + + " </byte>\n" + + " <long>-0500000</long>\n" + + " <long>\n" + + " 001\n" + + " </long>\n" + + " <long>\n" + + " +002\n" + + " </long>\n" + + " <double>\n" + + " +001\n" + + " </double>\n" + + " <double>\n" + + " -002.007000\n" + + " </double>\n" + + " <double>\n" + + " INF\n" + + " </double>\n" + + " <double>\n" + + " -INF\n" + + " </double>\n" + + " <double>\n" + + " NaN\n" + + " </double>\n" + + " <float>\n" + + " +12.325\n" + + " </float>\n" + + " <float>\n" + + " NaN\n" + + " </float>\n" + + " <float>\n" + + " INF\n" + + " </float>\n" + + " <float>\n" + + " -INF\n" + + " </float>\n" + + " <decimal>\n" + + " +001.001\n" + + " </decimal>\n" + + " <integer>\n" + + " +001<!--comments-->000000000\n" + + " </integer>\n" + + "</doc>"; + + @Test + void testNumerals() throws XmlException { + DocDocument.Doc doc = DocDocument.Factory.parse(XML).getDoc(); + assertEquals(" this is a long string \n ... ", doc.getStringArray()[0]); + assertEquals(5, doc.getIntArray()[0]); + assertEquals(-6, doc.getIntArray()[1]); + assertEquals(15, doc.getIntArray()[2]); + assertEquals(77, doc.getIntArray()[3]); assertTrue(doc.getBooleanArray(0)); - } - - @Test - public void test7() { assertFalse(doc.getBooleanArray(1)); - } - - @Test - public void test8() { assertFalse(doc.getBooleanArray(2)); - } - - @Test - public void test9() { assertTrue(doc.getBooleanArray(3)); - } - - @Test(expected = XmlValueOutOfRangeException.class) - public void test10() { - boolean b = doc.getBooleanArray()[4]; - } - - @Test - public void test11() { + assertThrows(XmlValueOutOfRangeException.class, () -> { boolean b = doc.getBooleanArray()[4]; }); assertEquals(3, doc.getShortArray()[0]); - } - - @Test - public void test12() { assertEquals(1, doc.getByteArray()[0]); - } - - @Test - public void test13() { - assertEquals("long expected:" + (-50000) + " actual:" + doc.getLongArray()[0], doc.getLongArray()[0], -500000); - } - - @Test - public void test14() { - assertEquals("long expected:" + 1 + " actual:" + doc.getLongArray()[1], 1, doc.getLongArray()[1]); - } - - @Test - public void test15() { - assertEquals("long expected:" + 2 + " actual:" + doc.getLongArray()[2], 2, doc.getLongArray()[2]); - } - - @Test - public void test16() { + assertEquals(-500000, doc.getLongArray()[0]); + assertEquals(1, doc.getLongArray()[1]); + assertEquals(2, doc.getLongArray()[2]); assertEquals(1, doc.getDoubleArray()[0], 0.0); - } - - @Test - public void test17() { - assertEquals("double expected:" + -2.007d + " actual:" + doc.getDoubleArray()[1], doc.getDoubleArray()[1], -2.007d, 0.0); - } - - @Test - public void test18() { + assertEquals(-2.007d, doc.getDoubleArray()[1], 0.0); assertEquals(Double.POSITIVE_INFINITY, doc.getDoubleArray()[2], 0); - } - - @Test - public void test19() { assertEquals(Double.NEGATIVE_INFINITY, doc.getDoubleArray()[3], 0); - } - - @Test - public void test20() { assertEquals(Double.NaN, doc.getDoubleArray()[4], 0); - } - - @Test - public void test21() { - assertEquals("fload expected:" + 12.325f + " actual:" + doc.getFloatArray()[0], 12.325f, doc.getFloatArray()[0], 0.0); - } - - @Test - public void test22() { + assertEquals(12.325f, doc.getFloatArray()[0], 0.0); assertEquals(Float.NaN, doc.getFloatArray()[1], 0); - } - - @Test - public void test23() { - assertEquals("fload expected:" + Float.POSITIVE_INFINITY + " actual:" + doc.getFloatArray()[2], Float.POSITIVE_INFINITY, doc.getFloatArray()[2], 0); - } - - @Test - public void test24() { + assertEquals(Float.POSITIVE_INFINITY, doc.getFloatArray()[2], 0); assertEquals(Float.NEGATIVE_INFINITY, doc.getFloatArray()[3], 0); - } - - @Test - public void test25() { assertEquals(new BigDecimal("1.001"), doc.getDecimalArray()[0]); - } - - @Test - public void test26() { assertEquals(new BigInteger("1000000000"), doc.getIntegerArray(0)); } } Modified: xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/QNameTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/QNameTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/QNameTests.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/QNameTests.java Sun Feb 6 01:51:55 2022 @@ -16,29 +16,21 @@ package xmlobject.schematypes.checkin; import org.apache.xmlbeans.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class QNameTests { - static String[] _args; - static String _test; - @Test - public void testQName() throws Exception { + void testQName() throws Exception { String schema = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" + - "" + " <xs:element name='any'>\n" + " </xs:element>\n" + - "" + - "</xs:schema>\n" + - ""; - - SchemaTypeLoader stl = - XmlBeans.loadXsd(new XmlObject[]{ - XmlObject.Factory.parse(schema)}); + "</xs:schema>"; + + SchemaTypeLoader stl = XmlBeans.loadXsd(XmlObject.Factory.parse(schema)); // // Test the set_XMLName function on XmlQNameImpl @@ -46,57 +38,37 @@ public class QNameTests { String ns = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " + - "xmlns:xs='http://www.w3.org/2001/XMLSchema'"; + "xmlns:xs='http://www.w3.org/2001/XMLSchema'"; XmlObject sourceDocument = - stl.parse( - "<any " + ns + " xsi:type='xs:QName' xmlns:xxx='xxx.com'>" + - "xxx:abc</any>", null, null); + stl.parse("<any " + ns + " xsi:type='xs:QName' xmlns:xxx='xxx.com'>xxx:abc</any>", null, null); XmlQName sourceQName; try (XmlCursor sourceCursor = sourceDocument.newCursor()) { sourceCursor.toFirstChild(); - sourceQName = (XmlQName) sourceCursor.getObject(); } - XmlObject targetDocument = - stl.parse( - "<any " + ns + " xsi:type='xs:QName'>" + - "</any>", null, null); + XmlObject targetDocument = stl.parse("<any " + ns + " xsi:type='xs:QName'></any>", null, null); - XmlQName targetQName; try (XmlCursor targetCursor = targetDocument.newCursor()) { targetCursor.toFirstChild(); - - targetQName = (XmlQName) targetCursor.getObject(); + XmlQName targetQName = (XmlQName) targetCursor.getObject(); + targetQName.set(sourceQName); + assertEquals("xxx.com", targetQName.getQNameValue().getNamespaceURI()); } - targetQName.set(sourceQName); - - assertEquals("xxx.com", targetQName.getQNameValue().getNamespaceURI()); - // // Test the set_text function on XmlQNameImpl // - - targetDocument = - stl.parse( - "<any " + ns + " xsi:type='xs:QName' xmlns:xxx='xxx.com'>" + - "</any>", null, null); + targetDocument = stl.parse("<any " + ns + " xsi:type='xs:QName' xmlns:xxx='xxx.com'></any>", null, null); try (XmlCursor targetCursor = targetDocument.newCursor()) { targetCursor.toFirstChild(); - - targetQName = (XmlQName) targetCursor.getObject(); - - targetQName.setStringValue("zzz:abc"); - fail("Must fail"); - } catch (Throwable t) { + XmlQName targetQName = (XmlQName) targetCursor.getObject(); + assertThrows(Throwable.class, () -> targetQName.setStringValue("zzz:abc")); + targetQName.setStringValue("xxx:abc"); + assertEquals("xxx.com", targetQName.getQNameValue().getNamespaceURI()); } - - targetQName.setStringValue("xxx:abc"); - - assertEquals("xxx.com", targetQName.getQNameValue().getNamespaceURI()); } } Modified: xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/SchemaTypesTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/SchemaTypesTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/SchemaTypesTests.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/schematypes/checkin/SchemaTypesTests.java Sun Feb 6 01:51:55 2022 @@ -18,42 +18,34 @@ package xmlobject.schematypes.checkin; import org.apache.xmlbeans.*; import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openuri.def.DefaultsDocument; import org.openuri.xstypes.test.CustomerDocument; import org.openuri.xstypes.test.Person; -import tools.util.JarUtil; import javax.xml.namespace.QName; import java.io.IOException; import java.io.InputStream; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static xmlcursor.common.BasicCursorTestCase.jobj; public class SchemaTypesTests { - - private CustomerDocument doc; - - private void ensureDoc() - throws Exception { - if (doc == null) { - doc = (CustomerDocument) - XmlObject.Factory.parse( - JarUtil.getResourceFromJarasFile("xbean/xmlobject/person.xml")); - } + private static CustomerDocument getDoc() throws Exception { + return (CustomerDocument) jobj("xbean/xmlobject/person.xml"); } @Test - public void testDefaults() { + void testDefaults() { DefaultsDocument doc = DefaultsDocument.Factory.newInstance(); DefaultsDocument.Defaults defs = doc.addNewDefaults(); assertEquals(783, defs.getCool()); // this is the default value } @Test - public void testSourceName() throws IOException, XmlException { + void testSourceName() throws IOException, XmlException { String name = DefaultsDocument.type.getSourceName(); assertEquals("defaults.xsd", name); InputStream str = XmlBeans.getContextTypeLoader().getSourceAsStream("defaults.xsd"); @@ -62,22 +54,20 @@ public class SchemaTypesTests { } @Test - public void testRead() throws Exception { - ensureDoc(); + void testRead() throws Exception { + CustomerDocument doc = getDoc(); // Move from the root to the root customer element Person person = doc.getCustomer(); assertEquals("Howdy", person.getFirstname()); - assertEquals(4, person.sizeOfNumberArray()); + assertEquals(4, person.sizeOfNumberArray()); assertEquals(436, person.getNumberArray(0)); assertEquals(123, person.getNumberArray(1)); - assertEquals(44, person.getNumberArray(2)); + assertEquals(44, person.getNumberArray(2)); assertEquals(933, person.getNumberArray(3)); - assertEquals(2, person.sizeOfBirthdayArray()); - assertEquals(new XmlCalendar("1998-08-26Z"), - person.getBirthdayArray(0)); - assertEquals(new XmlCalendar("2000-08-06-08:00"), - person.getBirthdayArray(1)); + assertEquals(2, person.sizeOfBirthdayArray()); + assertEquals(new XmlCalendar("1998-08-26Z"), person.getBirthdayArray(0)); + assertEquals(new XmlCalendar("2000-08-06-08:00"), person.getBirthdayArray(1)); Person.Gender.Enum g = person.getGender(); assertEquals(Person.Gender.MALE, g); @@ -100,8 +90,8 @@ public class SchemaTypesTests { } @Test - public void testWriteRead() throws Exception { - ensureDoc(); + void testWriteRead() throws Exception { + CustomerDocument doc = getDoc(); // Move from the root to the root customer element Person person = doc.getCustomer(); @@ -126,10 +116,10 @@ public class SchemaTypesTests { person.setAnyuriAtt("b.d:7002"); assertEquals("b.d:7002", person.getAnyuriAtt()); - person.setQnameAtt(new QName("aaa","bbb")); + person.setQnameAtt(new QName("aaa", "bbb")); assertEquals("{aaa}bbb", person.getQnameAtt().toString()); - person.setQname(new QName("ddd","eee")); + person.setQname(new QName("ddd", "eee")); assertEquals("{ddd}eee", person.getQname().toString()); //Exception: src/xmlstore/org/apache/xmlbeans/impl/store/Type.java(189): user == _user failed @@ -149,8 +139,8 @@ public class SchemaTypesTests { } @Test - public void testStoreWrite() throws Exception { - ensureDoc(); + void testStoreWrite() throws Exception { + CustomerDocument doc = getDoc(); // Move from the root to the root customer element Person person = doc.getCustomer(); @@ -159,31 +149,31 @@ public class SchemaTypesTests { person.setFirstname("George"); xmlobj = person.xgetFirstname(); try (XmlCursor xmlcurs = xmlobj.newCursor()) { - assertEquals("George", xmlcurs.getTextValue() ); + assertEquals("George", xmlcurs.getTextValue()); } - person.setQnameAtt( new QName("http://ggg.com","hhh") ); + person.setQnameAtt(new QName("http://ggg.com", "hhh")); xmlobj = person.xgetQnameAtt(); try (XmlCursor xmlcurs = xmlobj.newCursor()) { - assertEquals("ggg:hhh", xmlcurs.getTextValue() ); + assertEquals("ggg:hhh", xmlcurs.getTextValue()); } - person.setQname( new QName("http://ggg.com/gggAgain","kkk") ); + person.setQname(new QName("http://ggg.com/gggAgain", "kkk")); xmlobj = person.xgetQname(); try (XmlCursor xmlcurs = xmlobj.newCursor()) { - assertEquals("ggg1:kkk", xmlcurs.getTextValue() ); + assertEquals("ggg1:kkk", xmlcurs.getTextValue()); } - person.setAnyuri( "crossgain.com" ); + person.setAnyuri("crossgain.com"); xmlobj = person.xgetAnyuri(); try (XmlCursor xmlcurs = xmlobj.newCursor()) { - assertEquals("crossgain.com", xmlcurs.getTextValue() ); + assertEquals("crossgain.com", xmlcurs.getTextValue()); } - person.setAnyuriAtt( "www.crossgain.com" ); + person.setAnyuriAtt("www.crossgain.com"); xmlobj = person.xgetAnyuriAtt(); try (XmlCursor xmlcurs = xmlobj.newCursor()) { - assertEquals("www.crossgain.com", xmlcurs.getTextValue() ); + assertEquals("www.crossgain.com", xmlcurs.getTextValue()); } //person.setNotation("GIF"); Modified: xmlbeans/trunk/src/test/java/xmlobject/schematypes/detailed/ListAndUnionTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/schematypes/detailed/ListAndUnionTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/schematypes/detailed/ListAndUnionTests.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/schematypes/detailed/ListAndUnionTests.java Sun Feb 6 01:51:55 2022 @@ -14,9 +14,8 @@ */ package xmlobject.schematypes.detailed; -import org.junit.Assert; import org.apache.xmlbeans.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openuri.lut.DateOrDateTime; import org.openuri.lut.IncidentReportsDocument; import org.openuri.lut.ListsDocument; @@ -27,11 +26,12 @@ import java.util.Arrays; import java.util.Calendar; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ListAndUnionTests { @Test - public void testListGetters() throws Exception { + void testListGetters() throws Exception { ListsDocument lists = ListsDocument.Factory.parse( "<lut:lists xmlns:lut='http://openuri.org/lut'><lut:int-list>2 4 8 16 32</lut:int-list><lut:nni-list>unbounded 3 unbounded 6</lut:nni-list></lut:lists>"); List intList = lists.getLists().getIntList(); @@ -51,7 +51,7 @@ public class ListAndUnionTests { } @Test - public void testListSetters() throws Exception { + void testListSetters() throws Exception { ListsDocument doc = ListsDocument.Factory.newInstance(); ListsDocument.Lists lists = doc.addNewLists(); lists.setIntList(Arrays.asList(4, 18)); @@ -72,13 +72,13 @@ public class ListAndUnionTests { } @Test - public void testUnionGetters() throws Exception { + void testUnionGetters() throws Exception { UnionsDocument unions = UnionsDocument.Factory.parse( "<lut:unions xmlns:lut='http://openuri.org/lut'><lut:nni>unbounded</lut:nni><lut:sizes>2 3 5 7 11</lut:sizes></lut:unions>"); assertEquals("unbounded", unions.getUnions().getNni()); - Assert.assertTrue(unions.getUnions().getSizes() instanceof List); + assertTrue(unions.getUnions().getSizes() instanceof List); List sizes = (List) unions.getUnions().getSizes(); assertEquals(2, sizes.get(0)); assertEquals(3, sizes.get(1)); @@ -95,7 +95,7 @@ public class ListAndUnionTests { } @Test - public void testUnionSetters() throws Exception { + void testUnionSetters() throws Exception { // create a document UnionsDocument doc = UnionsDocument.Factory.newInstance(); @@ -128,7 +128,7 @@ public class ListAndUnionTests { } @Test - public void testUnionArray() throws Exception { + void testUnionArray() throws Exception { IncidentReportsDocument doc = IncidentReportsDocument.Factory.parse( "<lut:incident-reports xmlns:lut='http://openuri.org/lut'>" + "<lut:when>2001-08-06T03:34:00</lut:when>" + Modified: xmlbeans/trunk/src/test/java/xmlobject/schematypes/detailed/QNameSetTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/schematypes/detailed/QNameSetTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/schematypes/detailed/QNameSetTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/schematypes/detailed/QNameSetTest.java Sun Feb 6 01:51:55 2022 @@ -16,14 +16,14 @@ package xmlobject.schematypes.detailed; import org.apache.xmlbeans.QNameSetBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.xml.namespace.QName; import java.util.Random; import java.util.Stack; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class QNameSetTest { @@ -32,7 +32,7 @@ public class QNameSetTest { } @Test - public void testQNameSets() { + void testQNameSets() { int iterations = 10000; int seed = 0; @@ -212,14 +212,14 @@ public class QNameSetTest { // then, verify current matches contents int count = 0; for (int k = 0; k < width * namespace.length; k++) { - assertTrue(format(l, "Content mismatch " + name[k], current), (current.contains(name[k]) == contents[k])); + assertTrue((current.contains(name[k]) == contents[k]), format(l, "Content mismatch " + name[k], current)); if (contents[k]) count++; } - assertTrue(format(l, "ERROR: isEmpty is wrong", current), ((count == 0) == current.isEmpty())); + assertTrue(((count == 0) == current.isEmpty()), format(l, "ERROR: isEmpty is wrong", current)); - assertEquals(format(l, "ERROR: isAll is wrong", current), (count == width * namespace.length), current.isAll()); + assertEquals((count == width * namespace.length), current.isAll(), format(l, "ERROR: isAll is wrong", current)); // test isDisjoint and containsAll if (teststack.size() >= 1) { @@ -231,7 +231,7 @@ public class QNameSetTest { break; } } - assertEquals(format(l, "ERROR: disjoint is wrong", current), disjoint, current.isDisjoint(teststack.peek())); + assertEquals(disjoint, current.isDisjoint(teststack.peek()), format(l, "ERROR: disjoint is wrong", current)); boolean containsAll = true; for (int k = 0; k < width * namespace.length; k++) { @@ -240,7 +240,7 @@ public class QNameSetTest { break; } } - assertEquals(format(l, "ERROR: containsAll is wrong", current), containsAll, current.containsAll(teststack.peek())); + assertEquals(containsAll, current.containsAll(teststack.peek()), format(l, "ERROR: containsAll is wrong", current)); } } } Modified: xmlbeans/trunk/src/test/java/xmlobject/usertype/averageCase/checkin/AverageTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/usertype/averageCase/checkin/AverageTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/usertype/averageCase/checkin/AverageTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/usertype/averageCase/checkin/AverageTest.java Sun Feb 6 01:51:55 2022 @@ -17,7 +17,7 @@ package xmlobject.usertype.averageCase.c import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import usertype.xbean.averageCase.purchaseOrder.Items; import usertype.xbean.averageCase.purchaseOrder.PurchaseOrderDocument; import usertype.xbean.averageCase.purchaseOrder.PurchaseOrderType; @@ -25,13 +25,14 @@ import xmlobject.usertype.averageCase.ex import java.math.BigDecimal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class AverageTest { @Test - public void test(){ + void test(){ PurchaseOrderDocument poDoc = PurchaseOrderDocument.Factory.newInstance(); PurchaseOrderType po=poDoc.addNewPurchaseOrder(); int LEN=20; @@ -52,8 +53,8 @@ public class AverageTest { } } - @Test(expected = XmlValueOutOfRangeException.class) - public void testBadInput() throws XmlException{ + @Test + void testBadInput() throws XmlException{ String sb = "<purchaseOrder xmlns=\"http://xbean.usertype/averageCase/PurchaseOrder\">" + "<items><item partNum=\"000-AB\"><USPrice>2</USPrice></item>" + @@ -72,7 +73,7 @@ public class AverageTest { assertEquals(0, sku.getDigits()); assertEquals("AB", sku.getLetters()); - it[1].getPartNum(); + assertThrows(XmlValueOutOfRangeException.class, it[1]::getPartNum); // Invalid SKU format should fail } } Modified: xmlbeans/trunk/src/test/java/xmlobject/usertype/multipleItems/checkin/AverageTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/usertype/multipleItems/checkin/AverageTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/usertype/multipleItems/checkin/AverageTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/usertype/multipleItems/checkin/AverageTest.java Sun Feb 6 01:51:55 2022 @@ -18,7 +18,7 @@ package xmlobject.usertype.multipleItems import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import usertype.xbean.multipleItems.company.CompanyDocument; import usertype.xbean.multipleItems.company.CompanyType; import usertype.xbean.multipleItems.company.ConsultantType; @@ -27,13 +27,14 @@ import xmlobject.usertype.multipleItems. import java.math.BigInteger; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class AverageTest { @Test - public void test() { + void test() { CompanyDocument doc = CompanyDocument.Factory.newInstance(); CompanyType company = doc.addNewCompany(); DepartmentType dept = company.addNewDepartments(); @@ -43,17 +44,15 @@ public class AverageTest { cons.setName("Joe Smith"); cons.setAge(BigInteger.valueOf(100)); - int LEN=20; + int LEN = 20; - for (int i=0; i < LEN; i++) { + for (int i = 0; i < LEN; i++) { cons.addRoom(new Room(i, "AB")); } - System.out.println(doc.xmlText()); - Room[] rooms = cons.getRoomArray(); - for (int i=0; i < LEN; i++) { + for (int i = 0; i < LEN; i++) { assertEquals(i, rooms[i].getDigits()); assertEquals("AB", rooms[i].getLetters()); } @@ -61,7 +60,7 @@ public class AverageTest { @Test - public void testArrayGetSet() { + void testArrayGetSet() { CompanyDocument doc = CompanyDocument.Factory.newInstance(); CompanyType company = doc.addNewCompany(); @@ -72,18 +71,18 @@ public class AverageTest { cons.setName("Joe Smith"); cons.setAge(BigInteger.valueOf(100)); - int LEN=20; + int LEN = 20; Room[] rooms = new Room[LEN]; - for (int i=0; i < LEN; i++) { + for (int i = 0; i < LEN; i++) { rooms[i] = new Room(i, "AB"); } cons.setRoomArray(rooms); rooms = cons.getRoomArray(); - for (int i=0; i < LEN; i++) { + for (int i = 0; i < LEN; i++) { assertEquals(i, rooms[i].getDigits()); assertEquals("AB", rooms[i].getLetters()); } @@ -92,7 +91,7 @@ public class AverageTest { } @Test - public void testIthGetSet() { + void testIthGetSet() { CompanyDocument doc = CompanyDocument.Factory.newInstance(); CompanyType company = doc.addNewCompany(); @@ -104,18 +103,18 @@ public class AverageTest { cons.setAge(BigInteger.valueOf(100)); - int LEN=20; + int LEN = 20; - for (int i=0; i < LEN; i++) { + for (int i = 0; i < LEN; i++) { cons.addNewRoom(); } - for (int i=0; i < LEN; i++) { + for (int i = 0; i < LEN; i++) { cons.setRoomArray(i, new Room(i, "AB")); } - for (int i=0; i < LEN; i++) { + for (int i = 0; i < LEN; i++) { assertEquals(i, cons.getRoomArray(i).getDigits()); assertEquals("AB", cons.getRoomArray(i).getLetters()); } @@ -123,27 +122,26 @@ public class AverageTest { } - @Test(expected = XmlValueOutOfRangeException.class) - public void testBadInput() throws XmlException{ - - StringBuilder sb = new StringBuilder(); - sb.append("<com:company xmlns:com=\"http://xbean.usertype/multipleItems/company\">"); - sb.append("<departments><consultant name=\"Joe Smith\" age=\"100\">"); - sb.append("<room>000-AB</room><room>0001-AB</room><room>002-AB</room>"); - sb.append("</consultant></departments></com:company>"); + @Test + void testBadInput() throws XmlException { + String sb = + "<com:company xmlns:com=\"http://xbean.usertype/multipleItems/company\">" + + "<departments><consultant name=\"Joe Smith\" age=\"100\">" + + "<room>000-AB</room><room>0001-AB</room><room>002-AB</room>" + + "</consultant></departments></com:company>"; - CompanyDocument doc = CompanyDocument.Factory.parse(sb.toString()); + CompanyDocument doc = CompanyDocument.Factory.parse(sb); CompanyType company = doc.getCompany(); ConsultantType cons = company.getDepartmentsArray(0).getConsultantArray(0); assertEquals(3, cons.xgetRoomArray().length); - cons.getRoomArray(); + assertThrows(XmlValueOutOfRangeException.class, cons::getRoomArray); } - @Test(expected = XmlValueOutOfRangeException.class) - public void testBadInputGetIthBad() throws XmlException{ + @Test + void testBadInputGetIthBad() throws XmlException { String sb = "<com:company xmlns:com=\"http://xbean.usertype/multipleItems/company\">" + @@ -157,11 +155,11 @@ public class AverageTest { ConsultantType cons = company.getDepartmentsArray(0).getConsultantArray(0); assertEquals(3, cons.xgetRoomArray().length); - cons.getRoomArray(1); + assertThrows(XmlValueOutOfRangeException.class, () -> cons.getRoomArray(1)); } @Test - public void testBadInputGetIthGood() throws XmlException{ + void testBadInputGetIthGood() throws XmlException { String sb = "<com:company xmlns:com=\"http://xbean.usertype/multipleItems/company\">" + "<departments><consultant name=\"Joe Smith\" age=\"100\">" + Modified: xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/JapaneseTextTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/JapaneseTextTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/JapaneseTextTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/JapaneseTextTest.java Sun Feb 6 01:51:55 2022 @@ -1,93 +1,50 @@ /* Copyright 2004 The Apache Software Foundation -* -* 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. -*/ + * + * 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 xmlobject.xmlloader.detailed; import org.apache.xmlbeans.XmlObject; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import tools.util.JarUtil; -public class JapaneseTextTest { - - @Test - public void testEucJp() throws Exception { - loadFile("pr-xml-euc-jp.xml"); - } - - @Test - public void testIso2022Jp() throws Exception { - loadFile("pr-xml-iso-2022-jp.xml"); - } - - @Test - public void testLittleEndian() throws Exception { - loadFile("pr-xml-little-endian.xml"); - } +import java.io.InputStream; - @Test - public void testShift_jis() throws Exception { - loadFile("pr-xml-shift_jis.xml"); - } - - @Test - public void testUtf8() throws Exception { - loadFile("pr-xml-utf-8.xml"); - } - - @Test - public void testUtf16() throws Exception { - loadFile("pr-xml-utf-16.xml"); - } - - @Test - public void testWeeklyEucJp() throws Exception { - loadFile("weekly-euc-jp.xml"); - } - - @Test - public void testWeeklyIso2022Jp() throws Exception { - loadFile("weekly-iso-2022-jp.xml"); - } - - @Test - public void testWeeklyLittleEndian() throws Exception { - loadFile("weekly-little-endian.xml"); - } - - @Test - public void testWeeklyShift_jis() throws Exception { - loadFile("weekly-shift_jis.xml"); - } - - @Test - public void testWeeklyUtf8() throws Exception { - loadFile("weekly-utf-8.xml"); - } - - @Test - public void testWeeklyUtf16() throws Exception { - loadFile("weekly-utf-16.xml"); - } - - @Test - public void testPrefixLocalName() throws Exception { - loadFile("prefix_test.xml"); - } +import static org.junit.jupiter.api.Assertions.assertNotNull; +public class JapaneseTextTest { - private void loadFile(String file) throws Exception { - XmlObject.Factory.parse(JarUtil. - getResourceFromJarasStream("xbean/xmlobject/japanese/" + file)); + @ParameterizedTest + @ValueSource(strings = { + "pr-xml-euc-jp.xml", + "pr-xml-iso-2022-jp.xml", + "pr-xml-little-endian.xml", + "pr-xml-shift_jis.xml", + "pr-xml-utf-8.xml", + "pr-xml-utf-16.xml", + "weekly-euc-jp.xml", + "weekly-iso-2022-jp.xml", + "weekly-little-endian.xml", + "weekly-shift_jis.xml", + "weekly-utf-8.xml", + "weekly-utf-16.xml", + "prefix_test.xml" + }) + void testEncoding(String encodedFile) throws Exception { + try (InputStream is = JarUtil.getResourceFromJarasStream("xbean/xmlobject/japanese/" + encodedFile)) { + XmlObject obj = XmlObject.Factory.parse(is); + assertNotNull(obj); + } } } Modified: xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/ParseTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/ParseTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/ParseTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/ParseTest.java Sun Feb 6 01:51:55 2022 @@ -15,60 +15,62 @@ package xmlobject.xmlloader.detailed; -import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlOptions; -import org.junit.Test; +import org.apache.xmlbeans.*; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.xml.sax.InputSource; -import xmlcursor.common.BasicCursorTestCase; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.StringReader; -import java.util.Vector; +import java.util.ArrayList; +import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; -public class ParseTest extends BasicCursorTestCase { - private final XmlOptions m_map = new XmlOptions(); +public class ParseTest { @Test - public void testLoadStripWhitespace() throws Exception { + void testLoadStripWhitespace() throws Exception { + String xml = "<foo>01234 <bar>text</bar> chars \r\n</foo> "; + XmlOptions m_map = new XmlOptions(); m_map.setLoadStripWhitespace(); - m_xo = XmlObject.Factory.parse("<foo>01234 <bar>text</bar> chars \r\n</foo> ", - m_map); - m_xc = m_xo.newCursor(); - assertEquals("<foo>01234<bar>text</bar>chars</foo>", m_xc.xmlText()); + XmlObject m_xo = XmlObject.Factory.parse(xml, m_map); + try (XmlCursor m_xc = m_xo.newCursor()) { + assertEquals("<foo>01234<bar>text</bar>chars</foo>", m_xc.xmlText()); + } } @Test - public void testLoadDiscardDocumentElement() throws Exception { + void testLoadDiscardDocumentElement() throws Exception { + XmlOptions m_map = new XmlOptions(); m_map.setLoadReplaceDocumentElement(new QName("")); XmlObject.Factory.parse("<foo>01234 <bar>text</bar> chars </foo> ", m_map); } - @Test(expected = XmlException.class) - public void testPrefixNotDefined() throws Exception { + @Test + void testPrefixNotDefined() throws Exception { String sXml = "<Person xmlns=\"person\"><pre1:Name>steve</pre1:Name></Person>"; - XmlObject.Factory.parse(sXml); + assertThrows(XmlException.class, () -> XmlObject.Factory.parse(sXml)); } - @Test(expected = XmlException.class) - public void testErrorListener() throws Exception { - Vector vErrors = new Vector(); + @Test + void testErrorListener() throws Exception { + XmlOptions m_map = new XmlOptions(); + List<XmlError> vErrors = new ArrayList<>(); m_map.setErrorListener(vErrors); - XmlObject.Factory.parse("<foo>text<foo>", m_map); // improper end tag + // improper end tag + assertThrows(XmlException.class, () -> XmlObject.Factory.parse("<foo>text<foo>", m_map)); } @Test - public void testParsingDOMWithDTD() throws Exception { - final String svgDocumentString = "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n" + - "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" + - "<svg />"; + void testParsingDOMWithDTD() throws Exception { + final String svgDocumentString = + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n" + + "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" + + "<svg />"; assertNotNull(XmlObject.Factory.parse(svgDocumentString)); final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Modified: xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/XmlLoaderBvtTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/XmlLoaderBvtTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/XmlLoaderBvtTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/XmlLoaderBvtTest.java Sun Feb 6 01:51:55 2022 @@ -15,25 +15,18 @@ package xmlobject.xmlloader.detailed; -import org.apache.xmlbeans.XmlObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.tranxml.tranXML.version40.CarLocationMessageDocument; -import tools.util.JarUtil; -import xmlcursor.common.BasicCursorTestCase; import xmlcursor.common.Common; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static xmlcursor.common.BasicCursorTestCase.jobj; -public class XmlLoaderBvtTest extends BasicCursorTestCase { +public class XmlLoaderBvtTest { @Test - public void testCastDocument() throws Exception { - - CarLocationMessageDocument clm = - (CarLocationMessageDocument) XmlObject.Factory.parse( - JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)); - + void testCastDocument() throws Exception { + CarLocationMessageDocument clm = (CarLocationMessageDocument) jobj(Common.TRANXML_FILE_CLM); assertNotNull(clm); } } Modified: xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/XmlLoaderMiscTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/XmlLoaderMiscTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/XmlLoaderMiscTest.java (original) +++ xmlbeans/trunk/src/test/java/xmlobject/xmlloader/detailed/XmlLoaderMiscTest.java Sun Feb 6 01:51:55 2022 @@ -18,11 +18,11 @@ package xmlobject.xmlloader.detailed; import org.apache.xmlbeans.*; import org.apache.xmlbeans.XmlCursor.TokenType; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.tranxml.tranXML.version40.CarLocationMessageDocument; import org.tranxml.tranXML.version40.GeographicLocationDocument.GeographicLocation; import tools.util.JarUtil; -import xmlcursor.common.BasicCursorTestCase; import xmlcursor.common.Common; import javax.xml.namespace.QName; @@ -31,68 +31,65 @@ import java.util.HashSet; import java.util.Set; import java.util.Vector; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static xmlcursor.common.BasicCursorTestCase.jcur; -public class XmlLoaderMiscTest extends BasicCursorTestCase { - @Test - public void testNewInstance() throws Exception { - m_xo = XmlObject.Factory.newInstance(); - m_xc = m_xo.newCursor(); - assertEquals(TokenType.STARTDOC, m_xc.currentTokenType()); - m_xc.toNextToken(); - assertEquals(TokenType.ENDDOC, m_xc.currentTokenType()); +public class XmlLoaderMiscTest { + @Test + void testNewInstance() throws Exception { + try (XmlCursor m_xc = XmlObject.Factory.newInstance().newCursor()) { + assertEquals(TokenType.STARTDOC, m_xc.currentTokenType()); + m_xc.toNextToken(); + assertEquals(TokenType.ENDDOC, m_xc.currentTokenType()); + } } @Test - public void testTypeForClass() throws Exception { - m_xc = XmlObject.Factory.parse(JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)).newCursor(); - m_xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT + "$this//GeographicLocation"); - m_xc.toNextSelection(); - GeographicLocation gl = (GeographicLocation) m_xc.getObject(); - assertNotNull(gl.schemaType()); - assertEquals(gl.schemaType(), XmlBeans.typeForClass(GeographicLocation.class)); + void testTypeForClass() throws Exception { + try (XmlCursor m_xc = jcur(Common.TRANXML_FILE_CLM)) { + m_xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT + "$this//GeographicLocation"); + m_xc.toNextSelection(); + GeographicLocation gl = (GeographicLocation) m_xc.getObject(); + assertNotNull(gl.schemaType()); + assertEquals(gl.schemaType(), XmlBeans.typeForClass(GeographicLocation.class)); + } } @Test - public void testGetBuiltInTypeSystem() { + void testGetBuiltInTypeSystem() { SchemaTypeSystem sts = XmlBeans.getBuiltinTypeSystem(); - if (sts == null) { - fail("XmlBeans.getBuiltinTypeSystem() returned null"); - } + assertNotNull(sts, "XmlBeans.getBuiltinTypeSystem() returned null"); String sSchemaURI = "http://www.w3.org/2001/XMLSchema"; QName name = new QName(sSchemaURI, "dateTime"); SchemaType stDateTime = sts.findType(name); assertEquals(14, stDateTime.getBuiltinTypeCode()); } - @Test + @Disabled public void testTypeLoaderUnion() { - System.out.println("testTypeLoaderUnion not implemented"); // TODO } @Test - public void testTypeLoaderForClassLoader() throws Exception { - + void testTypeLoaderForClassLoader() throws Exception { SchemaTypeLoader stl = XmlBeans.typeLoaderForClassLoader(CarLocationMessageDocument.class.getClassLoader()); - if (stl == null) - fail("typeLoaderForClassLoader failed with CarLocationMessageDocument.class"); - m_xo = stl.parse(JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM), null, null); - m_xc = m_xo.newCursor(); - m_xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT + "$this//FleetID"); - m_xc.toNextSelection(); - assertEquals("FLEETNAME", m_xc.getTextValue()); + assertNotNull(stl, "typeLoaderForClassLoader failed with CarLocationMessageDocument.class"); + try (XmlCursor m_xc = stl.parse(JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM), null, null).newCursor()){ + m_xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT + "$this//FleetID"); + m_xc.toNextSelection(); + assertEquals("FLEETNAME", m_xc.getTextValue()); + } } @Test - public void testGetContextTypeLoader() throws Exception { + void testGetContextTypeLoader() throws Exception { SchemaTypeLoader stl = XmlBeans.getContextTypeLoader(); - if (stl == null) - fail("getContextTypeLoader failed"); + assertNotNull(stl, "getContextTypeLoader failed"); - Vector vThreads = new Vector(); - Set STLset = Collections.synchronizedSet(new HashSet()); + Vector<Thread> vThreads = new Vector<>(); + Set<SchemaTypeLoader> STLset = Collections.synchronizedSet(new HashSet<>()); for (int i = 0; i < 10000; i++) { Thread t = new BogusThread(STLset); vThreads.add(t); @@ -107,10 +104,10 @@ public class XmlLoaderMiscTest extends B } - public class BogusThread extends Thread { - private Set set; + private static class BogusThread extends Thread { + private final Set<SchemaTypeLoader> set; - public BogusThread(Set set) { + public BogusThread(Set<SchemaTypeLoader> set) { this.set = set; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
