Migrate JUnit 4 assertions to AssertJ
Migrate all existing JUnit 4 `assert...` based assertions to AssertJ and add a checkstyle rule to ensure they don't return. See gh-23022
This commit is contained in:
@@ -39,7 +39,6 @@ import org.springframework.tests.XmlContent;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -95,7 +94,8 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
||||
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
|
||||
DOMResult domResult = new DOMResult();
|
||||
marshaller.marshal(flights, domResult);
|
||||
assertTrue("DOMResult does not contain a Document", domResult.getNode() instanceof Document);
|
||||
boolean condition = domResult.getNode() instanceof Document;
|
||||
assertThat(condition).as("DOMResult does not contain a Document").isTrue();
|
||||
Document result = (Document) domResult.getNode();
|
||||
Document expected = builder.newDocument();
|
||||
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.xml.sax.XMLReader;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -146,11 +146,9 @@ public abstract class AbstractUnmarshallerTests<U extends Unmarshaller> {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
|
||||
streamReader.nextTag(); // skip to flights
|
||||
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
|
||||
streamReader.getName());
|
||||
assertThat(streamReader.getName()).as("Invalid element").isEqualTo(new QName("http://samples.springframework.org/flight", "flights"));
|
||||
streamReader.nextTag(); // skip to flight
|
||||
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
|
||||
streamReader.getName());
|
||||
assertThat(streamReader.getName()).as("Invalid element").isEqualTo(new QName("http://samples.springframework.org/flight", "flight"));
|
||||
Source source = StaxUtils.createStaxSource(streamReader);
|
||||
Object flight = unmarshaller.unmarshal(source);
|
||||
testFlight(flight);
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the {@link OxmNamespaceHandler} class.
|
||||
@@ -40,13 +40,13 @@ public class OxmNamespaceHandlerTests {
|
||||
@Test
|
||||
public void jaxb2ContextPathMarshaller() {
|
||||
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ContextPathMarshaller", Jaxb2Marshaller.class);
|
||||
assertNotNull(jaxb2Marshaller);
|
||||
assertThat(jaxb2Marshaller).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jaxb2ClassesToBeBoundMarshaller() {
|
||||
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ClassesMarshaller", Jaxb2Marshaller.class);
|
||||
assertNotNull(jaxb2Marshaller);
|
||||
assertThat(jaxb2Marshaller).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,9 +59,6 @@ import org.springframework.util.ReflectionUtils;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -196,32 +193,29 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
||||
}
|
||||
|
||||
private void testSupports() throws Exception {
|
||||
assertTrue("Jaxb2Marshaller does not support Flights class", marshaller.supports(Flights.class));
|
||||
assertTrue("Jaxb2Marshaller does not support Flights generic type", marshaller.supports((Type)Flights.class));
|
||||
assertThat(marshaller.supports(Flights.class)).as("Jaxb2Marshaller does not support Flights class").isTrue();
|
||||
assertThat(marshaller.supports((Type)Flights.class)).as("Jaxb2Marshaller does not support Flights generic type").isTrue();
|
||||
|
||||
assertFalse("Jaxb2Marshaller supports FlightType class", marshaller.supports(FlightType.class));
|
||||
assertFalse("Jaxb2Marshaller supports FlightType type", marshaller.supports((Type)FlightType.class));
|
||||
assertThat(marshaller.supports(FlightType.class)).as("Jaxb2Marshaller supports FlightType class").isFalse();
|
||||
assertThat(marshaller.supports((Type)FlightType.class)).as("Jaxb2Marshaller supports FlightType type").isFalse();
|
||||
|
||||
Method method = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
|
||||
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>",
|
||||
marshaller.supports(method.getGenericReturnType()));
|
||||
assertThat(marshaller.supports(method.getGenericReturnType())).as("Jaxb2Marshaller does not support JAXBElement<FlightsType>").isTrue();
|
||||
|
||||
marshaller.setSupportJaxbElementClass(true);
|
||||
JAXBElement<FlightType> flightTypeJAXBElement = new JAXBElement<>(new QName("https://springframework.org", "flight"), FlightType.class,
|
||||
new FlightType());
|
||||
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>", marshaller.supports(flightTypeJAXBElement.getClass()));
|
||||
assertThat(marshaller.supports(flightTypeJAXBElement.getClass())).as("Jaxb2Marshaller does not support JAXBElement<FlightsType>").isTrue();
|
||||
|
||||
assertFalse("Jaxb2Marshaller supports class not in context path", marshaller.supports(DummyRootElement.class));
|
||||
assertFalse("Jaxb2Marshaller supports type not in context path", marshaller.supports((Type)DummyRootElement.class));
|
||||
assertThat(marshaller.supports(DummyRootElement.class)).as("Jaxb2Marshaller supports class not in context path").isFalse();
|
||||
assertThat(marshaller.supports((Type)DummyRootElement.class)).as("Jaxb2Marshaller supports type not in context path").isFalse();
|
||||
method = getClass().getDeclaredMethod("createDummyRootElement");
|
||||
assertFalse("Jaxb2Marshaller supports JAXBElement not in context path",
|
||||
marshaller.supports(method.getGenericReturnType()));
|
||||
assertThat(marshaller.supports(method.getGenericReturnType())).as("Jaxb2Marshaller supports JAXBElement not in context path").isFalse();
|
||||
|
||||
assertFalse("Jaxb2Marshaller supports class not in context path", marshaller.supports(DummyType.class));
|
||||
assertFalse("Jaxb2Marshaller supports type not in context path", marshaller.supports((Type)DummyType.class));
|
||||
assertThat(marshaller.supports(DummyType.class)).as("Jaxb2Marshaller supports class not in context path").isFalse();
|
||||
assertThat(marshaller.supports((Type)DummyType.class)).as("Jaxb2Marshaller supports type not in context path").isFalse();
|
||||
method = getClass().getDeclaredMethod("createDummyType");
|
||||
assertFalse("Jaxb2Marshaller supports JAXBElement not in context path",
|
||||
marshaller.supports(method.getGenericReturnType()));
|
||||
assertThat(marshaller.supports(method.getGenericReturnType())).as("Jaxb2Marshaller supports JAXBElement not in context path").isFalse();
|
||||
|
||||
testSupportsPrimitives();
|
||||
testSupportsStandardClasses();
|
||||
@@ -233,8 +227,7 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
||||
@Override
|
||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
||||
Type returnType = method.getGenericReturnType();
|
||||
assertTrue("Jaxb2Marshaller does not support JAXBElement<" + method.getName().substring(9) + ">",
|
||||
marshaller.supports(returnType));
|
||||
assertThat(marshaller.supports(returnType)).as("Jaxb2Marshaller does not support JAXBElement<" + method.getName().substring(9) + ">").isTrue();
|
||||
try {
|
||||
// make sure the marshalling does not result in errors
|
||||
Object returnValue = method.invoke(primitives);
|
||||
@@ -258,8 +251,7 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
||||
@Override
|
||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
||||
Type returnType = method.getGenericReturnType();
|
||||
assertTrue("Jaxb2Marshaller does not support JAXBElement<" + method.getName().substring(13) + ">",
|
||||
marshaller.supports(returnType));
|
||||
assertThat(marshaller.supports(returnType)).as("Jaxb2Marshaller does not support JAXBElement<" + method.getName().substring(13) + ">").isTrue();
|
||||
try {
|
||||
// make sure the marshalling does not result in errors
|
||||
Object returnValue = method.invoke(standardClasses);
|
||||
@@ -282,11 +274,11 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
||||
marshaller = new Jaxb2Marshaller();
|
||||
marshaller.setClassesToBeBound(DummyRootElement.class, DummyType.class);
|
||||
marshaller.afterPropertiesSet();
|
||||
assertTrue("Jaxb2Marshaller does not support XmlRootElement class", marshaller.supports(DummyRootElement.class));
|
||||
assertTrue("Jaxb2Marshaller does not support XmlRootElement generic type", marshaller.supports((Type)DummyRootElement.class));
|
||||
assertThat(marshaller.supports(DummyRootElement.class)).as("Jaxb2Marshaller does not support XmlRootElement class").isTrue();
|
||||
assertThat(marshaller.supports((Type)DummyRootElement.class)).as("Jaxb2Marshaller does not support XmlRootElement generic type").isTrue();
|
||||
|
||||
assertFalse("Jaxb2Marshaller supports DummyType class", marshaller.supports(DummyType.class));
|
||||
assertFalse("Jaxb2Marshaller supports DummyType type", marshaller.supports((Type)DummyType.class));
|
||||
assertThat(marshaller.supports(DummyType.class)).as("Jaxb2Marshaller supports DummyType class").isFalse();
|
||||
assertThat(marshaller.supports((Type)DummyType.class)).as("Jaxb2Marshaller supports DummyType type").isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -306,7 +298,7 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
||||
BinaryObject object = new BinaryObject(bytes, dataHandler);
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(object, new StreamResult(writer), mimeContainer);
|
||||
assertTrue("No XML written", writer.toString().length() > 0);
|
||||
assertThat(writer.toString().length() > 0).as("No XML written").isTrue();
|
||||
verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class));
|
||||
}
|
||||
|
||||
@@ -341,8 +333,8 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
||||
verify(unmarshaller).unmarshal(sourceCaptor.capture());
|
||||
|
||||
SAXSource result = sourceCaptor.getValue();
|
||||
assertEquals(true, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl"));
|
||||
assertEquals(false, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities"));
|
||||
assertThat(result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl")).isEqualTo(true);
|
||||
assertThat(result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities")).isEqualTo(false);
|
||||
|
||||
// 2. external-general-entities and dtd support enabled
|
||||
|
||||
@@ -354,8 +346,8 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
||||
verify(unmarshaller).unmarshal(sourceCaptor.capture());
|
||||
|
||||
result = sourceCaptor.getValue();
|
||||
assertEquals(false, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl"));
|
||||
assertEquals(true, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities"));
|
||||
assertThat(result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl")).isEqualTo(false);
|
||||
assertThat(result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities")).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test // SPR-10806
|
||||
@@ -375,8 +367,8 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
||||
verify(unmarshaller).unmarshal(sourceCaptor.capture());
|
||||
|
||||
SAXSource result = sourceCaptor.getValue();
|
||||
assertEquals(true, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl"));
|
||||
assertEquals(false, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities"));
|
||||
assertThat(result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl")).isEqualTo(true);
|
||||
assertThat(result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities")).isEqualTo(false);
|
||||
|
||||
// 2. external-general-entities and dtd support enabled
|
||||
|
||||
@@ -388,8 +380,8 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
||||
verify(unmarshaller).unmarshal(sourceCaptor.capture());
|
||||
|
||||
result = sourceCaptor.getValue();
|
||||
assertEquals(false, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl"));
|
||||
assertEquals(true, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities"));
|
||||
assertThat(result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl")).isEqualTo(false);
|
||||
assertThat(result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities")).isEqualTo(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,9 +37,7 @@ import org.springframework.oxm.jaxb.test.Flights;
|
||||
import org.springframework.oxm.mime.MimeContainer;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -65,16 +63,16 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests<Jaxb2Marsh
|
||||
@Override
|
||||
protected void testFlights(Object o) {
|
||||
Flights flights = (Flights) o;
|
||||
assertNotNull("Flights is null", flights);
|
||||
assertEquals("Invalid amount of flight elements", 1, flights.getFlight().size());
|
||||
assertThat(flights).as("Flights is null").isNotNull();
|
||||
assertThat(flights.getFlight().size()).as("Invalid amount of flight elements").isEqualTo(1);
|
||||
testFlight(flights.getFlight().get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testFlight(Object o) {
|
||||
FlightType flight = (FlightType) o;
|
||||
assertNotNull("Flight is null", flight);
|
||||
assertEquals("Number is invalid", 42L, flight.getNumber());
|
||||
assertThat(flight).as("Flight is null").isNotNull();
|
||||
assertThat(flight.getNumber()).as("Number is invalid").isEqualTo(42L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,11 +100,12 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests<Jaxb2Marsh
|
||||
|
||||
StringReader reader = new StringReader(content);
|
||||
Object result = unmarshaller.unmarshal(new StreamSource(reader), mimeContainer);
|
||||
assertTrue("Result is not a BinaryObject", result instanceof BinaryObject);
|
||||
boolean condition = result instanceof BinaryObject;
|
||||
assertThat(condition).as("Result is not a BinaryObject").isTrue();
|
||||
BinaryObject object = (BinaryObject) result;
|
||||
assertNotNull("bytes property not set", object.getBytes());
|
||||
assertTrue("bytes property not set", object.getBytes().length > 0);
|
||||
assertNotNull("datahandler property not set", object.getSwaDataHandler());
|
||||
assertThat(object.getBytes()).as("bytes property not set").isNotNull();
|
||||
assertThat(object.getBytes().length > 0).as("bytes property not set").isTrue();
|
||||
assertThat(object.getSwaDataHandler()).as("datahandler property not set").isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,8 +132,7 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests<Jaxb2Marsh
|
||||
Source source = new StreamSource(new StringReader(
|
||||
"<brand-airplane><name>test</name></brand-airplane>"));
|
||||
JAXBElement<Airplane> airplane = (JAXBElement<Airplane>) unmarshaller.unmarshal(source);
|
||||
assertEquals("Unmarshalling via explicit @XmlRegistry tag should return correct type",
|
||||
"test", airplane.getValue().getName());
|
||||
assertThat(airplane.getValue().getName()).as("Unmarshalling via explicit @XmlRegistry tag should return correct type").isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,8 +27,6 @@ import org.springframework.tests.XmlContent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
/**
|
||||
@@ -90,8 +88,7 @@ public class JibxMarshallerTests extends AbstractMarshallerTests<JibxMarshaller>
|
||||
marshaller.setStandalone(Boolean.TRUE);
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(flights, new StreamResult(writer));
|
||||
assertTrue("Encoding and standalone not set",
|
||||
writer.toString().startsWith("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>"));
|
||||
assertThat(writer.toString().startsWith("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>")).as("Encoding and standalone not set").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,15 +97,14 @@ public class JibxMarshallerTests extends AbstractMarshallerTests<JibxMarshaller>
|
||||
marshaller.setDocTypeSystemId("flights.dtd");
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(flights, new StreamResult(writer));
|
||||
assertTrue("doc type not written",
|
||||
writer.toString().contains("<!DOCTYPE flights SYSTEM \"flights.dtd\">"));
|
||||
assertThat(writer.toString().contains("<!DOCTYPE flights SYSTEM \"flights.dtd\">")).as("doc type not written").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supports() throws Exception {
|
||||
assertTrue("JibxMarshaller does not support Flights", marshaller.supports(Flights.class));
|
||||
assertTrue("JibxMarshaller does not support FlightType", marshaller.supports(FlightType.class));
|
||||
assertFalse("JibxMarshaller supports illegal type", marshaller.supports(getClass()));
|
||||
assertThat(marshaller.supports(Flights.class)).as("JibxMarshaller does not support Flights").isTrue();
|
||||
assertThat(marshaller.supports(FlightType.class)).as("JibxMarshaller does not support FlightType").isTrue();
|
||||
assertThat(marshaller.supports(getClass())).as("JibxMarshaller supports illegal type").isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.oxm.AbstractUnmarshallerTests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
/**
|
||||
@@ -61,16 +60,16 @@ public class JibxUnmarshallerTests extends AbstractUnmarshallerTests<JibxMarshal
|
||||
@Override
|
||||
protected void testFlights(Object o) {
|
||||
Flights flights = (Flights) o;
|
||||
assertNotNull("Flights is null", flights);
|
||||
assertEquals("Invalid amount of flight elements", 1, flights.sizeFlightList());
|
||||
assertThat(flights).as("Flights is null").isNotNull();
|
||||
assertThat(flights.sizeFlightList()).as("Invalid amount of flight elements").isEqualTo(1);
|
||||
testFlight(flights.getFlight(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void testFlight(Object o) {
|
||||
FlightType flight = (FlightType) o;
|
||||
assertNotNull("Flight is null", flight);
|
||||
assertEquals("Number is invalid", 42L, flight.getNumber());
|
||||
assertThat(flight).as("Flight is null").isNotNull();
|
||||
assertThat(flight.getNumber()).as("Number is invalid").isEqualTo(42L);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +89,7 @@ public class JibxUnmarshallerTests extends AbstractUnmarshallerTests<JibxMarshal
|
||||
testFlights(flights);
|
||||
|
||||
FlightType flight = ((Flights)flights).getFlight(0);
|
||||
assertEquals("Airline is invalid", "Air Libert\u00e9", flight.getAirline());
|
||||
assertThat(flight.getAirline()).as("Airline is invalid").isEqualTo("Air Libert\u00e9");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,9 +60,6 @@ import org.springframework.tests.XmlContent;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
@@ -199,7 +196,7 @@ public class XStreamMarshallerTests {
|
||||
assertThat(XmlContent.from(writer)).isSimilarTo("<byte-array>AQI=</byte-array>");
|
||||
Reader reader = new StringReader(writer.toString());
|
||||
byte[] bufResult = (byte[]) marshaller.unmarshal(new StreamSource(reader));
|
||||
assertTrue("Invalid result", Arrays.equals(buf, bufResult));
|
||||
assertThat(Arrays.equals(buf, bufResult)).as("Invalid result").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -314,12 +311,12 @@ public class XStreamMarshallerTests {
|
||||
marshaller.setStreamDriver(new JettisonMappedXmlDriver());
|
||||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(flight, new StreamResult(writer));
|
||||
assertEquals("Invalid result", "{\"flight\":{\"flightNumber\":42}}", writer.toString());
|
||||
assertThat(writer.toString()).as("Invalid result").isEqualTo("{\"flight\":{\"flightNumber\":42}}");
|
||||
Object o = marshaller.unmarshal(new StreamSource(new StringReader(writer.toString())));
|
||||
assertTrue("Unmarshalled object is not Flights", o instanceof Flight);
|
||||
assertThat(o instanceof Flight).as("Unmarshalled object is not Flights").isTrue();
|
||||
Flight unflight = (Flight) o;
|
||||
assertNotNull("Flight is null", unflight);
|
||||
assertEquals("Number is invalid", 42L, unflight.getFlightNumber());
|
||||
assertThat(unflight).as("Flight is null").isNotNull();
|
||||
assertThat(unflight.getFlightNumber()).as("Number is invalid").isEqualTo(42L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -335,7 +332,7 @@ public class XStreamMarshallerTests {
|
||||
|
||||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(flight, new StreamResult(writer));
|
||||
assertEquals("Invalid result", "{\"flightNumber\": 42}", writer.toString());
|
||||
assertThat(writer.toString()).as("Invalid result").isEqualTo("{\"flightNumber\": 42}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -354,17 +351,17 @@ public class XStreamMarshallerTests {
|
||||
private static void assertXpathExists(String xPathExpression, String inXMLString){
|
||||
Source source = Input.fromString(inXMLString).build();
|
||||
Iterable<Node> nodes = new JAXPXPathEngine().selectNodes(xPathExpression, source);
|
||||
assertTrue("Expecting to find matches for Xpath " + xPathExpression, count(nodes) > 0);
|
||||
assertThat(count(nodes) > 0).as("Expecting to find matches for Xpath " + xPathExpression).isTrue();
|
||||
}
|
||||
|
||||
private static void assertXpathNotExists(String xPathExpression, String inXMLString){
|
||||
Source source = Input.fromString(inXMLString).build();
|
||||
Iterable<Node> nodes = new JAXPXPathEngine().selectNodes(xPathExpression, source);
|
||||
assertEquals("Should be zero matches for Xpath " + xPathExpression, 0, count(nodes));
|
||||
assertThat(count(nodes)).as("Should be zero matches for Xpath " + xPathExpression).isEqualTo(0);
|
||||
}
|
||||
|
||||
private static int count(Iterable<Node> nodes) {
|
||||
assertNotNull(nodes);
|
||||
assertThat(nodes).isNotNull();
|
||||
AtomicInteger count = new AtomicInteger();
|
||||
nodes.forEach(n -> count.incrementAndGet());
|
||||
return count.get();
|
||||
|
||||
@@ -35,9 +35,7 @@ import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -57,10 +55,11 @@ public class XStreamUnmarshallerTests {
|
||||
}
|
||||
|
||||
private void testFlight(Object o) {
|
||||
assertTrue("Unmarshalled object is not Flights", o instanceof Flight);
|
||||
boolean condition = o instanceof Flight;
|
||||
assertThat(condition).as("Unmarshalled object is not Flights").isTrue();
|
||||
Flight flight = (Flight) o;
|
||||
assertNotNull("Flight is null", flight);
|
||||
assertEquals("Number is invalid", 42L, flight.getFlightNumber());
|
||||
assertThat(flight).as("Flight is null").isNotNull();
|
||||
assertThat(flight.getFlightNumber()).as("Number is invalid").isEqualTo(42L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user