Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw AssumptionViolatedException when single null is passed to Assum… #1380

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/org/junit/Assume.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static void assumeFalse(String message, boolean b) {
* If called with one or more null elements in <code>objects</code>, the test will halt and be ignored.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the Javadoc:

If called with a {@code null} array or one or more {@code null} elements in {@code objects},
the test will halt and be ignored.

*/
public static void assumeNotNull(Object... objects) {
assumeThat(objects, notNullValue());
assumeThat(asList(objects), everyItem(notNullValue()));
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/junit/tests/experimental/AssumptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ public void assumeNotNullThrowsException() {
}
}

@Test
public void assumeNotNullSingleNullThrowsException() {
try {
assumeNotNull(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a cast to Object[] here.

fail("should throw AssumptionViolatedException");
} catch (AssumptionViolatedException e) {
// expected
}
}

@Test
public void assumeNotNullPasses() {
Object[] objects = {1, 2};
Expand Down