Skip to content

Commit

Permalink
fix jakartaee#229 including tests (jakartaee#286)
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Santos Izaguirre <[email protected]>
Co-authored-by: Lukas Jungmann <[email protected]>
  • Loading branch information
antoniosanct and lukasj authored Feb 15, 2024
1 parent 3eb7824 commit b950cd8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 7 additions & 0 deletions api/src/main/java/jakarta/xml/bind/DatatypeConverterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public String printInteger(BigInteger val) {
}

public static String _printInteger(BigInteger val) {
if (null == val) throw new IllegalArgumentException("val is null");
return val.toString();
}

Expand Down Expand Up @@ -423,6 +424,7 @@ public String printDateTime(Calendar val) {
}

public static String _printDateTime(Calendar val) {
if (null == val) throw new IllegalArgumentException("val is null");
return CalendarFormatter.doFormat("%Y-%M-%DT%h:%m:%s%z", val);
}

Expand Down Expand Up @@ -471,6 +473,7 @@ private static int hexToBin(char ch) {

@Override
public String printHexBinary(byte[] data) {
if (null == data) throw new IllegalArgumentException("data is null");
StringBuilder r = new StringBuilder(data.length * 2);
for (byte b : data) {
r.append(hexCode[(b >> 4) & 0xF]);
Expand Down Expand Up @@ -501,6 +504,7 @@ public Calendar parseTime(String lexicalXSDTime) {

@Override
public String printTime(Calendar val) {
if (null == val) throw new IllegalArgumentException("val is null");
return CalendarFormatter.doFormat("%h:%m:%s%z", val);
}

Expand All @@ -515,6 +519,7 @@ public String printDate(Calendar val) {
}

public static String _printDate(Calendar val) {
if (null == val) throw new IllegalArgumentException("val is null");
return CalendarFormatter.doFormat((new StringBuilder("%Y-%M-%D").append("%z")).toString(),val);
}

Expand Down Expand Up @@ -554,6 +559,7 @@ public String printDecimal(BigDecimal val) {
}

public static String _printDecimal(BigDecimal val) {
if (null == val) throw new IllegalArgumentException("val is null");
return val.toPlainString();
}

Expand Down Expand Up @@ -780,6 +786,7 @@ public static byte encodeByte(int i) {
}

public static String _printBase64Binary(byte[] input) {
if (null == input) throw new IllegalArgumentException("input is null");
return _printBase64Binary(input, 0, input.length);
}

Expand Down
28 changes: 26 additions & 2 deletions api/src/test/java/org/eclipse/jaxb/api/DatatypeConverterTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -56,12 +56,36 @@ public void testParseBoolean() {
Assert.assertEquals(true, DatatypeConverter.parseBoolean(" true "));
}

@Test
public void testPrint() {
Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printInteger(null));
Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printDateTime(null));
Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printHexBinary(null));
Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printTime(null));
Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printDate(null));
Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printDecimal(null));
Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printBase64Binary(null));

//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printShort(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printFloat(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printBoolean(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printByte(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printUnsignedInt(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printString(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printInt(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printLong(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printDouble(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printQName(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printUnsignedShort(null));
//Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.printAnySimpleType(null));

}

@Test
public void testBase64() {
Assert.assertThrows(IllegalArgumentException.class, () -> DatatypeConverter.parseBase64Binary("Qxx=="));
Assert.assertNotEquals("Hello, world!", new String(DatatypeConverter.parseBase64Binary("SGVsbG8sIJdvcmxkIQ==")));

Assert.assertEquals("Hello, world!", new String(DatatypeConverter.parseBase64Binary("SGVsbG8sIHdvcmxkIQ==")));
}

}

0 comments on commit b950cd8

Please sign in to comment.