diff --git a/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java b/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java index 69a210c95d4f..5468b7f9bcd1 100644 --- a/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java +++ b/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. diff --git a/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java b/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java index 6e855b37f698..d9efbcf003a1 100644 --- a/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java @@ -27,60 +27,54 @@ */ class XmlExpectationsHelperTests { + private static final String CONTROL = "f1f2"; + + private final XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); + + @Test void assertXmlEqualForEqual() throws Exception { - String control = "f1f2"; String test = "f1f2"; - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); - xmlHelper.assertXmlEqual(control, test); + xmlHelper.assertXmlEqual(CONTROL, test); } @Test void assertXmlEqualExceptionForIncorrectValue() { - String control = "f1f2"; String test = "notf1f2"; - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> - xmlHelper.assertXmlEqual(control, test)) - .withMessageStartingWith("Body content Expected child 'field1'"); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test)) + .withMessageStartingWith("Body content Expected child 'field1'"); } @Test void assertXmlEqualForOutOfOrder() throws Exception { - String control = "f1f2"; String test = "f2f1"; - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); - xmlHelper.assertXmlEqual(control, test); + xmlHelper.assertXmlEqual(CONTROL, test); } @Test void assertXmlEqualExceptionForMoreEntries() { - String control = "f1f2"; String test = "f1f2f3"; - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> - xmlHelper.assertXmlEqual(control, test)) - .withMessageContaining("Expected child nodelist length '2' but was '3'"); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test)) + .withMessageContaining("Expected child nodelist length '2' but was '3'"); } @Test - void assertXmlEqualExceptionForLessEntries() { + void assertXmlEqualExceptionForFewerEntries() { String control = "f1f2f3"; String test = "f1f2"; - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> - xmlHelper.assertXmlEqual(control, test)) - .withMessageContaining("Expected child nodelist length '3' but was '2'"); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> xmlHelper.assertXmlEqual(control, test)) + .withMessageContaining("Expected child nodelist length '3' but was '2'"); } @Test void assertXmlEqualExceptionWithFullDescription() { - String control = "f1f2"; String test = "f2f3"; - XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> - xmlHelper.assertXmlEqual(control, test)) + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> xmlHelper.assertXmlEqual(CONTROL, test)) .withMessageContaining("Expected child 'field1' but was 'null'") .withMessageContaining("Expected child 'null' but was 'field3'"); }