Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit ed21851

Browse files
authored
Merge pull request #9 from jQAssistant/GH-8-support-additional-junit-5-assert-methods
2 parents 57a8af7 + 091de9e commit ed21851

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
ifndef::jqa-in-manual[== Version 1.10.0]
22
ifdef::jqa-in-manual[== JUnit Plugin 1.10.0]
33

4-
* No changes in this version.
4+
=== Updated concepts
5+
6+
* Added support for additional assert methods to concept `junit5:AssertMethod`.
7+
** The concept now matches all methods in `org.junit.jupiter.api.Assertions` starting with `assert`, thus now supports `assertThrows` and `assertTimeout*`.

src/main/resources/META-INF/jqassistant-rules/junit5.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
(assertType:Type)-[:DECLARES]->(assertMethod)
419419
WHERE
420420
assertType.fqn = 'org.junit.jupiter.api.Assertions'
421-
and assertMethod.signature =~ 'void assert.*'
421+
and assertMethod.signature CONTAINS ' assert'
422422
SET
423423
assertMethod:Junit5:Assert
424424
RETURN

src/test/java/com/buschmais/jqassistant/plugin/junit/test/rule/Junit5IT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.junit.jupiter.api.AfterEach;
1818
import org.junit.jupiter.api.Assertions;
1919
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.function.Executable;
2021

2122
import static com.buschmais.jqassistant.core.report.api.model.Result.Status.SUCCESS;
2223
import static com.buschmais.jqassistant.plugin.java.test.matcher.MethodDescriptorMatcher.methodDescriptor;
@@ -431,7 +432,8 @@ public void assertMethod() throws Exception {
431432
// Oliver B. Fischer, 2019-02-20
432433
assertThat(methods.size()).isGreaterThanOrEqualTo(109);
433434
assertThat(methods, hasItems(methodDescriptor(Assertions.class, "assertTrue", boolean.class),
434-
methodDescriptor(Assertions.class, "assertTrue", boolean.class, String.class)));
435+
methodDescriptor(Assertions.class, "assertTrue", boolean.class, String.class),
436+
methodDescriptor(Assertions.class, "assertThrows", Class.class, Executable.class)));
435437
store.commitTransaction();
436438
}
437439

src/test/java/com/buschmais/jqassistant/plugin/junit/test/set/junit5/Assertions4Junit5.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.jupiter.params.ParameterizedTest;
77
import org.junit.jupiter.params.provider.ValueSource;
88

9+
import static org.junit.jupiter.api.Assertions.assertThrows;
910
import static org.junit.jupiter.api.Assertions.assertTrue;
1011

1112
@Disabled("This is not an actual test")
@@ -44,7 +45,16 @@ public void testWithNestedAssertion() {
4445
nestedAssertion();
4546
}
4647

48+
@Test
49+
public void assertWithNonVoidReturn() {
50+
assertThrows(IllegalArgumentException.class, this::throwsException);
51+
}
52+
4753
private void nestedAssertion() {
4854
assertTrue(() -> 2 > 1, "Condition must be true");
4955
}
56+
57+
private void throwsException() throws IllegalArgumentException {
58+
59+
}
5060
}

0 commit comments

Comments
 (0)