[OSD600] Contributing to assertj-core

Issue

The issue is to create a new feature — a shortcut for an extracting(Throwable::getMessage, as(InstanceOfAssertFactories.STRING)) . Basically, a user wants to verify the actual message’s exception matches with the expected one. Instead of writing such a long line of codes, I can achieve the similar things by using message()

assertThatThrownBy(() -> {
/* code to test */
})
.isInstanceOf(CertPathValidatorException.class)
.extracting(Throwable::getMessage, as(InstanceOfAssertFactories.STRING))
.containsAnyOf(
"could not be determined",
"could not determine revocation status",
"revocation status check failed"
);
assertThatThrownBy(() -> {
/* code to test */
})
.isInstanceOf(CertPathValidatorException.class)
.message()
.containsAnyOf(
"could not be determined",
"could not determine revocation status",
"revocation status check failed"
);

My problems

assertj-core has a very large code base with multiple classes that closely inherited each other and they use generics. It took me a couple of hours to read and understand the codes

My solutions

To understand the logic behind these lines of codes:

assertThatThrownBy(() -> {
/* code to test */
})
.isInstanceOf(CertPathValidatorException.class)
.extracting(Throwable::getMessage, as(InstanceOfAssertFactories.STRING))
.containsAnyOf(
"could not be determined",
"could not determine revocation status",
"revocation status check failed"
);
  • What’s the purpose of this function
  • Which class does it belong to
  • What’s it returned data type
public AbstractStringAssert<?> message() {
return new AbstractStringAssert(((Throwable) actual).getMessage(), AbstractStringAssert.class);
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Trang Nguyen

Trang Nguyen

39 Followers

Computer Programming Student @Seneca. Writing to share solutions and encourage my sister to write.