From f7938848ed9c88c6dd590a3d79388774c37fe797 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Mon, 18 Feb 2019 16:24:46 +0100 Subject: [PATCH] #232: fixes NPE when verifying interfaces --- CHANGELOG.md | 1 + .../equalsverifier/EqualsVerifierApi.java | 2 +- .../extended_contract/InterfaceTest.java | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/test/java/nl/jqno/equalsverifier/integration/extended_contract/InterfaceTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 67fc3c0b8..92292d8b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed +- Verifying interfaces directly causes NullPointerException. ([Issue 232](/~https://github.com/jqno/equalsverifier/issues/232)) - Improved error messages regarding JPA's `@EmbeddedId` annotation. ([Issue 231](/~https://github.com/jqno/equalsverifier/issues/231)) diff --git a/src/main/java/nl/jqno/equalsverifier/EqualsVerifierApi.java b/src/main/java/nl/jqno/equalsverifier/EqualsVerifierApi.java index ab714b22e..adff84fbe 100644 --- a/src/main/java/nl/jqno/equalsverifier/EqualsVerifierApi.java +++ b/src/main/java/nl/jqno/equalsverifier/EqualsVerifierApi.java @@ -339,7 +339,7 @@ private String buildErrorMessage(String description) { } private void performVerification() { - if (type.isEnum()) { + if (type.isEnum() || type.isInterface()) { return; } diff --git a/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/InterfaceTest.java b/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/InterfaceTest.java new file mode 100644 index 000000000..22722d59d --- /dev/null +++ b/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/InterfaceTest.java @@ -0,0 +1,20 @@ +package nl.jqno.equalsverifier.integration.extended_contract; + +import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.Test; + +public class InterfaceTest { + @Test + public void succeed_whenClassIsAnInterface() { + EqualsVerifier.forClass(CharSequence.class) + .verify(); + } + + @Test + public void succeed_whenClassIsAnEmptyInterface() { + EqualsVerifier.forClass(Interface.class) + .verify(); + } + + interface Interface {} +}