Refactor AssertJ assertions into more idiomatic ones

This commit refactors some AssertJ assertions into more idiomatic and
readable ones. Using the dedicated assertion instead of a generic one
will produce more meaningful error messages. 

For instance, consider collection size:
```
// expected: 5 but was: 2
assertThat(collection.size()).equals(5);
// Expected size: 5 but was: 2 in: [1, 2]
assertThat(collection).hasSize(5);
```

Closes gh-30104
This commit is contained in:
Krzysztof Krasoń
2023-04-04 17:34:07 +02:00
committed by GitHub
parent dd97ee4e99
commit 1734deca1e
371 changed files with 3177 additions and 3076 deletions

View File

@@ -287,7 +287,7 @@ class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshaller> {
BinaryObject object = new BinaryObject(bytes, dataHandler);
StringWriter writer = new StringWriter();
marshaller.marshal(object, new StreamResult(writer), mimeContainer);
assertThat(writer.toString().length() > 0).as("No XML written").isTrue();
assertThat(writer.toString()).as("No XML written").isNotEmpty();
verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class));
}

View File

@@ -66,7 +66,7 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests<Jaxb2Marsh
protected void testFlights(Object o) {
Flights flights = (Flights) o;
assertThat(flights).as("Flights is null").isNotNull();
assertThat(flights.getFlight().size()).as("Invalid amount of flight elements").isEqualTo(1);
assertThat(flights.getFlight()).as("Invalid amount of flight elements").hasSize(1);
testFlight(flights.getFlight().get(0));
}
@@ -106,7 +106,7 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests<Jaxb2Marsh
assertThat(condition).as("Result is not a BinaryObject").isTrue();
BinaryObject object = (BinaryObject) result;
assertThat(object.getBytes()).as("bytes property not set").isNotNull();
assertThat(object.getBytes().length > 0).as("bytes property not set").isTrue();
assertThat(object.getBytes()).as("bytes property not set").isNotEmpty();
assertThat(object.getSwaDataHandler()).as("datahandler property not set").isNotNull();
}

View File

@@ -339,7 +339,7 @@ class XStreamMarshallerTests {
marshaller.marshal(flight, new StreamResult(writer));
assertThat(writer.toString()).as("Invalid result").isEqualTo("{\"flight\":{\"flightNumber\":42}}");
Object o = marshaller.unmarshal(new StreamSource(new StringReader(writer.toString())));
assertThat(o instanceof Flight).as("Unmarshalled object is not Flights").isTrue();
assertThat(o).as("Unmarshalled object is not Flights").isInstanceOf(Flight.class);
Flight unflight = (Flight) o;
assertThat(unflight).as("Flight is null").isNotNull();
assertThat(unflight.getFlightNumber()).as("Number is invalid").isEqualTo(42L);
@@ -377,7 +377,7 @@ class XStreamMarshallerTests {
private static void assertXpathExists(String xPathExpression, String inXMLString){
Source source = Input.fromString(inXMLString).build();
Iterable<Node> nodes = new JAXPXPathEngine().selectNodes(xPathExpression, source);
assertThat(nodes).as("Expecting to find matches for Xpath " + xPathExpression).hasSizeGreaterThan(0);
assertThat(nodes).as("Expecting to find matches for Xpath " + xPathExpression).isNotEmpty();
}
private static void assertXpathDoesNotExist(String xPathExpression, String inXMLString){