diff --git a/spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java index d6a539691cd..19a067e4805 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.oxm; import java.io.ByteArrayOutputStream; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -66,7 +67,7 @@ public abstract class AbstractMarshallerTests { protected abstract Object createFlights(); @Test - public void marshalDOMResult() throws Exception { + void marshalDOMResult() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); @@ -89,7 +90,7 @@ public abstract class AbstractMarshallerTests { } @Test - public void marshalEmptyDOMResult() throws Exception { + void marshalEmptyDOMResult() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); @@ -114,7 +115,7 @@ public abstract class AbstractMarshallerTests { } @Test - public void marshalStreamResultWriter() throws Exception { + void marshalStreamResultWriter() throws Exception { StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); marshaller.marshal(flights, result); @@ -122,15 +123,15 @@ public abstract class AbstractMarshallerTests { } @Test - public void marshalStreamResultOutputStream() throws Exception { + void marshalStreamResultOutputStream() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); StreamResult result = new StreamResult(os); marshaller.marshal(flights, result); - assertThat(XmlContent.of(new String(os.toByteArray(), "UTF-8"))).isSimilarToIgnoringWhitespace(EXPECTED_STRING); + assertThat(XmlContent.of(os.toString(StandardCharsets.UTF_8))).isSimilarToIgnoringWhitespace(EXPECTED_STRING); } @Test - public void marshalStaxResultStreamWriter() throws Exception { + void marshalStaxResultStreamWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); @@ -140,7 +141,7 @@ public abstract class AbstractMarshallerTests { } @Test - public void marshalStaxResultEventWriter() throws Exception { + void marshalStaxResultEventWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer); @@ -150,7 +151,7 @@ public abstract class AbstractMarshallerTests { } @Test - public void marshalJaxp14StaxResultStreamWriter() throws Exception { + void marshalJaxp14StaxResultStreamWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); @@ -160,7 +161,7 @@ public abstract class AbstractMarshallerTests { } @Test - public void marshalJaxp14StaxResultEventWriter() throws Exception { + void marshalJaxp14StaxResultEventWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer); diff --git a/spring-oxm/src/test/java/org/springframework/oxm/AbstractUnmarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/AbstractUnmarshallerTests.java index 9795f47566c..4101925e059 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/AbstractUnmarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/AbstractUnmarshallerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.oxm; import java.io.ByteArrayInputStream; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilder; @@ -69,7 +70,7 @@ public abstract class AbstractUnmarshallerTests { protected abstract void testFlight(Object o); @Test - public void unmarshalDomSource() throws Exception { + void unmarshalDomSource() throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.newDocument(); Element flightsElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flights"); @@ -86,21 +87,22 @@ public abstract class AbstractUnmarshallerTests { } @Test - public void unmarshalStreamSourceReader() throws Exception { + void unmarshalStreamSourceReader() throws Exception { StreamSource source = new StreamSource(new StringReader(INPUT_STRING)); Object flights = unmarshaller.unmarshal(source); testFlights(flights); } @Test - public void unmarshalStreamSourceInputStream() throws Exception { - StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8"))); + void unmarshalStreamSourceInputStream() throws Exception { + StreamSource source = new StreamSource(new ByteArrayInputStream( + INPUT_STRING.getBytes(StandardCharsets.UTF_8))); Object flights = unmarshaller.unmarshal(source); testFlights(flights); } @Test - public void unmarshalSAXSource() throws Exception { + void unmarshalSAXSource() throws Exception { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setNamespaceAware(true); SAXParser saxParser = saxParserFactory.newSAXParser(); @@ -111,7 +113,7 @@ public abstract class AbstractUnmarshallerTests { } @Test - public void unmarshalStaxSourceXmlStreamReader() throws Exception { + void unmarshalStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); Source source = StaxUtils.createStaxSource(streamReader); @@ -120,7 +122,7 @@ public abstract class AbstractUnmarshallerTests { } @Test - public void unmarshalStaxSourceXmlEventReader() throws Exception { + void unmarshalStaxSourceXmlEventReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING)); Source source = StaxUtils.createStaxSource(eventReader); @@ -129,7 +131,7 @@ public abstract class AbstractUnmarshallerTests { } @Test - public void unmarshalJaxp14StaxSourceXmlStreamReader() throws Exception { + void unmarshalJaxp14StaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); StAXSource source = new StAXSource(streamReader); @@ -138,7 +140,7 @@ public abstract class AbstractUnmarshallerTests { } @Test - public void unmarshalJaxp14StaxSourceXmlEventReader() throws Exception { + void unmarshalJaxp14StaxSourceXmlEventReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING)); StAXSource source = new StAXSource(eventReader); @@ -147,7 +149,7 @@ public abstract class AbstractUnmarshallerTests { } @Test - public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { + protected void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); streamReader.nextTag(); // skip to flights diff --git a/spring-oxm/src/test/java/org/springframework/oxm/config/OxmNamespaceHandlerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/config/OxmNamespaceHandlerTests.java index 315f9fb2c62..6bf8e1e4732 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/config/OxmNamespaceHandlerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/config/OxmNamespaceHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,20 +31,20 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Jakub Narloch * @author Sam Brannen */ -public class OxmNamespaceHandlerTests { +class OxmNamespaceHandlerTests { private final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("oxmNamespaceHandlerTest.xml", getClass()); @Test - public void jaxb2ContextPathMarshaller() { + void jaxb2ContextPathMarshaller() { Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ContextPathMarshaller", Jaxb2Marshaller.class); assertThat(jaxb2Marshaller).isNotNull(); } @Test - public void jaxb2ClassesToBeBoundMarshaller() { + void jaxb2ClassesToBeBoundMarshaller() { Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ClassesMarshaller", Jaxb2Marshaller.class); assertThat(jaxb2Marshaller).isNotNull(); } diff --git a/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java index 7806276d8e6..37b49b2f8cf 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java @@ -148,13 +148,13 @@ class Jaxb2MarshallerTests extends AbstractMarshallerTests { } @Test - void noContextPathOrClassesToBeBound() throws Exception { + void noContextPathOrClassesToBeBound() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); assertThatIllegalArgumentException().isThrownBy(marshaller::afterPropertiesSet); } @Test - void testInvalidContextPath() throws Exception { + void testInvalidContextPath() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setContextPath("ab"); assertThatExceptionOfType(UncategorizedMappingException.class).isThrownBy(marshaller::afterPropertiesSet); diff --git a/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java index 61286ce9c4a..ad8b9701b3c 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java @@ -48,7 +48,7 @@ import static org.mockito.Mockito.mock; * @author Biju Kunjummen * @author Sam Brannen */ -public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests { +class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests { private static final String INPUT_STRING = "" + "42"; @@ -78,7 +78,7 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests { + assertThat(object.getBytes()).as("bytes property not set").isNotNull(); + assertThat(object.getBytes()).as("bytes property not set").isNotEmpty(); + assertThat(object.getSwaDataHandler()).as("datahandler property not set").isNotNull(); + }); } @Test @@ -129,7 +128,7 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTeststest")); @@ -138,7 +137,7 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests> aliases = new HashMap<>(); @@ -62,7 +62,7 @@ public class XStreamUnmarshallerTests { @Test - public void unmarshalDomSource() throws Exception { + void unmarshalDomSource() throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(INPUT_STRING))); DOMSource source = new DOMSource(document); @@ -71,7 +71,7 @@ public class XStreamUnmarshallerTests { } @Test - public void unmarshalStaxSourceXmlStreamReader() throws Exception { + void unmarshalStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); Source source = StaxUtils.createStaxSource(streamReader); @@ -80,14 +80,14 @@ public class XStreamUnmarshallerTests { } @Test - public void unmarshalStreamSourceInputStream() throws Exception { + void unmarshalStreamSourceInputStream() throws Exception { StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes(StandardCharsets.UTF_8))); Object flights = unmarshaller.unmarshal(source); testFlight(flights); } @Test - public void unmarshalStreamSourceReader() throws Exception { + void unmarshalStreamSourceReader() throws Exception { StreamSource source = new StreamSource(new StringReader(INPUT_STRING)); Object flights = unmarshaller.unmarshal(source); testFlight(flights); @@ -95,11 +95,10 @@ public class XStreamUnmarshallerTests { private void testFlight(Object o) { - boolean condition = o instanceof Flight; - assertThat(condition).as("Unmarshalled object is not Flights").isTrue(); - Flight flight = (Flight) o; - assertThat(flight).as("Flight is null").isNotNull(); - assertThat(flight.getFlightNumber()).as("Number is invalid").isEqualTo(42L); + assertThat(o).isInstanceOfSatisfying(Flight.class, flight -> { + assertThat(flight).as("Flight is null").isNotNull(); + assertThat(flight.getFlightNumber()).as("Number is invalid").isEqualTo(42L); + }); } }