Debian Codegraph @

src/test/java/io/reactivex/rxjava3/validators/OperatorsAreFinal.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.validators;
15
16 import java.io.File;
17 import java.lang.reflect.Modifier;
18
19 import org.junit.Test;
20
21 import io.reactivex.rxjava3.testsupport.TestHelper;
22
23 public class OperatorsAreFinal {
24
25 File directoryOf(String baseClassName) throws Exception {
26 File f = TestHelper.findSource("Flowable");
27 if (f == null) {
28 return null;
29 }
30
31 String parent = f.getParentFile().getParentFile().getAbsolutePath().replace('\\', '/');
32 if (!parent.endsWith("/")) {
33 parent += "/";
34 }
35
36 parent += "internal/operators/" + baseClassName.toLowerCase() + "/";
37 return new File(parent);
38 }
39
40 void check(String baseClassName) throws Exception {
41 File f = directoryOf(baseClassName);
42 if (f == null) {
43 return;
44 }
45
46 StringBuilder e = new StringBuilder();
47
48 File[] files = f.listFiles();
49 if (files != null) {
50 for (File g : files) {
51 if (g.getName().startsWith(baseClassName) && g.getName().endsWith(".java")) {
52 String className = "io.reactivex.rxjava3.internal.operators." + baseClassName.toLowerCase() + "." + g.getName().replace(".java", "");
53
54 Class<?> clazz = Class.forName(className);
55
56 if ((clazz.getModifiers() & Modifier.FINAL) == 0 && (clazz.getModifiers() & Modifier.ABSTRACT) == 0) {
57 e.append("java.lang.RuntimeException: ").append(className).append(" is not final\r\n");
58 e.append(" at ").append(className).append(" (").append(g.getName()).append(":14)\r\n\r\n");
59 }
60 }
61 }
62 }
63
64 if (e.length() != 0) {
65 System.out.println(e);
66
67 throw new AssertionError(e.toString());
68 }
69 }
70
71 @Test
72 public void flowable() throws Exception {
73 check("Flowable");
74 }
75
76 @Test
77 public void observable() throws Exception {
78 check("Observable");
79 }
80
81 @Test
82 public void single() throws Exception {
83 check("Single");
84 }
85
86 @Test
87 public void completable() throws Exception {
88 check("Completable");
89 }
90
91 @Test
92 public void maybe() throws Exception {
93 check("Maybe");
94 }
95
96 }