Skip to content

Commit 36a579d

Browse files
committed
version updates and java level up to 21
1 parent 390b1f5 commit 36a579d

File tree

42 files changed

+372
-817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+372
-817
lines changed

00-basics/pom.xml

+11-7
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212
<artifactId>junit5-testengines-00-basics</artifactId>
1313

1414
<dependencies>
15-
<!-- <dependency>-->
16-
<!-- <groupId>org.junit.platform</groupId>-->
17-
<!-- <artifactId>junit-platform-launcher</artifactId>-->
18-
<!-- <version>1.5.1</version>-->
19-
<!-- <scope>test</scope>-->
20-
<!-- </dependency>-->
15+
<dependency>
16+
<groupId>org.junit.platform</groupId>
17+
<artifactId>junit-platform-launcher</artifactId>
18+
<scope>test</scope>
19+
</dependency>
2120
<dependency>
2221
<groupId>org.junit.platform</groupId>
2322
<artifactId>junit-platform-testkit</artifactId>
24-
<version>${junit.platform.version}</version>
2523
<scope>test</scope>
2624
</dependency>
25+
<dependency>
26+
<groupId>org.junit.platform</groupId>
27+
<artifactId>junit-platform-engine</artifactId>
28+
<version>${junit-platform-launcher.version}</version>
29+
<scope>compile</scope>
30+
</dependency>
2731
</dependencies>
2832

2933
</project>

00-basics/src/main/java/org/rapidpm/junit/example/DataSource.java

+25-26
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@
1010

