当前位置: 首页>>代码示例>>Java>>正文


Java AssertionFailedError类代码示例

本文整理汇总了Java中org.opentest4j.AssertionFailedError的典型用法代码示例。如果您正苦于以下问题:Java AssertionFailedError类的具体用法?Java AssertionFailedError怎么用?Java AssertionFailedError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AssertionFailedError类属于org.opentest4j包,在下文中一共展示了AssertionFailedError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的org.opentest4j.AssertionFailedError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。