Skip to content

Commit

Permalink
Remove hasNoPermittedSuperclass() assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
pbacz committed Jan 3, 2024
1 parent 62f30c9 commit b122624
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1197,36 +1197,6 @@ public SELF hasPermittedSubclasses(Class<?>... permittedSubclasses) {
return myself;
}

/**
* Verifies that permitted subclasses of the actual {@code Class} does not have any permitted subclasses.
* <p>
* Example:
* <pre><code class='java'> sealed class SuperClass permits Permitted {
* }
*
* final class Permitted extends SuperClass {
* }
*
* final class NotPermitted {
* }
*
* // these assertions succeed:
* assertThat(String.class).hasNoPermittedSubclasses();
* assertThat(Permitted.class).hasNoPermittedSubclasses();
* assertThat(NotPermitted.class).hasNoPermittedSubclasses();
*
* // this assertion fails:
* assertThat(SuperClass.class).hasNoPermittedSubclasses();</code></pre>
*
* @return {@code this} assertions object
* @throws AssertionError if {@code actual} is {@code null}.
* @throws AssertionError if the actual {@code Class} has any permitted subclasses
*/
public SELF hasNoPermittedSubclasses() {
classes.assertHasNoPermittedSubclasses(info, actual);
return myself;
}

/**
* Verifies that the actual {@code Class} is a primitive type.
* <p>
Expand Down

This file was deleted.

17 changes: 0 additions & 17 deletions assertj-core/src/main/java/org/assertj/core/internal/Classes.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
import static org.assertj.core.error.ShouldHaveMethods.shouldNotHaveMethods;
import static org.assertj.core.error.ShouldHaveNoFields.shouldHaveNoDeclaredFields;
import static org.assertj.core.error.ShouldHaveNoFields.shouldHaveNoPublicFields;
import static org.assertj.core.error.ShouldHaveNoPermittedSubclasses.shouldHaveNoPermittedSubclasses;
import static org.assertj.core.error.ShouldHavePermittedSubclasses.shouldHavePermittedSubclasses;
import static org.assertj.core.error.ShouldOnlyHaveFields.shouldOnlyHaveDeclaredFields;
import static org.assertj.core.error.ShouldOnlyHaveFields.shouldOnlyHaveFields;
import static org.assertj.core.util.Arrays.array;
import static org.assertj.core.util.Arrays.isArrayEmpty;
import static org.assertj.core.util.Lists.newArrayList;
import static org.assertj.core.util.Preconditions.checkArgument;
import static org.assertj.core.util.Sets.newLinkedHashSet;
Expand Down Expand Up @@ -138,21 +136,6 @@ public void assertContainsPermittedSubclasses(AssertionInfo info, Class<?> actua
if (!missing.isEmpty()) throw failures.failure(info, shouldHavePermittedSubclasses(actual, expected, missing));
}

/**
* Verifies that the actual {@code Class} has no permitted subclasses.
*
* @param info contains information about the assertion.
* @param actual the "actual" {@code Class}.
* @throws AssertionError if {@code actual} is {@code null}.
* @throws AssertionError if the actual {@code Class} has any permitted subclasses.
*/
public void assertHasNoPermittedSubclasses(AssertionInfo info, Class<?> actual) {
assertNotNull(info, actual);
Class<?>[] permittedSubclasses = getPermittedSubclasses(actual);
if (!isArrayEmpty(permittedSubclasses))
throw failures.failure(info, shouldHaveNoPermittedSubclasses(actual, newLinkedHashSet(permittedSubclasses)));
}

private static Class<?>[] getPermittedSubclasses(Class<?> actual) {
try {
Method getPermittedSubclasses = Class.class.getMethod("getPermittedSubclasses");
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.assertj.core.error.ShouldBeRecord.shouldNotBeRecord;
import static org.assertj.core.error.ShouldBeSealed.shouldBeSealed;
import static org.assertj.core.error.ShouldBeSealed.shouldNotBeSealed;
import static org.assertj.core.error.ShouldHaveNoPermittedSubclasses.shouldHaveNoPermittedSubclasses;
import static org.assertj.core.error.ShouldHavePermittedSubclasses.shouldHavePermittedSubclasses;
import static org.assertj.core.error.ShouldHaveRecordComponents.shouldHaveRecordComponents;
import static org.assertj.core.util.Sets.set;
Expand Down Expand Up @@ -126,21 +125,6 @@ void hasPermittedSubclasses_should_fail_if_actual_does_not_have_one_of_given_cla
List.of(String.class)).create());
}

@Test
void hasNoPermittedSubclasses_should_pass_if_actual_has_no_permitted_subclasses() {
// WHEN/THEN
assertThat(NonSealedClass.class).hasNoPermittedSubclasses();
}

@Test
void hasNoPermittedSubclasses_should_fail_if_actual_has_a_permitted_subclass() {
// WHEN
Throwable thrown = catchThrowable(() -> assertThat(SealedClass.class).hasNoPermittedSubclasses());
// THEN
then(thrown).isInstanceOf(AssertionError.class)
.hasMessage(shouldHaveNoPermittedSubclasses(SealedClass.class, List.of(NonSealedClass.class)).create());
}

private sealed class SealedClass permits NonSealedClass {
}

Expand Down

0 comments on commit b122624

Please sign in to comment.