"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "junit-jupiter-engine/src/test/java/org/junit/jupiter/api/AssertEqualsAssertionsTests.java" between
junit5-r5.3.2.tar.gz and junit5-r5.4.0.tar.gz

About: JUnit 5 is a unit testing framework for the Java programming language.

AssertEqualsAssertionsTests.java  (junit5-r5.3.2):AssertEqualsAssertionsTests.java  (junit5-r5.4.0)
/* /*
* Copyright 2015-2018 the original author or authors. * Copyright 2015-2019 the original author or authors.
* *
* All rights reserved. This program and the accompanying materials are * All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which * made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at * accompanies this distribution and is available at
* *
* http://www.eclipse.org/legal/epl-v20.html * http://www.eclipse.org/legal/epl-v20.html
*/ */
package org.junit.jupiter.api; package org.junit.jupiter.api;
skipping to change at line 332 skipping to change at line 332
} }
@Test @Test
void assertEqualsFloatWithDelta() { void assertEqualsFloatWithDelta() {
assertEquals(0.0f, 0.0f, 0.1f); assertEquals(0.0f, 0.0f, 0.1f);
assertEquals(0.0f, 0.0f, 0.1f, "message"); assertEquals(0.0f, 0.0f, 0.1f, "message");
assertEquals(0.0f, 0.0f, 0.1f, () -> "message"); assertEquals(0.0f, 0.0f, 0.1f, () -> "message");
assertEquals(0.56f, 0.6f, 0.05f); assertEquals(0.56f, 0.6f, 0.05f);
assertEquals(0.01f, 0.011f, 0.002f); assertEquals(0.01f, 0.011f, 0.002f);
assertEquals(Float.NaN, Float.NaN, 0.5f); assertEquals(Float.NaN, Float.NaN, 0.5f);
assertEquals(0.1f, 0.1f, 0.0f);
} }
@Test @Test
void assertEqualsFloatWithIllegalDelta() { void assertEqualsFloatWithIllegalDelta() {
AssertionFailedError e1 = assertThrows(AssertionFailedError.class , () -> assertEquals(0.1f, 0.2f, -0.9f)); AssertionFailedError e1 = assertThrows(AssertionFailedError.class , () -> assertEquals(0.1f, 0.2f, -0.9f));
assertMessageEndsWith(e1, "positive delta expected but was: <-0.9 >"); assertMessageEndsWith(e1, "positive delta expected but was: <-0.9 >");
AssertionFailedError e2 = assertThrows(AssertionFailedError.class , () -> assertEquals(.0f, .0f, -10.5f)); AssertionFailedError e2 = assertThrows(AssertionFailedError.class , () -> assertEquals(.0f, .0f, -10.5f));
assertMessageEndsWith(e2, "positive delta expected but was: <-10. 5>"); assertMessageEndsWith(e2, "positive delta expected but was: <-10. 5>");
skipping to change at line 445 skipping to change at line 446
} }
@Test @Test
void assertEqualsDoubleWithDelta() { void assertEqualsDoubleWithDelta() {
assertEquals(0.0d, 0.0d, 0.1d); assertEquals(0.0d, 0.0d, 0.1d);
assertEquals(0.0d, 0.0d, 0.1d, "message"); assertEquals(0.0d, 0.0d, 0.1d, "message");
assertEquals(0.0d, 0.0d, 0.1d, () -> "message"); assertEquals(0.0d, 0.0d, 0.1d, () -> "message");
assertEquals(0.42d, 0.24d, 0.19d); assertEquals(0.42d, 0.24d, 0.19d);
assertEquals(0.02d, 0.011d, 0.01d); assertEquals(0.02d, 0.011d, 0.01d);
assertEquals(Double.NaN, Double.NaN, 0.2d); assertEquals(Double.NaN, Double.NaN, 0.2d);
assertEquals(0.001d, 0.001d, 0.0d);
} }
@Test @Test
void assertEqualsDoubleWithIllegalDelta() { void assertEqualsDoubleWithIllegalDelta() {
AssertionFailedError e1 = assertThrows(AssertionFailedError.class , () -> assertEquals(1.1d, 1.11d, -0.5d)); AssertionFailedError e1 = assertThrows(AssertionFailedError.class , () -> assertEquals(1.1d, 1.11d, -0.5d));
assertMessageEndsWith(e1, "positive delta expected but was: <-0.5 >"); assertMessageEndsWith(e1, "positive delta expected but was: <-0.5 >");
AssertionFailedError e2 = assertThrows(AssertionFailedError.class , () -> assertEquals(.55d, .56d, -10.5d)); AssertionFailedError e2 = assertThrows(AssertionFailedError.class , () -> assertEquals(.55d, .56d, -10.5d));
assertMessageEndsWith(e2, "positive delta expected but was: <-10. 5>"); assertMessageEndsWith(e2, "positive delta expected but was: <-10. 5>");
skipping to change at line 505 skipping to change at line 507
Executable assertion = () -> assertEquals(0.9d, 10.12d, 5.001d, ( ) -> "message"); Executable assertion = () -> assertEquals(0.9d, 10.12d, 5.001d, ( ) -> "message");
AssertionFailedError e = assertThrows(AssertionFailedError.class, assertion); AssertionFailedError e = assertThrows(AssertionFailedError.class, assertion);
assertMessageStartsWith(e, "message"); assertMessageStartsWith(e, "message");
assertMessageEndsWith(e, "expected: <0.9> but was: <10.12>"); assertMessageEndsWith(e, "expected: <0.9> but was: <10.12>");
assertExpectedAndActualValues(e, 0.9d, 10.12d); assertExpectedAndActualValues(e, 0.9d, 10.12d);
} }
@Test @Test
void assertEqualsWithTwoNulls() { void assertEqualsWithNullReferences() {
assertEquals(null, null); Object null1 = null;
Object null2 = null;
assertEquals(null1, null);
assertEquals(null, null2);
assertEquals(null1, null2);
} }
@Test @Test
void assertEqualsWithSameObject() { void assertEqualsWithSameObject() {
Object foo = new Object(); Object foo = new Object();
assertEquals(foo, foo); assertEquals(foo, foo);
assertEquals(foo, foo, "message"); assertEquals(foo, foo, "message");
assertEquals(foo, foo, () -> "message"); assertEquals(foo, foo, () -> "message");
} }
skipping to change at line 589 skipping to change at line 596
void assertEqualsWithUnequalObjectWhoseToStringImplementationThrowsAnExce ption() { void assertEqualsWithUnequalObjectWhoseToStringImplementationThrowsAnExce ption() {
try { try {
assertEquals(new ToStringThrowsException(), "foo"); assertEquals(new ToStringThrowsException(), "foo");
} }
catch (AssertionFailedError ex) { catch (AssertionFailedError ex) {
assertMessageStartsWith(ex, "expected: <" + ToStringThrow sException.class.getName() + "@"); assertMessageStartsWith(ex, "expected: <" + ToStringThrow sException.class.getName() + "@");
assertMessageEndsWith(ex, "but was: <foo>"); assertMessageEndsWith(ex, "but was: <foo>");
} }
} }
// ----------------------------------------------------------------------
---
@Nested
class MixedBoxedAndUnboxedPrimitivesTests {
@Test
void bytes() {
byte primitive = (byte) 42;
Byte wrapper = Byte.valueOf("42");
assertEquals(primitive, wrapper);
assertEquals(primitive, wrapper, "message");
assertEquals(primitive, wrapper, () -> "message");
assertEquals(wrapper, primitive);
assertEquals(wrapper, primitive, "message");
assertEquals(wrapper, primitive, () -> "message");
}
@Test
void shorts() {
short primitive = (short) 42;
Short wrapper = Short.valueOf("42");
assertEquals(primitive, wrapper);
assertEquals(primitive, wrapper, "message");
assertEquals(primitive, wrapper, () -> "message");
assertEquals(wrapper, primitive);
assertEquals(wrapper, primitive, "message");
assertEquals(wrapper, primitive, () -> "message");
}
@Test
void integers() {
int primitive = 42;
Integer wrapper = Integer.valueOf("42");
assertEquals(primitive, wrapper);
assertEquals(primitive, wrapper, "message");
assertEquals(primitive, wrapper, () -> "message");
assertEquals(wrapper, primitive);
assertEquals(wrapper, primitive, "message");
assertEquals(wrapper, primitive, () -> "message");
}
@Test
void longs() {
long primitive = 42L;
Long wrapper = Long.valueOf("42");
assertEquals(primitive, wrapper);
assertEquals(primitive, wrapper, "message");
assertEquals(primitive, wrapper, () -> "message");
assertEquals(wrapper, primitive);
assertEquals(wrapper, primitive, "message");
assertEquals(wrapper, primitive, () -> "message");
}
@Test
void floats() {
float primitive = 42.0f;
Float wrapper = Float.valueOf("42.0");
assertEquals(primitive, wrapper);
assertEquals(primitive, wrapper, 0.0f);
assertEquals(primitive, wrapper, "message");
assertEquals(primitive, wrapper, 0.0f, "message");
assertEquals(primitive, wrapper, () -> "message");
assertEquals(primitive, wrapper, 0.0f, () -> "message");
assertEquals(wrapper, primitive);
assertEquals(wrapper, primitive, 0.0f);
assertEquals(wrapper, primitive, "message");
assertEquals(wrapper, primitive, 0.0f, "message");
assertEquals(wrapper, primitive, () -> "message");
assertEquals(wrapper, primitive, 0.0f, () -> "message");
}
@Test
void doubles() {
double primitive = 42.0d;
Double wrapper = Double.valueOf("42.0");
assertEquals(primitive, wrapper);
assertEquals(primitive, wrapper, 0.0d);
assertEquals(primitive, wrapper, "message");
assertEquals(primitive, wrapper, 0.0d, "message");
assertEquals(primitive, wrapper, () -> "message");
assertEquals(primitive, wrapper, 0.0d, () -> "message");
assertEquals(wrapper, primitive);
assertEquals(wrapper, primitive, 0.0d);
assertEquals(wrapper, primitive, "message");
assertEquals(wrapper, primitive, 0.0d, "message");
assertEquals(wrapper, primitive, () -> "message");
assertEquals(wrapper, primitive, 0.0d, () -> "message");
}
@Test
void booleans() {
boolean primitive = true;
Boolean wrapper = Boolean.valueOf("true");
assertEquals(primitive, wrapper);
assertEquals(primitive, wrapper, "message");
assertEquals(primitive, wrapper, () -> "message");
assertEquals(wrapper, primitive);
assertEquals(wrapper, primitive, "message");
assertEquals(wrapper, primitive, () -> "message");
}
@Test
void chars() {
char primitive = 'a';
Character wrapper = Character.valueOf('a');
assertEquals(primitive, wrapper);
assertEquals(primitive, wrapper, "message");
assertEquals(primitive, wrapper, () -> "message");
assertEquals(wrapper, primitive);
assertEquals(wrapper, primitive, "message");
assertEquals(wrapper, primitive, () -> "message");
}
}
// ----------------------------------------------------------------------
---
private static class EqualsThrowsException { private static class EqualsThrowsException {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
throw new NumberFormatException(); throw new NumberFormatException();
} }
} }
private static class ToStringThrowsException { private static class ToStringThrowsException {
 End of changes. 5 change blocks. 
3 lines changed or deleted 145 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)