Skip to content

Commit

Permalink
Adds prefab values for various Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Jun 23, 2023
1 parent 2a82952 commit 8d08234
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Adds prefab values for `Throwable`, `Exception` and `RuntimeException`. ([Issue 831](https://github.com/jqno/equalsverifier/issues/831))

## [3.14.2] - 2023-05-31

- Adds prefab values for `DoubleAdder`, `DoubleAccumulator`, `LongAdder` and `LongAccumulator`.
- Adds prefab values for `DoubleAdder`, `DoubleAccumulator`, `LongAdder` and `LongAccumulator`. ([Issue 817](https://github.com/jqno/equalsverifier/issues/817))

## [3.14.1] - 2023-03-16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private void addJavaClasses() {
addSets();
addQueues();
addNioBuffers();
addExceptions();
addReflectionClasses();
addAtomicClasses();
addAncientJavaApiClasses();
Expand Down Expand Up @@ -513,6 +514,25 @@ private void addNioBuffers() {
);
}

private void addExceptions() {
Throwable redThrowable = new Throwable();
Throwable blueThrowable = new Throwable();
addValues(Throwable.class, redThrowable, blueThrowable, redThrowable);

Exception redException = new Exception();
Exception blueException = new Exception();
addValues(Exception.class, redException, blueException, redException);

RuntimeException redRuntimeException = new RuntimeException();
RuntimeException blueRuntimeException = new RuntimeException();
addValues(
RuntimeException.class,
redRuntimeException,
blueRuntimeException,
redRuntimeException
);
}

@SuppressWarnings("unused")
private static class JavaApiReflectionClassesContainer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public void succeed_whenClassContainsACommonJavaApiClass() {
EqualsVerifier.forClass(CommonClassesContainer.class).verify();
}

@Test
public void succeed_whenClassContainsExceptions() {
EqualsVerifier.forClass(ExceptionsContainer.class).verify();
}

@Test
public void succeed_whenClassContainsReflectionApiClass() {
EqualsVerifier
Expand Down Expand Up @@ -703,6 +708,34 @@ public int hashCode() {
}
}

@SuppressWarnings("unused") // because of the use of defaultEquals and defaultHashCode
static final class ExceptionsContainer {

private final Throwable throwable;
private final Exception exception;
private final RuntimeException runtimeException;

public ExceptionsContainer(
Throwable throwable,
Exception exception,
RuntimeException runtimeException
) {
this.throwable = throwable;
this.exception = exception;
this.runtimeException = runtimeException;
}

@Override
public boolean equals(Object obj) {
return defaultEquals(this, obj);
}

@Override
public int hashCode() {
return defaultHashCode(this);
}
}

@SuppressWarnings("unused") // because of the use of defaultEquals and defaultHashCode
static final class ReflectionClassesContainer {

Expand Down

0 comments on commit 8d08234

Please sign in to comment.