Skip to content

Commit 84ea446

Browse files
committed
t Fixing test class names
1 parent 9770b62 commit 84ea446

File tree

9 files changed

+91
-6
lines changed

9 files changed

+91
-6
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.approvaltests;
2+
3+
import com.spun.util.ObjectUtils;
4+
import com.spun.util.io.FileUtils;
5+
import com.spun.util.logger.SimpleLogger;
6+
import org.approvaltests.core.Options;
7+
import org.junit.jupiter.api.Test;
8+
import org.lambda.functions.Functions;
9+
import org.lambda.query.Query;
10+
import org.lambda.query.Queryable;
11+
12+
import java.io.File;
13+
import java.lang.reflect.Method;
14+
import java.lang.reflect.Modifier;
15+
import java.util.List;
16+
17+
public class TestFilesTest
18+
{
19+
@Test
20+
void testTestFileNamesEndInTest()
21+
{
22+
// Get all of the classes for all the packages
23+
Queryable<Class<?>> classes = getAllClasses();
24+
// Filter for methods in the classes that have a checked exception
25+
Queryable<String> methods = classes.selectMany(s -> getTestMethods(s))
26+
.select(m -> String.format("%s.%s", m.getDeclaringClass().getName(), m.getName()))
27+
.orderBy(m -> m.toString());
28+
// Verify the methods
29+
Options options = new Options();
30+
Approvals.verifyAll(
31+
"Test Methods in files that do not contain the word 'Test' (these will not be run in our CI build)",
32+
methods, c -> c.toString(), options);
33+
}
34+
private List<Method> getTestMethods(Class<?> aClass)
35+
{
36+
Method[] declaredMethods = aClass.getDeclaredMethods();
37+
return Query.where(declaredMethods,
38+
m -> Queryable.as(m.getAnnotations()).any(a -> a.toString().contains("Test")));
39+
}
40+
private Queryable<Class<?>> getAllClasses()
41+
{
42+
File[] files = FileUtils.getRecursiveFileList(new File("."), f -> f.getName().endsWith(".java"));
43+
Queryable<String> paths = Query.select(files,
44+
Functions.unchecked(f -> f.getCanonicalPath().replace(File.separatorChar, '.')));
45+
paths = paths.where(p -> p.contains(".test.")).where(p -> !p.contains("Test.java"));
46+
return paths.select(f -> getJavaClass(f));
47+
}
48+
private Class<?> getJavaClass(String path)
49+
{
50+
String className = path.substring(0, path.length() - ".java".length());
51+
if (className.contains(".com."))
52+
{
53+
className = className.substring(className.indexOf(".com.") + 1);
54+
}
55+
if (className.contains(".org."))
56+
{
57+
className = className.substring(className.indexOf(".org.") + 1);
58+
}
59+
try
60+
{
61+
Class<?> aClass = Class.forName(className);
62+
return aClass;
63+
}
64+
catch (Throwable e)
65+
{
66+
SimpleLogger.variable("Path", path);
67+
throw ObjectUtils.throwAsError(e);
68+
}
69+
}
70+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Test Methods in files that do not contain the word 'Test' (these will not be run in our CI build)
2+
3+
4+
org.approvaltests.DocumentHelpers.listAllVerifyFunctions
5+
org.approvaltests.DocumentHelpers.testLineNumberOfThisMethod
6+
org.approvaltests.DocumentHelpers.testLineNumbers
7+
org.approvaltests.Samples.sampleParameterizedTest
8+
org.approvaltests.Samples.testArray
9+
org.approvaltests.Samples.testObject
10+
org.approvaltests.Samples.testString
11+
org.approvaltests.namer.NamerSamples.useAlternativeSourceFileFinder
12+
org.approvaltests.packagesettings.basedirectory.TestApprovalDirectoryConfig.testApprovalBaseDirectory
13+
org.approvaltests.packagesettings.subdirectory.TestApprovalDirectoryConfig.testApprovalSubdirectory

approvaltests-tests/src/test/java/org/approvaltests/packagesettings/basedirectory/TestApprovalDirectoryConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.File;
77
import java.text.MessageFormat;
88

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

1112
public class TestApprovalDirectoryConfig

approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTests.java renamed to approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import java.util.stream.Stream;
1313

1414
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.junit.jupiter.api.Assertions.assertFalse;
1516

16-
public class DateScrubberTests
17+
public class DateScrubberTest
1718
{
1819
@Test
1920
void testSupportedFormatWorksForExamples()

approvaltests/docs/Scrubbers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,22 @@ The easiest way to scrub a date is by calling
9696
```java
9797
Approvals.verify("created at 03:14:15", new Options().withScrubber(DateScrubber.getScrubberFor("00:00:00")));
9898
```
99-
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTests.java#L48-L50' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrub-date-example' title='Start of snippet'>anchor</a></sup>
99+
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java#L48-L50' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrub-date-example' title='Start of snippet'>anchor</a></sup>
100100
<!-- endSnippet -->
101101

102102
which will produce
103103

104-
<!-- snippet: DateScrubberTests.exampleForDocumentation.approved.txt -->
105-
<a id='snippet-DateScrubberTests.exampleForDocumentation.approved.txt'></a>
104+
<!-- snippet: DateScrubberTest.exampleForDocumentation.approved.txt -->
105+
<a id='snippet-DateScrubberTest.exampleForDocumentation.approved.txt'></a>
106106
```txt
107107
created at [Date1]
108108
```
109-
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTests.exampleForDocumentation.approved.txt#L1-L1' title='Snippet source file'>snippet source</a> | <a href='#snippet-DateScrubberTests.exampleForDocumentation.approved.txt' title='Start of snippet'>anchor</a></sup>
109+
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.exampleForDocumentation.approved.txt#L1-L1' title='Snippet source file'>snippet source</a> | <a href='#snippet-DateScrubberTest.exampleForDocumentation.approved.txt' title='Start of snippet'>anchor</a></sup>
110110
<!-- endSnippet -->
111111

112112
### Supported formats
113113

114-
<!-- include: DateScrubberTests.supportedFormats.approved.md -->
114+
<!-- include: DateScrubberTest.supportedFormats.approved.md -->
115115
| Example Date | RegEx Pattern |
116116
| :-------------------- | :----------------------- |
117117
| Tue May 13 16:30:00 | [a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} |

0 commit comments

Comments
 (0)