1111
public class DataSource {
1212

13+
private AtomicLong idGenerator = new AtomicLong(0);
14+
private Map<Long, User> persistenceStore = Stream.of(new User(idGenerator.incrementAndGet(), "admin", "admin", "Mr Admin"),
15+
new User(idGenerator.incrementAndGet(), "user", "user", "Mr User"))
16+
.collect(toConcurrentMap(User::id, u -> u));
17+
18+
public User load(Long id) {
19+
return persistenceStore.get(id);
20+
}
21+
22+
public void addUser(String login, String passwd, String name) {
23+
final User u = new User(idGenerator.incrementAndGet(), login, passwd, name);
24+
persistenceStore.put(u.id(), u);
25+
}
26+
27+
public void deleteUser(User u) {
28+
persistenceStore.remove(u.id());
29+
}
30+
31+
public Stream<User> queryForLogin(String login, String password) {
32+
return persistenceStore.values()
33+
.stream()
34+
.filter(u -> u.login().equals(login))
35+
.filter(u -> u.passwd().equals(password));
36+
}
37+
1338
public static class User
1439
extends Quad<Long, String, String, String> {
1540

@@ -35,30 +60,4 @@ public String name() {
3560

3661
}
3762

38-
private AtomicLong idGenerator = new AtomicLong(0);
39-
40-
private Map<Long, User> persistenceStore = Stream.of(new User(idGenerator.incrementAndGet(), "admin", "admin", "Mr Admin"),
41-
new User(idGenerator.incrementAndGet(), "user", "user", "Mr User"))
42-
.collect(toConcurrentMap(User::id, u -> u));
43-
44-
public User load(Long id){
45-
return persistenceStore.get(id);
46-
}
47-
48-
public void addUser(String login, String passwd, String name){
49-
final User u = new User(idGenerator.incrementAndGet(), login, passwd, name);
50-
persistenceStore.put(u.id(), u);
51-
}
52-
53-
public void deleteUser(User u){
54-
persistenceStore.remove(u.id());
55-
}
56-
57-
public Stream<User> queryForLogin(String login, String password){
58-
return persistenceStore.values()
59-
.stream()
60-
.filter(u -> u.login().equals(login))
61-
.filter(u -> u.passwd().equals(password));
62-
}
63-
6463
}

00-basics/src/main/java/org/rapidpm/junit/example/LoginService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public LoginService(DataSource dataSource) {
88
this.dataSource = dataSource;
99
}
1010

11-
public boolean checkLogin(String login, String passwd){
11+
public boolean checkLogin(String login, String passwd) {
1212
return dataSource.queryForLogin(login, passwd).findFirst().isPresent();
1313
}
1414

00-basics/src/test/java/junit/org/rapidpm/junit/basics/Basic04Test.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package junit.org.rapidpm.junit.basics;
22

3+
import com.svenruppert.dependencies.core.logger.HasLogger;
34
import org.junit.jupiter.api.Test;
45
import org.junit.jupiter.api.extension.AfterEachCallback;
56
import org.junit.jupiter.api.extension.BeforeEachCallback;
67
import org.junit.jupiter.api.extension.ExtendWith;
78
import org.junit.jupiter.api.extension.ExtensionContext;
89
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
9-
import org.rapidpm.dependencies.core.logger.HasLogger;
1010

1111
public class Basic04Test {
1212

00-basics/src/test/java/junit/org/rapidpm/junit/tdd/TestEngineTDD01Test.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void verifyJupiterContainerStats() {
2727
EngineTestKit.engine("junit-jupiter")
2828
.selectors(selectClass(DemoTestClass.class))
2929
.execute()
30-
.containers()
30+
.containerEvents()
3131
.assertStatistics(stats -> stats.started(2)
3232
.succeeded(2)
3333
.skipped(0));
@@ -39,7 +39,7 @@ void verifyJupiterTestStats() {
3939
EngineTestKit.engine("junit-jupiter")
4040
.selectors(selectClass(DemoTestClass.class))
4141
.execute()
42-
.tests()
42+
.testEvents()
4343
.assertStatistics(stats -> stats.started(2)
4444
.succeeded(1)
4545
.skipped(1)

00-basics/src/test/java/junit/org/rapidpm/junit/tdd/TestEngineTDD02Test.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void verifyJupiterTestStats() {
3131
EngineTestKit.engine("junit-jupiter")
3232
.selectors(selectClass(DemoTestClass.class))
3333
.execute()
34-
.tests()
34+
.testEvents()
3535
.assertStatistics(stats -> stats.started(2)
3636
.succeeded(1)
3737
.skipped(1)
@@ -46,7 +46,7 @@ void verifyTest002() {
4646
final Events events = EngineTestKit.engine("junit-jupiter")
4747
.selectors(selectMethod(DemoTestClass.class, methodName))
4848
.execute()
49-
.tests();
49+
.testEvents();
5050

5151
events.assertStatistics(stats -> stats.failed(1));
5252

@@ -62,7 +62,7 @@ void verifyTest003() {
6262
final Events events = EngineTestKit.engine("junit-jupiter")
6363
.selectors(selectMethod(DemoTestClass.class, methodName))
6464
.execute()
65-
.tests();
65+
.testEvents();
6666

6767
events.assertStatistics(stats -> stats.skipped(1));
6868

01-useless/pom.xml

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@
1616
<dependency>
1717
<groupId>org.junit.platform</groupId>
1818
<artifactId>junit-platform-launcher</artifactId>
19-
<version>${junit.platform.version}</version>
2019
<scope>test</scope>
2120
</dependency>
2221
<dependency>
2322
<groupId>org.junit.platform</groupId>
2423
<artifactId>junit-platform-testkit</artifactId>
25-
<version>${junit.platform.version}</version>
2624
<scope>test</scope>
2725
</dependency>
26+
<dependency>
27+
<groupId>org.junit.platform</groupId>
28+
<artifactId>junit-platform-engine</artifactId>
29+
<version>${junit-platform-launcher.version}</version>
30+
<scope>compile</scope>
31+
</dependency>
2832
</dependencies>
2933

3034
</project>

01-useless/src/main/java/org/rapidpm/junit/engine/useless/UselessEngine.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.junit.platform.engine.*;
44
import org.junit.platform.engine.support.descriptor.EngineDescriptor;
5-
import org.rapidpm.dependencies.core.logger.HasLogger;
5+
import com.svenruppert.dependencies.core.logger.HasLogger;
66

77
import static org.junit.platform.engine.TestExecutionResult.successful;
88

01-useless/src/main/java/org/rapidpm/junit/engine/useless/UselessEngineTestDescriptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.junit.platform.engine.TestSource;
44
import org.junit.platform.engine.UniqueId;
55
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;
6-
import org.rapidpm.dependencies.core.logger.HasLogger;
6+
import com.svenruppert.dependencies.core.logger.HasLogger;
77

88
public class UselessEngineTestDescriptor
99
extends AbstractTestDescriptor

01-useless/src/test/java/demo/TestEngineRunner001.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void main(String[] args) {
3333
.filter(TestIdentifier::isContainer)
3434
.map(TestIdentifier::getDisplayName)
3535
.map(name -> "TestEngineName: " + name)
36-
.collect(Collectors.toList())
36+
.toList()
3737
.forEach(out::println);
3838
}
3939
}

01-useless/src/test/java/demo/TestEngineRunner002.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void main(String[] args) {
4747
.filter(TestIdentifier::isContainer)
4848
.map(TestIdentifier::getDisplayName)
4949
.map(name -> "TestEngineName: " + name)
50-
.collect(Collectors.toList())
50+
.toList()
5151
.forEach(out::println);
5252
}
5353

01-useless/src/test/java/demo/UselessEngineRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void main(String[] args) {
4747
.filter(TestIdentifier::isContainer)
4848
.map(TestIdentifier::getDisplayName)
4949
.map(name -> "TestEngineName: " + name)
50-
.collect(Collectors.toList())
50+
.toList()
5151
.forEach(out::println);
5252
}
5353

02-nanoengine/pom.xml

+18
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,23 @@
1111

1212
<artifactId>junit5-testengines-02-nanoengine</artifactId>
1313

14+
<dependencies>
15+
<dependency>
16+
<groupId>org.junit.platform</groupId>
17+
<artifactId>junit-platform-launcher</artifactId>
18+
<scope>test</scope>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.junit.platform</groupId>
22+
<artifactId>junit-platform-testkit</artifactId>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.junit.platform</groupId>
27+
<artifactId>junit-platform-engine</artifactId>
28+
<version>${junit-platform-launcher.version}</version>
29+
<scope>compile</scope>
30+
</dependency>
31+
</dependencies>
1432

1533
</project>

02-nanoengine/src/main/java/org/rapidpm/junit/engine/nano/NanoEngine.java

+27-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.rapidpm.junit.engine.nano;
22

3+
4+
import com.svenruppert.dependencies.core.logger.HasLogger;
35
import org.junit.platform.commons.support.AnnotationSupport;
46
import org.junit.platform.commons.support.ReflectionSupport;
57
import org.junit.platform.commons.util.ReflectionUtils;
@@ -9,8 +11,6 @@
911
import org.junit.platform.engine.discovery.MethodSelector;
1012
import org.junit.platform.engine.discovery.PackageSelector;
1113
import org.junit.platform.engine.support.descriptor.EngineDescriptor;
12-
import org.rapidpm.dependencies.core.logger.HasLogger;
13-
import org.rapidpm.dependencies.core.logger.Logger;
1414

1515
import java.lang.reflect.Method;
1616
import java.net.URI;
@@ -24,27 +24,26 @@
2424
import static org.rapidpm.frp.model.Result.failure;
2525
import static org.rapidpm.frp.model.Result.success;
2626

27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
2730
public class NanoEngine
2831
implements TestEngine, HasLogger {
2932

3033
public static final String ENGINE_ID = NanoEngine.class.getSimpleName();
3134

35+
private static final Logger LOGGER = LoggerFactory.getLogger(NanoEngine.class);
36+
3237
protected static Predicate<Class<?>> isTestClass() {
33-
return classCandidate -> match(matchCase(
34-
() -> failure("this class is not a supported by this TestEngine - " + classCandidate.getSimpleName())),
35-
matchCase(() -> isAbstract(classCandidate), () -> failure(
36-
"no support for abstract classes" + classCandidate.getSimpleName())),
37-
matchCase(() -> isPrivate(classCandidate), () -> failure(
38-
"no support for private classes" + classCandidate.getSimpleName())),
39-
matchCase(() -> isAnnotated(classCandidate, NanoTestClass.class),
40-
() -> success(Boolean.TRUE))).ifFailed(
41-
msg -> Logger.getLogger(NanoEngine.class)
42-
.info(msg))
43-
.ifPresent(
44-
b -> Logger.getLogger(NanoEngine.class)
45-
.info("selected class "
46-
+ classCandidate))
47-
.getOrElse(() -> Boolean.FALSE);
38+
return classCandidate -> match(
39+
matchCase(
40+
() -> failure("this class is not a supported by this TestEngine - " + classCandidate.getSimpleName())),
41+
matchCase(() -> isAbstract(classCandidate), () -> failure("no support for abstract classes" + classCandidate.getSimpleName())),
42+
matchCase(() -> isPrivate(classCandidate), () -> failure("no support for private classes" + classCandidate.getSimpleName())),
43+
matchCase(() -> isAnnotated(classCandidate, NanoTestClass.class), () -> success(Boolean.TRUE)))
44+
.ifFailed(msg -> LOGGER.info(msg))
45+
.ifPresent(b -> LOGGER.info("selected class " + classCandidate))
46+
.getOrElse(() -> Boolean.FALSE);
4847
}
4948

5049
protected static Predicate<Method> isTestMethod() {
@@ -54,7 +53,7 @@ protected static Predicate<Method> isTestMethod() {
5453
if (ReflectionUtils.isAbstract(method)) return false;
5554
if (method.getParameterCount() > 0) return false;
5655
return AnnotationSupport.isAnnotated(method, NanoTest.class) && method.getReturnType()
57-
.equals(void.class);
56+
.equals(void.class);
5857
};
5958
}
6059

@@ -70,31 +69,31 @@ public TestDescriptor discover(EngineDiscoveryRequest request, UniqueId engineID
7069
//TODO https://github.com/junit-team/junit5/issues/2001
7170
request.getSelectorsByType(ClasspathRootSelector.class)
7271
// .forEach(selector -> resolver().get().resolve(request,rootNode));
73-
.forEach(selector -> appendTestInRoot(rootNode, selector));
72+
.forEach(selector -> appendTestInRoot(rootNode, selector));
7473

7574
request.getSelectorsByType(PackageSelector.class)
76-
.forEach(selector -> appendTestInPackage(selector.getPackageName(), rootNode));
75+
.forEach(selector -> appendTestInPackage(selector.getPackageName(), rootNode));
7776

7877
request.getSelectorsByType(ClassSelector.class)
79-
.forEach(classSelector -> appendTestInClass(classSelector.getJavaClass(), rootNode));
78+
.forEach(classSelector -> appendTestInClass(classSelector.getJavaClass(), rootNode));
8079

8180
request.getSelectorsByType(MethodSelector.class)
82-
.forEach(selector -> appendTestInMethod(selector.getJavaMethod(), rootNode));
81+
.forEach(selector -> appendTestInMethod(selector.getJavaMethod(), rootNode));
8382

8483
return rootNode;
8584
}
8685

8786
private void appendTestInRoot(EngineDescriptor rootNode, ClasspathRootSelector selector) {
8887
URI classpathRoot = selector.getClasspathRoot();
8988
ReflectionUtils.findAllClassesInClasspathRoot(classpathRoot, isTestClass(), (name) -> true)
90-
.forEach(clazz -> appendTestInClass(clazz, rootNode));
89+
.forEach(clazz -> appendTestInClass(clazz, rootNode));
9190
}
9291

9392
private void appendTestInMethod(Method javaMethod, EngineDescriptor rootNode) {
9493
Class<?> declaringClass = javaMethod.getDeclaringClass();
9594
if (isTestClass().test(declaringClass)) {
9695
final NanoEngineMethodTestDescriptor child = new NanoEngineMethodTestDescriptor(javaMethod, declaringClass,
97-
rootNode.getUniqueId());
96+
rootNode.getUniqueId());
9897
rootNode.addChild(child);
9998
}
10099
}
@@ -107,10 +106,10 @@ private void appendTestInClass(Class<?> javaClass, EngineDescriptor rootNode) {
107106
private void appendTestInPackage(String packageName, EngineDescriptor rootNode) {
108107

109108
ReflectionSupport.findAllClassesInPackage(packageName, isTestClass(), name -> true)
110-
.stream()
111-
.peek((e) -> logger().info("class in package -> " + e.getSimpleName()))
112-
.map(javaClass -> new NanoEngineClassTestDescriptor(javaClass, rootNode.getUniqueId()))
113-
.forEach(rootNode::addChild);
109+
.stream()
110+
.peek((e) -> logger().info("class in package -> " + e.getSimpleName()))
111+
.map(javaClass -> new NanoEngineClassTestDescriptor(javaClass, rootNode.getUniqueId()))
112+
.forEach(rootNode::addChild);
114113
}
115114

116115
@Override

02-nanoengine/src/main/java/org/rapidpm/junit/engine/nano/NanoEngineClassTestDescriptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.junit.platform.engine.UniqueId;
55
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;
66
import org.junit.platform.engine.support.descriptor.ClassSource;
7-
import org.rapidpm.dependencies.core.logger.HasLogger;
7+
import com.svenruppert.dependencies.core.logger.HasLogger;
88

99
import static org.rapidpm.junit.engine.nano.NanoEngine.isTestMethod;
1010

0 commit comments

Comments
 (0)