I have created a DTO class for EmailAddress
as follows and I'm trying to write a basic unit-test for it
EmailAddress.java
package com.company.service.interfaces.types.contacts;
import org.apache.commons.lang3.Validate;
import org.immutables.value.Value;
/**
* Type for wrapping a valid email addresslayer
*/
@Value.Immutable(builder = false)
public abstract class EmailAddress {
@Value.Parameter
public abstract String value();
@Value.Check
void validate() {
Validate.notBlank(value(), "'emailAddress' cannot be blank"); // i want to unit-test this
}
}
EmailAddressTest.java
package com.company.service.interfaces.types.contacts;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class EmailAddressTest {
@Test
public void testBuilder_nullInput() {
assertThatThrownBy(() -> ImmutableEmailAddress.of(null)) // spot-bugs is failing on this line
.isExactlyInstanceOf(NullPointerException.class);
}
}
The above test-case is failing in SpotBugs report with RV_RETURN_VALUE_IGNORED
error as follows
Bug type RV_RETURN_VALUE_IGNORED (click for details)
In class com.company.service.interfaces.types.contacts.EmailAddressTest
In method com.company.service.interfaces.types.contacts.EmailAddressTest.lambda$testBuilder_nullInput$0()
Called method com.company.service.interfaces.types.contacts.ImmutableEmailAddress.of(String)
At EmailAddressTest.java:[line 11]
As I understand the suppression annotations such as @CheckReturnValue
and @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
only work on methods with bodies and not on lambdas.
How can I work around this?