https://github.com/marschall/junit-lambda
junit extensions that make use of lambda expressions
https://github.com/marschall/junit-lambda
Last synced: 9 months ago
JSON representation
junit extensions that make use of lambda expressions
- Host: GitHub
- URL: https://github.com/marschall/junit-lambda
- Owner: marschall
- Created: 2013-09-26T20:08:22.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2020-11-15T19:55:42.000Z (about 5 years ago)
- Last Synced: 2025-03-27T02:43:13.195Z (9 months ago)
- Language: Java
- Size: 40 KB
- Stars: 6
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JUnit λ [](https://travis-ci.org/marschall/junit-lambda) [](https://maven-badges.herokuapp.com/maven-central/com.github.marschall/junit-lambda)
=======
JUnit extensions built on Java 8 lambdas. Helps to test exceptions and can be used instead of the following pattern:
```java
try {
Long.parseLong("foo");
fail("'foo' should not be a valid long");
} catch (NumberFormatException e) {
// should reach here
}
```
You can either use `#assertRaises`
```java
import static com.github.marschall.junitlambda.LambdaAssert.assertRaises;
import org.junit.Test;
public final class JunitLambdaTest {
@Test
public void testNumberFormatException() {
assertRaises(() -> Long.parseLong("foo"), NumberFormatException.class);
}
}
```
or the Hamcrest matcher `#throwsException`
```java
import static com.github.marschall.junitlambda.ThrowsException.throwsException;
import org.junit.Test;
public final class JunitLambdaTest {
@Test
public void testNumberFormatException() {
assertThat(() -> Long.parseLong("foo"), throwsException(NumberFormatException.class));
}
}
```
```xml
com.github.marschall
junit-lambda
0.3.0
test
```
The code is under MIT license.