/
ClassNameFilter.java
45 lines (37 loc) · 1.11 KB
/
ClassNameFilter.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
/*
* Copyright 2015-2016 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 v1.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.junit.gen5.engine;
import static org.junit.gen5.engine.FilterResult.excluded;
import static org.junit.gen5.engine.FilterResult.included;
import java.util.regex.Pattern;
import org.junit.gen5.engine.ClassFilter;
import org.junit.gen5.engine.FilterResult;
/**
* @since 5.0
*/
class ClassNameFilter implements ClassFilter {
private final Pattern pattern;
ClassNameFilter(String pattern) {
this.pattern = Pattern.compile(pattern);
}
@Override
public FilterResult filter(Class<?> testClass) {
if (pattern.matcher(testClass.getName()).matches()) {
return included("TestClass matches name pattern");
}
else {
return excluded("TestClass does not match name pattern");
}
}
@Override
public String toString() {
return "Filter class names with regular expression: " + pattern;
}
}