forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR fixes various comments, 1. added cross ref to "Third-party Assertion Libraries" 2. wrapped lines to 90 char 3. made the anchors hierarchical 4. added note for assertJ's no-exception assertion 5. used static imports for Assertions 6. created separate sections for assertThrows and assertThrowsExactly 7. explicitly mentioned that explicitly mention that a throws clause has no effect. Solves Issue: junit-team#3730 --- I hereby agree to the terms of the JUnit Contributor License Agreement.
- Loading branch information
Driptaroop Das
committed
Apr 17, 2024
1 parent
f13cbcd
commit 45de756
Showing
4 changed files
with
142 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
documentation/src/test/java/example/exception/ExceptionAssertionDemoTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package example.exception; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
// @formatter:off | ||
// tag::user_guide[] | ||
|
||
class ExceptionAssertionDemoTestCase { | ||
@Test | ||
void testExpectedExceptionIsThrown() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
throw new IllegalArgumentException("Expected exception"); | ||
}, "Expected IllegalArgumentException to be thrown"); | ||
|
||
assertThrows(RuntimeException.class, () -> { | ||
throw new IllegalArgumentException("Expected exception"); | ||
}, "should also pass because IllegalArgumentException is subclass of RuntimeException"); | ||
} | ||
} | ||
|
||
// end::user_guide[] | ||
// @formatter:on |
34 changes: 34 additions & 0 deletions
34
documentation/src/test/java/example/exception/ExceptionAssertionExactDemoTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package example.exception; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrowsExactly; | ||
|
||
// @formatter:off | ||
// tag::user_guide[] | ||
|
||
public class ExceptionAssertionExactDemoTestCase { | ||
@Test | ||
void testExpectedExceptionIsThrown() { | ||
assertThrowsExactly(IllegalArgumentException.class, () -> { | ||
throw new IllegalArgumentException("Expected exception"); | ||
}, "This will fail because because we expect IllegalArgumentException to be thrown"); | ||
|
||
assertThrowsExactly(RuntimeException.class, () -> { | ||
throw new IllegalArgumentException("Expected exception"); | ||
}, "This will fail because expected exactly RuntimeException to be thrown, not subclasses"); | ||
} | ||
} | ||
|
||
// end::user_guide[] | ||
// @formatter:on |