|
4 | 4 | import static org.hamcrest.CoreMatchers.instanceOf;
|
5 | 5 | import static org.hamcrest.CoreMatchers.is;
|
6 | 6 | import static org.junit.Assert.assertArrayEquals;
|
| 7 | +import static org.junit.Assert.assertContentEquals; |
7 | 8 | import static org.junit.Assert.assertEquals;
|
8 | 9 | import static org.junit.Assert.assertNotEquals;
|
9 | 10 | import static org.junit.Assert.assertNotSame;
|
@@ -956,6 +957,90 @@ public void expectThrowsUsesCanonicalNameWhenRequiredExceptionNotThrown() {
|
956 | 957 | throw new AssertionError(ASSERTION_ERROR_EXPECTED);
|
957 | 958 | }
|
958 | 959 |
|
| 960 | + @Test |
| 961 | + public void assertContentEqualsPass() throws Exception { |
| 962 | + String expected = "StringValue"; |
| 963 | + CharSequence charSequence = new String("StringValue"); |
| 964 | + assertContentEquals(expected, charSequence); |
| 965 | + } |
| 966 | + |
| 967 | + @Test |
| 968 | + public void assertContentEqualsPassBothNull() throws Exception { |
| 969 | + String expected = null; |
| 970 | + CharSequence charSequence = null; |
| 971 | + assertContentEquals(expected, charSequence); |
| 972 | + } |
| 973 | + |
| 974 | + @Test |
| 975 | + public void assertContentsActualNull() { |
| 976 | + String expected = "StringValue"; |
| 977 | + CharSequence charSequence = null; |
| 978 | + try { |
| 979 | + assertContentEquals(expected, charSequence); |
| 980 | + } catch (AssertionError exception) { |
| 981 | + String expectedException = "expected:<StringValue> but was:<null>"; |
| 982 | + assertEquals(expectedException, exception.getMessage()); |
| 983 | + return; |
| 984 | + } |
| 985 | + fail("Expected an AssertionError"); |
| 986 | + } |
| 987 | + |
| 988 | + @Test |
| 989 | + public void assertContentsExpectedNull() { |
| 990 | + String expected = null; |
| 991 | + CharSequence charSequence = new String("StringValue"); |
| 992 | + try { |
| 993 | + assertContentEquals(expected, charSequence); |
| 994 | + } catch (AssertionError exception) { |
| 995 | + String expectedException = "expected:<null> but was:<StringValue>"; |
| 996 | + assertEquals(expectedException, exception.getMessage()); |
| 997 | + return; |
| 998 | + } |
| 999 | + fail("Expected an AssertionError"); |
| 1000 | + } |
| 1001 | + |
| 1002 | + @Test |
| 1003 | + public void assertContentEqualsNotEqualButSameLength() { |
| 1004 | + String expected = "StringValue"; |
| 1005 | + CharSequence charSequence = new String("NotTheSame!"); |
| 1006 | + try { |
| 1007 | + assertContentEquals(expected, charSequence); |
| 1008 | + } catch (AssertionError exception) { |
| 1009 | + String expectedException = "expected:<[StringValue]> but was:<[NotTheSame!]>"; |
| 1010 | + assertEquals(expectedException, exception.getMessage()); |
| 1011 | + return; |
| 1012 | + } |
| 1013 | + fail("Expected an AssertionError"); |
| 1014 | + } |
| 1015 | + |
| 1016 | + @Test |
| 1017 | + public void assertContentEqualsNotEqualDifferentLength() { |
| 1018 | + String expected = "StringValue"; |
| 1019 | + CharSequence charSequence = new String("NotTheSame"); |
| 1020 | + try { |
| 1021 | + assertContentEquals(expected, charSequence); |
| 1022 | + } catch (AssertionError exception) { |
| 1023 | + String expectedException = "expected:<[StringValu]e> but was:<[NotTheSam]e>"; |
| 1024 | + assertEquals(expectedException, exception.getMessage()); |
| 1025 | + return; |
| 1026 | + } |
| 1027 | + fail("Expected an AssertionError"); |
| 1028 | + } |
| 1029 | + |
| 1030 | + @Test |
| 1031 | + public void assertContentEqualsPassCustomMessage() throws Exception { |
| 1032 | + String expected = "StringValue"; |
| 1033 | + CharSequence charSequence = new String("StringValue"); |
| 1034 | + assertContentEquals("My Message", expected, charSequence); |
| 1035 | + } |
| 1036 | + |
| 1037 | + @Test |
| 1038 | + public void assertContentEqualsPassBothNullCustomMessage() throws Exception { |
| 1039 | + String expected = null; |
| 1040 | + CharSequence charSequence = null; |
| 1041 | + assertContentEquals("My Message", expected, charSequence); |
| 1042 | + } |
| 1043 | + |
959 | 1044 | private static class NestedException extends RuntimeException {
|
960 | 1045 | private static final long serialVersionUID = 1L;
|
961 | 1046 | }
|
|
0 commit comments