Search in sources :

Example 71 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project blackduck-alert by blackducksoftware.

the class SettingsProxyControllerTestIT method testDelete.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
void testDelete() throws Exception {
    createDefaultSettingsProxyModel().orElseThrow(AssertionFailedError::new);
    String url = AlertRestConstants.SETTINGS_PROXY_PATH;
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.delete(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AssertionFailedError(org.opentest4j.AssertionFailedError) URI(java.net.URI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 72 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project intellij-community by JetBrains.

the class JUnit5TestExecutionListener method testFailure.

private void testFailure(String methodName, String id, String messageName, Throwable ex, long duration, String reason, boolean includeThrowable) {
    final Map<String, String> attrs = new LinkedHashMap<>();
    attrs.put("name", methodName);
    attrs.put("id", id);
    if (duration > 0) {
        attrs.put("duration", Long.toString(duration));
    }
    if (reason != null) {
        attrs.put("message", reason);
    }
    try {
        if (ex != null) {
            ComparisonFailureData failureData = null;
            if (ex instanceof MultipleFailuresError && ((MultipleFailuresError) ex).hasFailures()) {
                for (AssertionError assertionError : ((MultipleFailuresError) ex).getFailures()) {
                    testFailure(methodName, id, messageName, assertionError, duration, reason, false);
                }
            } else if (ex instanceof AssertionFailedError && ((AssertionFailedError) ex).isActualDefined() && ((AssertionFailedError) ex).isExpectedDefined()) {
                final ValueWrapper actual = ((AssertionFailedError) ex).getActual();
                final ValueWrapper expected = ((AssertionFailedError) ex).getExpected();
                failureData = new ComparisonFailureData(expected.getStringRepresentation(), actual.getStringRepresentation());
            } else {
                //try to detect failure with junit 4 if present in the classpath
                try {
                    failureData = ExpectedPatterns.createExceptionNotification(ex);
                } catch (Throwable ignore) {
                }
            }
            if (includeThrowable || failureData == null) {
                ComparisonFailureData.registerSMAttributes(failureData, getTrace(ex), ex.getMessage(), attrs, ex, "Comparison Failure: ", "expected: <");
            } else {
                ComparisonFailureData.registerSMAttributes(failureData, "", "", attrs, ex, "", "expected: <");
            }
        }
    } finally {
        myPrintStream.println("\n" + MapSerializerUtil.asString(messageName, attrs));
    }
}
Also used : ValueWrapper(org.opentest4j.ValueWrapper) ComparisonFailureData(com.intellij.rt.execution.junit.ComparisonFailureData) AssertionFailedError(org.opentest4j.AssertionFailedError) LinkedHashMap(java.util.LinkedHashMap) MultipleFailuresError(org.opentest4j.MultipleFailuresError)

Example 73 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project intellij-community by JetBrains.

the class JUnit5EventsTest method multipleFailures.

@Test
void multipleFailures() throws Exception {
    TestDescriptor testDescriptor = new MethodTestDescriptor(UniqueId.forEngine("engine"), TestClass.class, TestClass.class.getDeclaredMethod("test1"));
    TestIdentifier identifier = TestIdentifier.from(testDescriptor);
    myExecutionListener.executionStarted(identifier);
    MultipleFailuresError multipleFailuresError = new MultipleFailuresError("2 errors");
    multipleFailuresError.addFailure(new AssertionFailedError("message1", "expected1", "actual1"));
    multipleFailuresError.addFailure(new AssertionFailedError("message2", "expected2", "actual2"));
    myExecutionListener.executionFinished(identifier, TestExecutionResult.failed(multipleFailuresError));
    Assertions.assertEquals("##teamcity[enteredTheMatrix]\n" + "\n" + "##teamcity[testStarted id='|[engine:engine|]' name='test1()' locationHint='java:test://com.intellij.junit5.JUnit5EventsTest$TestClass.test1']\n" + "\n" + "##teamcity[testFailed name='test1()' id='|[engine:engine|]' details='' message='' expected='expected1' actual='actual1']\n" + "\n" + "##teamcity[testFailed name='test1()' id='|[engine:engine|]' details='' message='' expected='expected2' actual='actual2']\n" + "\n" + "##teamcity[testFailed name='test1()' id='|[engine:engine|]' details='TRACE' message='2 errors (2 failures)|n\tmessage1|n\tmessage2']\n" + "\n" + "##teamcity[testFinished id='|[engine:engine|]' name='test1()']\n", StringUtil.convertLineSeparators(myBuf.toString()));
}
Also used : MethodTestDescriptor(org.junit.jupiter.engine.descriptor.MethodTestDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) AssertionFailedError(org.opentest4j.AssertionFailedError) MethodTestDescriptor(org.junit.jupiter.engine.descriptor.MethodTestDescriptor) TestFactoryTestDescriptor(org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) MultipleFailuresError(org.opentest4j.MultipleFailuresError)

Example 74 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project assertj-core by joel-costigliola.

the class ShouldBeEqual_Test method should_display_comparison_strategy_in_error_message.

@Test
void should_display_comparison_strategy_in_error_message() {
    // GIVEN
    String actual = "Luke";
    String expected = "Yoda";
    ThrowingCallable code = () -> then(actual).as("Jedi").usingComparator(CaseInsensitiveStringComparator.instance).isEqualTo(expected);
    // WHEN
    AssertionFailedError error = catchThrowableOfType(code, AssertionFailedError.class);
    // THEN
    then(error.getActual().getValue()).isEqualTo(STANDARD_REPRESENTATION.toStringOf(actual));
    then(error.getExpected().getValue()).isEqualTo(STANDARD_REPRESENTATION.toStringOf(expected));
    then(error).hasMessage(format("[Jedi] %n" + "expected: \"Yoda\"%n" + " but was: \"Luke\"%n" + "when comparing values using CaseInsensitiveStringComparator"));
}
Also used : ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.jupiter.api.Test)

Example 75 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project assertj-core by joel-costigliola.

the class OptionalAssert_contains_Test method should_fail_if_optional_does_not_contain_expected_value.

@Test
void should_fail_if_optional_does_not_contain_expected_value() {
    // GIVEN
    Optional<String> actual = Optional.of("not-expected");
    String expectedValue = "something";
    // WHEN
    AssertionFailedError error = catchThrowableOfType(() -> assertThat(actual).contains(expectedValue), AssertionFailedError.class);
    // THEN
    assertThat(error).hasMessage(shouldContain(actual, expectedValue).create());
    assertThat(error.getActual().getStringRepresentation()).isEqualTo(actual.get());
    assertThat(error.getExpected().getStringRepresentation()).isEqualTo(expectedValue);
}
Also used : AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.jupiter.api.Test)

Aggregations

AssertionFailedError (org.opentest4j.AssertionFailedError)153 Test (org.junit.jupiter.api.Test)72 AssertionTestUtils.expectAssertionFailedError (org.junit.jupiter.api.AssertionTestUtils.expectAssertionFailedError)12 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)8 IOException (java.io.IOException)8 URI (java.net.URI)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)8 Collectors (java.util.stream.Collectors)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 ThrowingCallable (org.assertj.core.api.ThrowableAssert.ThrowingCallable)4 GeneCentricEntry (org.uniprot.core.genecentric.GeneCentricEntry)4 GeneCentricDocument (org.uniprot.store.search.document.genecentric.GeneCentricDocument)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)3 Search (io.zulia.client.command.builder.Search)3 SearchResult (io.zulia.client.result.SearchResult)3 ExecutionException (java.util.concurrent.ExecutionException)3 Assertions (org.junit.jupiter.api.Assertions)3