-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
VintageDiscovererTests.java
102 lines (80 loc) · 3.15 KB
/
VintageDiscovererTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright 2015-2017 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
*
* http://www.eclipse.org/legal/epl-v20.html
*/
package org.junit.vintage.engine.discovery;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.platform.engine.FilterResult.includedIf;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
import static org.junit.vintage.engine.VintageUniqueIdBuilder.engineId;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.engine.TrackLogRecords;
import org.junit.platform.commons.logging.LogRecordListener;
import org.junit.platform.engine.EngineDiscoveryRequest;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.discovery.ClassNameFilter;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.vintage.engine.samples.junit3.AbstractJUnit3TestCase;
import org.junit.vintage.engine.samples.junit4.AbstractJunit4TestCaseWithConstructorParameter;
/**
* Tests for {@link VintageDiscoverer}.
*
* @since 4.12
*/
@TrackLogRecords
class VintageDiscovererTests {
@Test
void logsDebugMessageWhenFilterExcludesClass(LogRecordListener listener) {
ClassNameFilter fooFilter = className -> includedIf(Foo.class.getName().equals(className), () -> "match",
() -> "no match");
// @formatter:off
EngineDiscoveryRequest request = request()
.selectors(selectClass(Foo.class), selectClass(Bar.class))
.filters(fooFilter)
.build();
// @formatter:on
VintageDiscoverer discoverer = new VintageDiscoverer();
TestDescriptor testDescriptor = discoverer.discover(request, engineId());
assertThat(testDescriptor.getChildren()).hasSize(1);
// @formatter:off
assertThat(listener.getLogRecords(VintageDiscoverer.class, Level.FINE).stream()
.map(LogRecord::getMessage)
.filter(m -> m.equals("Class " + Bar.class.getName() + " was excluded by a class filter: no match"))
.count()
).isEqualTo(1);
// @formatter:on
}
@Test
void doesNotResolveAbstractJUnit3Classes(LogRecordListener listener) {
doesNotResolve(listener, AbstractJUnit3TestCase.class);
}
@Test
void doesNotResolveAbstractJUnit4Classes(LogRecordListener listener) {
doesNotResolve(listener, AbstractJunit4TestCaseWithConstructorParameter.class);
}
private void doesNotResolve(LogRecordListener listener, Class<?> testClass) {
LauncherDiscoveryRequest request = request().selectors(selectClass(testClass)).build();
VintageDiscoverer discoverer = new VintageDiscoverer();
TestDescriptor testDescriptor = discoverer.discover(request, engineId());
assertThat(testDescriptor.getChildren()).isEmpty();
assertThat(listener.getLogRecords(VintageDiscoverer.class)).isEmpty();
}
public static class Foo {
@org.junit.Test
public void test() {
}
}
public static class Bar {
@org.junit.Test
public void test() {
}
}
}