Debian Codegraph @

src/test/java/io/reactivex/rxjava3/validators/TextualAorAn.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.*;
17 import java.util.*;
18
19 import org.junit.Test;
20
21 import io.reactivex.rxjava3.testsupport.TestHelper;
22
23 /**
24 * Adds license header to java files.
25 */
26 public class TextualAorAn {
27
28 @Test
29 public void checkFiles() throws Exception {
30 File f = TestHelper.findSource("Flowable");
31 if (f == null) {
32 return;
33 }
34
35 Queue<File> dirs = new ArrayDeque<>();
36
37 File parent = f.getParentFile().getParentFile();
38 dirs.offer(parent);
39 // dirs.offer(new File(parent.getAbsolutePath().replace('\\', '/').replace("src/main/java", "src/perf/java")));
40 // dirs.offer(new File(parent.getAbsolutePath().replace('\\', '/').replace("src/main/java", "src/test/java")));
41
42 StringBuilder fail = new StringBuilder();
43
44 while (!dirs.isEmpty()) {
45 f = dirs.poll();
46
47 File[] list = f.listFiles();
48 if (list != null && list.length != 0) {
49
50 for (File u : list) {
51 if (u.isDirectory()) {
52 dirs.offer(u);
53 } else {
54 if (u.getName().endsWith(".java")) {
55
56 List<String> lines = new ArrayList<>();
57 BufferedReader in = new BufferedReader(new FileReader(u));
58 try {
59 for (;;) {
60 String line = in.readLine();
61 if (line == null) {
62 break;
63 }
64
65 lines.add(line);
66 }
67 } finally {
68 in.close();
69 }
70
71 String clazz = u.getAbsolutePath().replace('\\', '/');
72 int idx = clazz.indexOf("/io/reactivex/");
73 clazz = clazz.substring(idx + 14).replace(".java", "");
74
75 processFile(fail, lines, clazz, u.getName());
76 }
77 }
78 }
79 }
80 }
81
82 if (fail.length() != 0) {
83 System.out.println(fail);
84 throw new AssertionError(fail.toString());
85 }
86 }
87
88 static void processFile(StringBuilder b, List<String> lines, String className, String fileName) {
89 int i = 1;
90 for (String s : lines) {
91
92 if (s.contains(" a Observer")) {
93 b.append("java.lang.RuntimeException: ' a Observer'\r\n at io.reactivex.")
94 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
95 ;
96 }
97
98 if (s.contains("A Observer")) {
99 b.append("java.lang.RuntimeException: 'A Observer'\r\n at io.reactivex.")
100 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
101 ;
102 }
103
104 if (s.contains(" a Observable")) {
105 b.append("java.lang.RuntimeException: ' a Observable'\r\n at io.reactivex.")
106 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
107 ;
108 }
109
110 if (s.contains("A Observable")) {
111 b.append("java.lang.RuntimeException: 'A Observable'\r\n at io.reactivex.")
112 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
113 ;
114 }
115
116 if (s.contains(" an Subscriber")) {
117 b.append("java.lang.RuntimeException: ' an Subscriber'\r\n at io.reactivex.")
118 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
119 ;
120 }
121
122 if (s.contains("An Subscriber")) {
123 b.append("java.lang.RuntimeException: 'An Subscriber'\r\n at io.reactivex.")
124 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
125 ;
126 }
127
128 if (s.contains(" an Publisher")) {
129 b.append("java.lang.RuntimeException: ' an Publisher'\r\n at io.reactivex.")
130 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
131 ;
132 }
133
134 if (s.contains("An Publisher")) {
135 b.append("java.lang.RuntimeException: 'An Publisher'\r\n at io.reactivex.")
136 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
137 ;
138 }
139
140 if (s.contains(" an Flowable")) {
141 b.append("java.lang.RuntimeException: ' an Flowable'\r\n at io.reactivex.")
142 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
143 ;
144 }
145
146 if (s.contains("An Flowable")) {
147 b.append("java.lang.RuntimeException: 'An Flowable'\r\n at io.reactivex.")
148 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
149 ;
150 }
151
152 if (s.contains(" an Single")) {
153 b.append("java.lang.RuntimeException: ' an Single'\r\n at io.reactivex.")
154 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
155 ;
156 }
157
158 if (s.contains("An Single")) {
159 b.append("java.lang.RuntimeException: 'An Single'\r\n at io.reactivex.")
160 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
161 ;
162 }
163
164 if (s.contains(" an Maybe")) {
165 b.append("java.lang.RuntimeException: ' an Maybe'\r\n at io.reactivex.")
166 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
167 ;
168 }
169
170 if (s.contains("An Maybe")) {
171 b.append("java.lang.RuntimeException: 'An Maybe'\r\n at io.reactivex.")
172 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
173 ;
174 }
175
176 if (s.contains(" an Completable")) {
177 b.append("java.lang.RuntimeException: ' an Completable'\r\n at io.reactivex.")
178 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
179 ;
180 }
181
182 if (s.contains("An Completable")) {
183 b.append("java.lang.RuntimeException: 'An Completable'\r\n at io.reactivex.")
184 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
185 ;
186 }
187
188 if (s.contains(" an cancel")) {
189 b.append("java.lang.RuntimeException: ' an cancel'\r\n at io.reactivex.")
190 .append(className).append(" (").append(fileName).append(":").append(i).append(")\r\n");
191 ;
192 }
193
194 i++;
195 }
196 }
197 }