Skip to content

Commit

Permalink
Add assertions for java.lang.reflect. Fix assertj#3130
Browse files Browse the repository at this point in the history
This changes adds assertions for classes:
* Field
* Method
* Constructor

Fix binary compatibility for ShouldHaveAnnotations
Improve Javadoc in AbstractMethodAssert
  • Loading branch information
William Bakker committed Aug 1, 2023
1 parent da690d4 commit f97a3cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void assertIsNotFinal() {
* assertThat(Math.class.getDeclaredMethod("abs", long.class)).isStatic();
*
* // this assertion fails:
* assertThat(AtomicLong.class.getDeclaredMethod("get")).isStatic() </code></pre>
* assertThat(AtomicLong.class.getDeclaredMethod("get")).isStatic(); </code></pre>
*
* @return {@code this} assertions object
* @throws AssertionError if {@code actual} is {@code null}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ public static ErrorMessageFactory shouldHaveAnnotations(AnnotatedElement actual,
return new ShouldHaveAnnotations(actual, expected, missing);
}

/**
* Creates a new <code>{@link ShouldHaveAnnotations}</code>.
*
* @param actual the actual value in the failed assertion.
* @param expected expected annotations for this class
* @param missing missing annotations for this class
* @return the created {@code ErrorMessageFactory}.
*
* @deprecated This method is retained for binary compatibility with assertj 3.24.2 and older.
* Use {@link #shouldHaveAnnotations(AnnotatedElement, Collection, Collection)} instead
*/
@Deprecated
public static ErrorMessageFactory shouldHaveAnnotations(Class<?> actual,
Collection<Class<? extends Annotation>> expected,
Collection<Class<? extends Annotation>> missing) {
return new ShouldHaveAnnotations(actual, expected, missing);
}

private ShouldHaveAnnotations(AnnotatedElement actual, Collection<Class<? extends Annotation>> expected,
Collection<Class<? extends Annotation>> missing) {
super("%nExpecting%n %s%nto have annotations:%n %s%nbut the following annotations were not found:%n %s", actual, expected,
Expand Down

0 comments on commit f97a3cb

Please sign in to comment.