Debian Codegraph @

src/test/java/io/reactivex/rxjava3/validators/InternalWrongNaming.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 InternalWrongNaming {
27
28 static void checkInternalOperatorNaming(String baseClassName, String consumerClassName, String... ignore) throws Exception {
29 File f = TestHelper.findSource(baseClassName);
30 if (f == null) {
31 return;
32 }
33
34 String rxdir = f.getParentFile().getParentFile().getAbsolutePath().replace('\\', '/');
35
36 if (!rxdir.endsWith("/")) {
37 rxdir += "/";
38 }
39
40 rxdir += "internal/operators/" + baseClassName.toLowerCase() + "/";
41
42 File[] list = new File(rxdir).listFiles();
43 if (list != null && list.length != 0) {
44
45 StringBuilder fail = new StringBuilder();
46
47 int count = 0;
48
49 outer:
50 for (File g : list) {
51 for (String s : ignore) {
52 if (g.getName().equals(s + ".java")) {
53 continue outer;
54 }
55 }
56 List<String> lines = readFile(g);
57
58 for (int i = 0; i < lines.size(); i++) {
59 String line = lines.get(i);
60 if (line.contains(consumerClassName)) {
61
62 fail.append("java.lang.RuntimeException: " + g.getName() + " mentions " + consumerClassName)
63 .append("\r\n at io.reactivex.internal.operators.")
64 .append(baseClassName.toLowerCase()).append(".").append(g.getName().replace(".java", ""))
65 .append(".method(").append(g.getName()).append(":").append(i + 1).append(")\r\n\r\n");
66
67 count++;
68 }
69 }
70 }
71
72 if (fail.length() != 0) {
73 System.out.println(fail);
74
75 System.out.println();
76 System.out.println("Total: " + count);
77 throw new AssertionError(fail.toString());
78 }
79
80 }
81 }
82
83 static List<String> readFile(File u) throws Exception {
84 List<String> lines = new ArrayList<>();
85
86 BufferedReader in = new BufferedReader(new FileReader(u));
87 try {
88 for (;;) {
89 String line = in.readLine();
90 if (line == null) {
91 break;
92 }
93
94 lines.add(line);
95 }
96 } finally {
97 in.close();
98 }
99 return lines;
100 }
101
102 @Test
103 public void observableNoSubscriber() throws Exception {
104 checkInternalOperatorNaming("Observable", "Subscriber",
105 "ObservableFromPublisher"
106 );
107 }
108
109 @Test
110 public void observableNoSubscribers() throws Exception {
111 checkInternalOperatorNaming("Observable", "subscribers");
112 }
113
114 @Test
115 public void observableNoSubscription() throws Exception {
116 checkInternalOperatorNaming("Observable", "Subscription",
117 "ObservableFromPublisher", "ObservableDelaySubscriptionOther");
118 }
119
120 @Test
121 public void observableNoPublisher() throws Exception {
122 checkInternalOperatorNaming("Observable", "Publisher",
123 "ObservableFromPublisher");
124 }
125
126 @Test
127 public void observableNoFlowable() throws Exception {
128 checkInternalOperatorNaming("Observable", "Flowable", "ObservableFromPublisher");
129 }
130
131 @Test
132 public void observableProducer() throws Exception {
133 checkInternalOperatorNaming("Observable", "Producer");
134 }
135
136 @Test
137 public void observableProducers() throws Exception {
138 checkInternalOperatorNaming("Observable", "producers");
139 }
140
141 @Test
142 public void flowableNoProducer() throws Exception {
143 checkInternalOperatorNaming("Flowable", "Producer");
144 }
145
146 @Test
147 public void flowableNoProducers() throws Exception {
148 checkInternalOperatorNaming("Flowable", "producers");
149 }
150
151 @Test
152 public void flowableNoUnsubscrib() throws Exception {
153 checkInternalOperatorNaming("Flowable", "unsubscrib");
154 }
155
156 @Test
157 public void observableNoUnsubscrib() throws Exception {
158 checkInternalOperatorNaming("Observable", "unsubscrib");
159 }
160
161 @Test
162 public void flowableNoObserver() throws Exception {
163 checkInternalOperatorNaming("Flowable", "Observer",
164 "FlowableFromObservable",
165 "FlowableLastSingle",
166 "FlowableAnySingle",
167 "FlowableAllSingle",
168 "FlowableToListSingle",
169 "FlowableCollectSingle",
170 "FlowableCountSingle",
171 "FlowableElementAtMaybe",
172 "FlowableElementAtSingle",
173 "FlowableElementAtMaybePublisher",
174 "FlowableElementAtSinglePublisher",
175 "FlowableFromCompletable",
176 "FlowableSingleSingle",
177 "FlowableSingleMaybe",
178 "FlowableLastMaybe",
179 "FlowableIgnoreElementsCompletable",
180 "FlowableReduceMaybe",
181 "FlowableReduceWithSingle",
182 "FlowableReduceSeedSingle",
183 "FlowableFlatMapCompletable",
184 "FlowableFlatMapCompletableCompletable",
185 "FlowableFlatMapSingle",
186 "FlowableFlatMapMaybe",
187 "FlowableSequenceEqualSingle",
188 "FlowableConcatWithSingle",
189 "FlowableConcatWithMaybe",
190 "FlowableConcatWithCompletable",
191 "FlowableMergeWithSingle",
192 "FlowableMergeWithMaybe",
193 "FlowableMergeWithCompletable"
194 );
195 }
196 }