Search in sources :

Example 56 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project junit5 by junit-team.

the class AssertEqualsAssertionsTests method assertEqualsFloatWithDeltaWithUnequalValuesAndMessage.

@Test
void assertEqualsFloatWithDeltaWithUnequalValuesAndMessage() {
    Executable assertion = () -> assertEquals(0.5f, 0.45f, 0.03f, "message");
    AssertionFailedError e = assertThrows(AssertionFailedError.class, assertion);
    assertMessageStartsWith(e, "message");
    assertMessageEndsWith(e, "expected: <0.5> but was: <0.45>");
    assertExpectedAndActualValues(e, 0.5f, 0.45f);
}
Also used : Executable(org.junit.jupiter.api.function.Executable) AssertionFailedError(org.opentest4j.AssertionFailedError) AssertionTestUtils.expectAssertionFailedError(org.junit.jupiter.api.AssertionTestUtils.expectAssertionFailedError)

Example 57 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project junit5 by junit-team.

the class AssertEqualsAssertionsTests method assertEqualsFloatWithDeltaWithUnequalValuesAndMessageSupplier.

@Test
void assertEqualsFloatWithDeltaWithUnequalValuesAndMessageSupplier() {
    Executable assertion = () -> assertEquals(0.5f, 0.45f, 0.03f, () -> "message");
    AssertionFailedError e = assertThrows(AssertionFailedError.class, assertion);
    assertMessageStartsWith(e, "message");
    assertMessageEndsWith(e, "expected: <0.5> but was: <0.45>");
    assertExpectedAndActualValues(e, 0.5f, 0.45f);
}
Also used : Executable(org.junit.jupiter.api.function.Executable) AssertionFailedError(org.opentest4j.AssertionFailedError) AssertionTestUtils.expectAssertionFailedError(org.junit.jupiter.api.AssertionTestUtils.expectAssertionFailedError)

Example 58 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project aws-mysql-jdbc by awslabs.

the class MetaDataRegressionTest method testBug20491.

@Test
public void testBug20491() throws Exception {
    this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE '%char%'");
    while (this.rs.next()) {
        System.out.println(this.rs.getString(1) + " = " + this.rs.getString(2));
    }
    this.rs.close();
    String[] fields = { "field1_ae_\u00e4", "field2_ue_\u00fc", "field3_oe_\u00f6", "field4_sz_\u00df" };
    createTable("tst", "(`" + fields[0] + "` int(10) unsigned NOT NULL default '0', `" + fields[1] + "` varchar(45) default '', `" + fields[2] + "` varchar(45) default '', `" + fields[3] + "` varchar(45) default '', PRIMARY KEY  (`" + fields[0] + "`))");
    for (int i = 0; i < fields.length; i++) {
        try {
            assertEquals(fields[i], new String(fields[i].getBytes("Cp1252"), "Cp1252"));
        } catch (AssertionFailedError afEr) {
            if (i == 3) {
                if (!Constants.OS_NAME.startsWith("Mac")) {
                    throw afEr;
                }
            }
        }
    }
    @SuppressWarnings("unused") byte[] asBytes = fields[0].getBytes("utf-8");
    DatabaseMetaData md = this.conn.getMetaData();
    this.rs = md.getColumns(this.dbName, "%", "tst", "%");
    int j = 0;
    while (this.rs.next()) {
        try {
            assertEquals(fields[j++], this.rs.getString(4), "Wrong column name:" + this.rs.getString(4));
        } catch (AssertionFailedError afEr) {
            if (j == 3) {
                if (!Constants.OS_NAME.startsWith("Mac")) {
                    throw afEr;
                }
            }
        }
    }
    this.rs.close();
    this.rs = this.stmt.executeQuery("SELECT * FROM tst");
    ResultSetMetaData rsmd = this.rs.getMetaData();
    for (int i = 1; i <= rsmd.getColumnCount(); i++) {
        try {
            assertEquals(fields[i - 1], rsmd.getColumnName(i), "Wrong column name:" + rsmd.getColumnName(i));
        } catch (AssertionFailedError afEr) {
            if (i - 1 == 3) {
                if (!Constants.OS_NAME.startsWith("Mac")) {
                    throw afEr;
                }
            }
        }
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) AssertionFailedError(org.opentest4j.AssertionFailedError) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.jupiter.api.Test)

Example 59 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project sonar-java by SonarSource.

the class RegexParserTestUtils method assertSuccessfulParse.

public static RegexTree assertSuccessfulParse(String regex) {
    RegexSource source = makeSource(regex);
    RegexParseResult result = new RegexParser(source, new FlagSet()).parse();
    if (!result.getSyntaxErrors().isEmpty()) {
        throw new AssertionFailedError("Parsing should complete with no errors.", "no errors", result.getSyntaxErrors());
    }
    return result.getResult();
}
Also used : RegexParser(org.sonarsource.analyzer.commons.regex.RegexParser) FlagSet(org.sonarsource.analyzer.commons.regex.ast.FlagSet) RegexParseResult(org.sonarsource.analyzer.commons.regex.RegexParseResult) RegexSource(org.sonarsource.analyzer.commons.regex.RegexSource) AssertionFailedError(org.opentest4j.AssertionFailedError)

Example 60 with AssertionFailedError

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

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