use of org.opentest4j.AssertionFailedError in project assertj-core by assertj.
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"));
}
use of org.opentest4j.AssertionFailedError in project open-smart-grid-platform by OSGP.
the class GetDataSteps method assertSystemResponse.
private void assertSystemResponse(final Map<String, String> responseParameters, final List<GetDataSystemIdentifier> systemIdentifiers, final int systemIndex) {
final int numberOfSystems = systemIdentifiers.size();
final String indexPostfix = "_" + (systemIndex + 1);
final String systemDescription = "System[" + (systemIndex + 1) + "/" + numberOfSystems + "]";
final GetDataSystemIdentifier systemIdentifier = systemIdentifiers.get(systemIndex);
if (responseParameters.containsKey(PlatformKeys.KEY_SYSTEM_TYPE.concat(indexPostfix))) {
final String expectedType = responseParameters.get(PlatformKeys.KEY_SYSTEM_TYPE.concat(indexPostfix));
try {
assertThat(systemIdentifier.getType()).as(systemDescription + " type").isEqualTo(expectedType);
} catch (final AssertionFailedError e) {
// Work around for OSGP's restore connection scheduled task. If
// the type is not as expected it can be equal to RTU.
assertThat(systemIdentifier.getType()).as(systemDescription + " type").isEqualTo("RTU");
}
}
if (responseParameters.containsKey(PlatformKeys.KEY_NUMBER_OF_MEASUREMENTS.concat(indexPostfix))) {
this.assertMeasurements(responseParameters, systemIdentifier.getMeasurement(), numberOfSystems, systemIndex, systemDescription, indexPostfix);
}
if (responseParameters.containsKey(PlatformKeys.KEY_NUMBER_OF_PROFILES.concat(indexPostfix))) {
this.assertProfiles(responseParameters, systemIdentifier.getProfile(), numberOfSystems, systemIndex, systemDescription, indexPostfix);
}
}
use of org.opentest4j.AssertionFailedError in project JSqlParser by JSQLParser.
the class SpecialOracleTest method testAllSqlsParseDeparse.
@Test
public void testAllSqlsParseDeparse() throws IOException {
int count = 0;
int success = 0;
File[] sqlTestFiles = SQLS_DIR.listFiles();
boolean foundUnexpectedFailures = false;
for (File file : sqlTestFiles) {
if (file.isFile()) {
count++;
String sql = FileUtils.readFileToString(file, Charset.forName("UTF-8"));
try {
assertSqlCanBeParsedAndDeparsed(sql, true);
success++;
recordSuccessOnSourceFile(file);
} catch (JSQLParserException ex) {
String message = ex.getMessage();
// strip the Exception Class Name from the Message
if (message.startsWith(net.sf.jsqlparser.parser.ParseException.class.getCanonicalName())) {
message = message.substring(net.sf.jsqlparser.parser.ParseException.class.getCanonicalName().length() + 2);
}
int pos = message.indexOf('\n');
if (pos > 0) {
message = message.substring(0, pos);
}
if (sql.contains("@SUCCESSFULLY_PARSED_AND_DEPARSED") || EXPECTED_SUCCESSES.contains(file.getName())) {
LOG.log(Level.SEVERE, "UNEXPECTED PARSING FAILURE: {0}\n\t" + message, file.getName());
foundUnexpectedFailures = true;
} else {
LOG.log(Level.FINE, "EXPECTED PARSING FAILURE: {0}", file.getName());
}
recordFailureOnSourceFile(file, message);
} catch (Exception ex) {
LOG.log(Level.SEVERE, "UNEXPECTED EXCEPTION: {0}\n\t" + ex.getMessage(), file.getName());
foundUnexpectedFailures = true;
} catch (AssertionFailedError ex) {
if (sql.contains("@SUCCESSFULLY_PARSED_AND_DEPARSED") || EXPECTED_SUCCESSES.contains(file.getName())) {
LOG.log(Level.SEVERE, "UNEXPECTED DE-PARSING FAILURE: {0}\n" + ex.toString(), file.getName());
foundUnexpectedFailures = true;
} else {
LOG.log(Level.FINE, "EXPECTED DE-PARSING FAILURE: {0}", file.getName());
}
recordFailureOnSourceFile(file, ex.getActual().getStringRepresentation());
}
}
}
LOG.log(Level.INFO, "tested {0} files. got {1} correct parse results, expected {2}", new Object[] { count, success, EXPECTED_SUCCESSES.size() });
assertTrue(success >= EXPECTED_SUCCESSES.size());
assertFalse(foundUnexpectedFailures, "Found Testcases failing unexpectedly.");
}
use of org.opentest4j.AssertionFailedError in project osgi-test by osgi.
the class AssertTest method assertEqualityAssertion.
/**
* Routine containing boilerplate code for checking correct assertion
* behavior. This function calls {@link #assertPassing assertPassing()} and
* {@link #assertFailing assertFailing()}. It also asserts that the failure
* message matches the general pattern "expected <%s>, but was <%s>". It
* returns the {@link AbstractThrowableAssert} instance so that you can
* perform further assertions on the exception.
*
* @param <T> the type of the arguments accepted by the assertion method
* under test.
* @param softly the {@code SoftAssertions} object passed in to the original
* test message.
* @param assertion reference to the assertion method of the {@link #aut()}
* @param actual the value that the method under test will actually return.
* @param failing an argument to pass to the assertion method that should
* fail.
* @return The {@code AbstractThrowableAssert} instance used for chaining
* further assertions.
*/
default <T> AbstractThrowableAssert<?, ?> assertEqualityAssertion(String msg, String field, Function<T, SELF> assertion, T actual, T failing) {
assertPassing(msg, assertion, actual);
AbstractThrowableAssert<?, ?> retval = assertFailing(msg, assertion, failing).hasMessageMatching("(?si).*expecting.*" + field + ".*" + failing + ".*but.*was.*" + actual + ".*").isInstanceOf(AssertionFailedError.class);
try {
Field f = AbstractAssert.class.getDeclaredField("actual");
f.setAccessible(true);
Object a = f.get(retval);
if (!(a instanceof AssertionFailedError)) {
return retval;
}
AssertionFailedError afe = (AssertionFailedError) a;
softly().assertThat(afe.getActual().getStringRepresentation()).as("actual").isEqualTo(String.valueOf(actual));
softly().assertThat(afe.getExpected().getStringRepresentation()).as("expected").isEqualTo(String.valueOf(failing));
} catch (Exception e) {
throw Exceptions.duck(e);
}
return retval;
}
use of org.opentest4j.AssertionFailedError in project blackduck-alert by blackducksoftware.
the class SettingsProxyControllerTestIT method testUpdate.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
void testUpdate() throws Exception {
createDefaultSettingsProxyModel().orElseThrow(AssertionFailedError::new);
SettingsProxyModel newSettingsProxyModel = new SettingsProxyModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, "newHostname", 678);
String url = AlertRestConstants.SETTINGS_PROXY_PATH;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(newSettingsProxyModel)).contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
Aggregations