本文整理汇总了Java中org.opentest4j.AssertionFailedError类的典型用法代码示例。如果您正苦于以下问题:Java AssertionFailedError类的具体用法?Java AssertionFailedError怎么用?Java AssertionFailedError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssertionFailedError类属于org.opentest4j包,在下文中一共展示了AssertionFailedError类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: assertSchema
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@TestFactory
public Stream<DynamicTest> assertSchema() {
List<TestCase> tests = new ArrayList<>();
of(tests, Schema.STRING_SCHEMA, Schema.STRING_SCHEMA, true);
of(tests, Schema.STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, false);
of(tests, Schema.BYTES_SCHEMA, Decimal.schema(4), false);
of(tests, null, null, true);
of(tests, Schema.STRING_SCHEMA, null, false);
of(tests, null, Schema.STRING_SCHEMA, false);
return tests.stream().map(testCase -> dynamicTest(testCase.toString(), () -> {
if (testCase.isEqual) {
AssertSchema.assertSchema(testCase.expected, testCase.actual);
} else {
assertThrows(AssertionFailedError.class, () -> {
AssertSchema.assertSchema(testCase.expected, testCase.actual);
});
}
}));
}
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:21,代码来源:AssertSchemaTest.java
示例2: afterTestExecution
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Override
public void afterTestExecution(ExtensionContext context) throws Exception {
switch (loadExceptionStatus(context)) {
case WAS_NOT_THROWN:
//@formatter:off
expectedException(context)
.map(expected -> new AssertionFailedError(format(EXPECTED_EXCEPTION_WAS_NOT_THROWN, expected)))
.ifPresent(error -> { throw error; });
//@formatter:on
case WAS_THROWN_AS_EXPECTED:
// the exception was thrown as expected so there is nothing to do
break;
case WAS_THROWN_NOT_AS_EXPECTED:
// an exception was thrown but of the wrong type;
// it was rethrown in `handleTestExecutionException`
// so there is nothing to do here
break;
}
}
开发者ID:junit-pioneer,项目名称:junit-pioneer,代码行数:20,代码来源:ExpectedExceptionExtension.java
示例3: wrongDelta
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
/**
* It may seem trivial, but they happen more often than you would assume.
*/
@Test
void wrongDelta() {
assertNotEquals(0.9, DummyUtil.calculateTimesThree(0.3)); // --> That's why the delta is important
// Using a 0.0 delta doesn't make much sense and JUnit 5 actively prevents it
AssertionFailedError ex = assertThrows(AssertionFailedError.class,
() -> assertEquals(20.9, DummyUtil.calculateTimesThree(19), 0.0));
LOG.info(ex.toString());
// org.opentest4j.AssertionFailedError: positive delta expected but was: <0.0>
// With such a high delta the correctness of the calculation is no longer assured
assertEquals(15.5, DummyUtil.calculateTimesThree(5.0), 0.5);
}
开发者ID:msg-DAVID-GmbH,项目名称:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito,代码行数:19,代码来源:JUnit_BestPractice.java
示例4: should_create_AssertionError_with_message_differentiating_expected_and_actual_persons
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Test
public void should_create_AssertionError_with_message_differentiating_expected_and_actual_persons() {
Person actual = new Person("Jake", 43);
Person expected = new Person("Jake", 47);
shouldBeEqual = (ShouldBeEqual) shouldBeEqual(actual, expected, new StandardRepresentation());
shouldBeEqual.descriptionFormatter = mock(DescriptionFormatter.class);
when(shouldBeEqual.descriptionFormatter.format(description)).thenReturn(formattedDescription);
AssertionError error = shouldBeEqual.newAssertionError(description, new StandardRepresentation());
assertThat(error).isInstanceOf(AssertionFailedError.class)
.hasMessage("[my test] %n" +
"Expecting:%n" +
" <\"Person[name=Jake] ([email protected]%s)\">%n" +
"to be equal to:%n" +
" <\"Person[name=Jake] ([email protected]%s)\">%n"
+ "but was not.", toHexString(actual.hashCode()), toHexString(expected.hashCode()));
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:19,代码来源:ShouldBeEqual_newAssertionError_differentiating_expected_and_actual_Test.java
示例5: Person
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Test
public void should_create_AssertionError_with_message_differentiating_expected_and_actual_persons_even_if_a_comparator_based_comparison_strategy_is_used() {
Person actual = new Person("Jake", 43);
Person expected = new Person("Jake", 47);
ComparisonStrategy ageComparisonStrategy = new ComparatorBasedComparisonStrategy(new PersonComparator());
shouldBeEqual = (ShouldBeEqual) shouldBeEqual(actual, expected, ageComparisonStrategy,
new StandardRepresentation());
shouldBeEqual.descriptionFormatter = mock(DescriptionFormatter.class);
when(shouldBeEqual.descriptionFormatter.format(description)).thenReturn(formattedDescription);
AssertionError error = shouldBeEqual.newAssertionError(description, new StandardRepresentation());
assertThat(error).isInstanceOf(AssertionFailedError.class)
.hasMessage("[my test] %n" +
"Expecting:%n" +
" <\"Person[name=Jake] ([email protected]%s)\">%n" +
"to be equal to:%n" +
" <\"Person[name=Jake] ([email protected]%s)\">%n" +
"when comparing values using PersonComparator%n" +
"but was not.", toHexString(actual.hashCode()), toHexString(expected.hashCode()));
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:22,代码来源:ShouldBeEqual_newAssertionError_differentiating_expected_and_actual_Test.java
示例6: should_create_AssertionError_with_message_differentiating_null_and_object_with_null_toString
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Test
public void should_create_AssertionError_with_message_differentiating_null_and_object_with_null_toString() {
Object actual = null;
Object expected = new ToStringIsNull();
shouldBeEqual = (ShouldBeEqual) shouldBeEqual(actual, expected, new StandardRepresentation());
shouldBeEqual.descriptionFormatter = mock(DescriptionFormatter.class);
when(shouldBeEqual.descriptionFormatter.format(description)).thenReturn(formattedDescription);
AssertionError error = shouldBeEqual.newAssertionError(description, new StandardRepresentation());
assertThat(error).isInstanceOf(AssertionFailedError.class)
.hasMessage("[my test] %n" +
"Expecting:%n" +
" <null>%n" +
"to be equal to:%n" +
" <\"null ([email protected]%s)\">%n" +
"but was not.", toHexString(expected.hashCode()));
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:19,代码来源:ShouldBeEqual_newAssertionError_differentiating_expected_and_actual_Test.java
示例7: should_create_AssertionError_with_message_differentiating_object_with_null_toString_and_null
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Test
public void should_create_AssertionError_with_message_differentiating_object_with_null_toString_and_null() {
Object actual = new ToStringIsNull();
Object expected = null;
shouldBeEqual = (ShouldBeEqual) shouldBeEqual(actual, expected, new StandardRepresentation());
shouldBeEqual.descriptionFormatter = mock(DescriptionFormatter.class);
when(shouldBeEqual.descriptionFormatter.format(description)).thenReturn(formattedDescription);
AssertionError error = shouldBeEqual.newAssertionError(description, new StandardRepresentation());
assertThat(error).isInstanceOf(AssertionFailedError.class)
.hasMessage("[my test] %n" +
"Expecting:%n" +
" <\"null ([email protected]%s)\">%n" +
"to be equal to:%n" +
" <null>%n" +
"but was not.", toHexString(actual.hashCode()));
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:19,代码来源:ShouldBeEqual_newAssertionError_differentiating_expected_and_actual_Test.java
示例8: notTheSame
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Override
public void notTheSame(byte[] oldValue, File fileForVerification, byte[] newValue, File fileForApproval) {
if (oldValue.length == newValue.length) {
double error = calculateError(oldValue, newValue);
if (error < MAX_DEVIATION) {
throw new TestAbortedException(String
.format("Approval failed with less than %s %% difference, skipping test", MAX_DEVIATION * 100));
}
}
approvalScriptWriter.addMoveCommand(fileForApproval, fileForVerification);
throw new AssertionFailedError("Approval failed, please check console output.\n", asString(oldValue),
asString(newValue));
}
开发者ID:maxbechtold,项目名称:golden-master,代码行数:15,代码来源:JUnitReporter.java
示例9: test
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
void test(Struct expected, Struct actual, boolean matches) {
if (matches) {
AssertStruct.assertStruct(expected, actual);
} else {
assertThrows(AssertionFailedError.class, () -> {
AssertStruct.assertStruct(expected, actual);
});
}
}
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:10,代码来源:AssertStructTest.java
示例10: assertTrueNotNullTest
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
/**
* Don't check for nulls with {@link Assertions#assertTrue}. Error messages will be meaningless and therefore useless.
* Do use {@link Assertions#assertNotNull} or {@link Assertions#assertNull} instead.
*/
@Test
void assertTrueNotNullTest() {
// Unclear, useless error-message when tests fail
AssertionFailedError ex = assertThrows(AssertionFailedError.class,
() -> assertTrue(dummyFruits.get(4) != null));
LOG.info(ex.toString());
// org.opentest4j.AssertionFailedError // It couldn't be more useless...
}
开发者ID:msg-DAVID-GmbH,项目名称:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito,代码行数:14,代码来源:JUnit_BestPractice.java
示例11: assertNotNullTest
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Test
void assertNotNullTest() {
// Better error-message you can actually use and understand
AssertionFailedError ex = assertThrows(AssertionFailedError.class,
() -> assertNotNull(dummyFruits.get(4)));
LOG.info(ex.toString());
// org.opentest4j.AssertionFailedError: expected: not <null>
}
开发者ID:msg-DAVID-GmbH,项目名称:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito,代码行数:10,代码来源:JUnit_BestPractice.java
示例12: assertTrueEqualsTest
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
/**
* The same applies for using {@link Assertions#assertTrue} and {@link Object#equals}. Use {@link Assertions#assertEquals} instead.
*/
@Test
void assertTrueEqualsTest() {
// Unclear, useless error-message when tests fail
AssertionFailedError ex = assertThrows(AssertionFailedError.class,
() -> assertTrue(TYPE.BANANA.equals(dummyFruits.get(2).getType())));
LOG.info(ex.toString());
// org.opentest4j.AssertionFailedError: // It - again - couldn't be more useless...
}
开发者ID:msg-DAVID-GmbH,项目名称:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito,代码行数:13,代码来源:JUnit_BestPractice.java
示例13: assertEqualsTest
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Test
void assertEqualsTest() {
// Really useful error-message you can actually use and understand
AssertionFailedError ex = assertThrows(AssertionFailedError.class,
() ->
assertEquals(TYPE.BANANA, dummyFruits.get(2).getType()));
LOG.info(ex.toString());
// org.opentest4j.AssertionFailedError: expected: <BANANA> but was: <APPLE>
}
开发者ID:msg-DAVID-GmbH,项目名称:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito,代码行数:11,代码来源:JUnit_BestPractice.java
示例14: wrongParameterOrder
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Test
void wrongParameterOrder() {
//Gives you unclear, actually wrong fail-reports!
AssertionFailedError ex = assertThrows(AssertionFailedError.class,
() -> assertEquals(dummyFruits.get(2).getName(), "Grapefruit"));
// . . . . . . . . . . . . . . ^expected . . . . . . . . . . . ^actual
LOG.info(ex.toString());
// org.opentest4j.AssertionFailedError: expected: <Granny Smith Apple> but was: <Grapefruit>
// So wait, the constant String I put in there is not an expected value? Tell me more about that!
// Or don't... Just fix the order and everything will be fine ;)
}
开发者ID:msg-DAVID-GmbH,项目名称:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito,代码行数:14,代码来源:JUnit_BestPractice.java
示例15: correctParameterOrder
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Test
void correctParameterOrder() {
// Clear and useful fail-report ;)
AssertionFailedError ex = assertThrows(AssertionFailedError.class,
() -> assertEquals("Grapefruit", dummyFruits.get(2).getName()));
// . . . . . . . . . . . . . . ^expected . . . . . . ^actual
LOG.info(ex.toString());
// org.opentest4j.AssertionFailedError: expected: <Grapefruit> but was: <Granny Smith Apple>
// "Oh... my actual value is not what was expected? Well now I know what the problem is and I can fix it!"
}
开发者ID:msg-DAVID-GmbH,项目名称:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito,代码行数:13,代码来源:JUnit_BestPractice.java
示例16: assertNotThrows
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
/**
* Asserts that execution of the supplied executable does not throw an exception.
*
* <p>
* If an exception is thrown, this method will fail.
* </p>
*/
public static void assertNotThrows(final Executable executable) {
checkNotNull(executable);
try {
executable.execute();
} catch (final Throwable t) {
throw new AssertionFailedError(
String.format("Expected no exception to be thrown, but %s was thrown", getCanonicalName(t.getClass())));
}
}
开发者ID:triplea-game,项目名称:triplea,代码行数:18,代码来源:Assertions.java
示例17: initialSeedIsReportedWhenTestFails
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
@Test
void initialSeedIsReportedWhenTestFails() throws InitializationError {
final TestRunReport report = runnerFor(FailingTest.class).run();
assertThat(report.detailsFor(FailingTest.class, "noSeedAnnotation").failure().getException())
.isInstanceOf(FailedWithSeed.class)
.hasMessage("Test failed with seed " + initialSeed)
.hasCause(new AssertionFailedError("uh oh"));
assertThat(report.detailsFor(FailingTest.class, "withSeedAnnotation").failure().getException())
.isInstanceOf(FailedWithSeed.class)
.hasMessage("Test failed with seed 1");
}
开发者ID:fyodor-org-uk,项目名称:fyodor,代码行数:14,代码来源:SeedTest.java
示例18: check
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
private void check(AssertionError error) throws Exception {
verify(constructorInvoker).newInstance(ComparisonFailure.class.getName(),
new Class<?>[] { String.class, String.class, String.class },
"[Jedi]", "\"Yoda\"", "\"Luke\"");
verify(constructorInvoker).newInstance(AssertionFailedError.class.getName(),
new Class<?>[] { String.class, Object.class, Object.class },
String.format("[Jedi] %nExpecting:%n <\"Luke\">%nto be equal to:%n <\"Yoda\">%nbut was not."),
"Yoda", "Luke");
assertThat(error).isNotInstanceOf(ComparisonFailure.class)
.isInstanceOf(AssertionFailedError.class);
AssertionFailedError assertionFailedError = (AssertionFailedError) error;
assertThat(assertionFailedError.getActual().getValue()).isEqualTo("Luke");
assertThat(assertionFailedError.getExpected().getValue()).isEqualTo("Yoda");
assertThat(error.getMessage()).isEqualTo(String.format("[Jedi] %nExpecting:%n <\"Luke\">%nto be equal to:%n <\"Yoda\">%nbut was not."));
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:16,代码来源:ShouldBeEqual_newAssertionError_without_JUnit_Test.java
示例19: check
import org.opentest4j.AssertionFailedError; //导入依赖的package包/类
private void check(AssertionError error) throws Exception {
verify(constructorInvoker).newInstance(ComparisonFailure.class.getName(),
new Class<?>[] { String.class, String.class, String.class },
"[Jedi]", "\"Yoda\"", "\"Luke\"");
verify(constructorInvoker).newInstance(AssertionFailedError.class.getName(),
new Class<?>[] { String.class, Object.class, Object.class },
String.format("[Jedi] %nExpecting:%n <\"Luke\">%nto be equal to:%n <\"Yoda\">%nbut was not."),
"Yoda", "Luke");
assertThat(error).isNotInstanceOf(ComparisonFailure.class);
assertThat(error).isNotInstanceOf(AssertionFailedError.class);
assertThat(error.getMessage()).isEqualTo(String.format("[Jedi] %nExpecting:%n <\"Luke\">%nto be equal to:%n <\"Yoda\">%nbut was not."));
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:13,代码来源:ShouldBeEqual_newAssertionError_without_JUnit_and_OTA4J_Test.java
注:本文中的org.opentest4j.AssertionFailedError类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论