| 921 | } |
| 922 | |
| 923 | private void testTests(final File dir) throws Exception { |
| 924 | final File[] files = dir.listFiles(); |
| 925 | if (files == null) { |
| 926 | return; |
| 927 | } |
| 928 | |
| 929 | for (final File file : files) { |
| 930 | if (file.isDirectory()) { |
| 931 | if (!".git".equals(file.getName())) { |
| 932 | testTests(file); |
| 933 | } |
| 934 | } |
| 935 | else { |
| 936 | if (file.getName().endsWith(".java")) { |
| 937 | final int index = new File("src/test/java").getAbsolutePath().length(); |
| 938 | String name = file.getAbsolutePath(); |
| 939 | name = name.substring(index + 1, name.length() - 5); |
| 940 | name = name.replace(File.separatorChar, '.'); |
| 941 | final Class<?> clazz; |
| 942 | try { |
| 943 | clazz = Class.forName(name); |
| 944 | } |
| 945 | catch (final Exception e) { |
| 946 | continue; |
| 947 | } |
| 948 | name = file.getName(); |
| 949 | if (name.endsWith("Test.java") || name.endsWith("TestCase.java")) { |
| 950 | for (final Constructor<?> ctor : clazz.getConstructors()) { |
| 951 | if (ctor.getParameterTypes().length == 0) { |
| 952 | for (final Method method : clazz.getDeclaredMethods()) { |
| 953 | if (Modifier.isPublic(method.getModifiers()) |
| 954 | && method.getAnnotation(BeforeEach.class) == null |
| 955 | && method.getAnnotation(BeforeAll.class) == null |
| 956 | && method.getAnnotation(AfterEach.class) == null |
| 957 | && method.getAnnotation(AfterAll.class) == null |
| 958 | && method.getAnnotation(Test.class) == null |
| 959 | && method.getAnnotation(RepeatedTest.class) == null |
| 960 | && method.getAnnotation(RetryingTest.class) == null |
| 961 | && method.getReturnType() == Void.TYPE |
| 962 | && method.getParameterTypes().length == 0) { |
| 963 | final List<String> lines = FileUtils.readLines(file, SOURCE_ENCODING); |
| 964 | int line = -1; |
| 965 | for (int i = 0; i < lines.size(); ++i) { |
| 966 | if (lines.get(i).contains("public void " + method.getName() + "()")) { |
| 967 | line = i + 1; |
| 968 | break; |
| 969 | } |
| 970 | } |
| 971 | addFailure(file.toString().replace('\\', '/'), line, |
| 972 | "Method '" + method.getName() + "' does not declare @Test annotation"); |
| 973 | } |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | } |