@@ -13,8 +13,8 @@ class CompletenessTest extends JUnitSuite {
13
13
14
14
val unnecessary = " [considered unnecessary in Scala land]"
15
15
16
- val correspondence = defaultInstanceMethodCorrespondence ++ Map (
17
- // manually added entries
16
+ val correspondence = defaultMethodCorrespondence ++ Map (
17
+ // manually added entries for Java instance methods
18
18
" aggregate(Func2[T, T, T])" -> " reduce((U, U) => U)" ,
19
19
" aggregate(R, Func2[R, _ >: T, R])" -> " fold(R)((R, T) => R)" ,
20
20
" all(Func1[_ >: T, Boolean])" -> " forall(T => Boolean)" ,
@@ -40,11 +40,38 @@ class CompletenessTest extends JUnitSuite {
40
40
" toSortedList(Func2[_ >: T, _ >: T, Integer])" -> unnecessary,
41
41
" where(Func1[_ >: T, Boolean])" -> " filter(T => Boolean)" ,
42
42
" window(Long, Long, TimeUnit)" -> " window(Duration, Duration)" ,
43
- " window(Long, Long, TimeUnit, Scheduler)" -> " window(Duration, Duration, Scheduler)"
43
+ " window(Long, Long, TimeUnit, Scheduler)" -> " window(Duration, Duration, Scheduler)" ,
44
+
45
+ // manually added entries for Java static methods
46
+ " create(OnSubscribeFunc[T])" -> " apply(Observer[T] => Subscription)" ,
47
+ " defer(Func0[_ <: Observable[_ <: T]])" -> " defer(=> Observable[T])" ,
48
+ " empty()" -> " apply(T*)" ,
49
+ " error(Throwable)" -> " apply(Throwable)" ,
50
+ " from(Array[T])" -> " apply(T*)" ,
51
+ " from(Iterable[_ <: T])" -> " apply(T*)" ,
52
+ " merge(Observable[_ <: T], Observable[_ <: T])" -> " merge(Observable[T])" ,
53
+ " mergeDelayError(Observable[_ <: T], Observable[_ <: T])" -> " mergeDelayError(Observable[T])" ,
54
+ " range(Int, Int)" -> " apply(Range)" ,
55
+ " sequenceEqual(Observable[_ <: T], Observable[_ <: T])" -> " [use (first zip second) map (p => p._1 == p._2)]" ,
56
+ " sequenceEqual(Observable[_ <: T], Observable[_ <: T], Func2[_ >: T, _ >: T, Boolean])" -> " [use (first zip second) map (p => equality(p._1, p._2))]" ,
57
+ " switchDo(Observable[_ <: Observable[_ <: T]])" -> " switch" ,
58
+ " synchronize(Observable[_ <: T])" -> " synchronize" ,
59
+ " zip(Observable[_ <: T1], Observable[_ <: T2], Func2[_ >: T1, _ >: T2, _ <: R])" -> " [use instance method zip and map]"
44
60
) ++ List .iterate(" T" , 9 )(s => s + " , T" ).map(
45
61
// all 9 overloads of startWith:
46
62
" startWith(" + _ + " )" -> " [unnecessary because we can just use ++ instead]"
47
- ).toMap
63
+ ).toMap ++ List .iterate(" Observable[_ <: T]" , 9 )(s => s + " , Observable[_ <: T]" ).map(
64
+ // concat 2-9
65
+ " concat(" + _ + " )" -> " [unnecessary because we can use ++ instead]"
66
+ ).drop(1 ).toMap ++ List .iterate(" T" , 10 )(s => s + " , T" ).map(
67
+ // all 10 overloads of from:
68
+ " from(" + _ + " )" -> " apply(T*)"
69
+ ).toMap ++ (3 to 9 ).map(i => {
70
+ // zip3-9:
71
+ val obsArgs = (1 to i).map(j => s " Observable[_ <: T $j], " ).mkString(" " )
72
+ val funcParams = (1 to i).map(j => s " _ >: T $j, " ).mkString(" " )
73
+ (" zip(" + obsArgs + " Func" + i + " [" + funcParams + " _ <: R])" , unnecessary)
74
+ }).toMap
48
75
49
76
def removePackage (s : String ) = s.replaceAll(" (\\ w+\\ .)+(\\ w+)" , " $2" )
50
77
@@ -71,42 +98,37 @@ class CompletenessTest extends JUnitSuite {
71
98
.filter(! _.contains(" $extension" ))
72
99
}
73
100
74
- def getStaticJavaMethods (className : String ): Iterable [String ] = {
75
- val c = Class .forName(className)
76
- for (method <- c.getMethods() if Modifier .isStatic(method.getModifiers)) yield {
77
- method.getName + method.getParameterTypes().map(_.getSimpleName()).mkString(" (" , " , " , " )" )
78
- }
79
- }
101
+ // also applicable for Java types
102
+ def getPublicInstanceAndCompanionMethods (tp : Type ): Iterable [String ] =
103
+ getPublicInstanceMethods(tp) ++
104
+ getPublicInstanceMethods(tp.typeSymbol.companionSymbol.typeSignature)
80
105
81
- def getObservableCompanionMethods : Iterable [String ] = {
82
- val tp = typeOf[rx.lang.scala.Observable .type ]
83
- getPublicInstanceMethods(tp.typeSymbol.companionSymbol.typeSignature)
84
- // TODO how can we filter out instance methods which were put into companion because
85
- // of extends AnyVal in a way which does not depend on implementation-chosen name '$extension'?
86
- .filter(! _.contains(" $extension" ))
87
- }
88
106
89
107
def printMethodSet (title : String , tp : Type ) {
90
108
println(" \n " + title)
91
109
println(title.map(_ => '-' ) + " \n " )
92
110
getPublicInstanceMethods(tp).toList.sorted.foreach(println(_))
93
111
}
94
112
113
+ @ Ignore // because spams output
95
114
@ Test def printJavaInstanceMethods : Unit = {
96
115
printMethodSet(" Instance methods of rx.Observable" ,
97
116
typeOf[rx.Observable [_]])
98
117
}
99
118
119
+ @ Ignore // because spams output
100
120
@ Test def printScalaInstanceMethods : Unit = {
101
121
printMethodSet(" Instance methods of rx.lang.scala.Observable" ,
102
122
typeOf[rx.lang.scala.Observable [_]])
103
123
}
104
124
125
+ @ Ignore // because spams output
105
126
@ Test def printJavaStaticMethods : Unit = {
106
127
printMethodSet(" Static methods of rx.Observable" ,
107
128
typeOf[rx.Observable [_]].typeSymbol.companionSymbol.typeSignature)
108
129
}
109
130
131
+ @ Ignore // because spams output
110
132
@ Test def printScalaCompanionMethods : Unit = {
111
133
printMethodSet(" Companion methods of rx.lang.scala.Observable" ,
112
134
typeOf[rx.lang.scala.Observable .type ])
@@ -125,25 +147,36 @@ class CompletenessTest extends JUnitSuite {
125
147
.replaceAllLiterally(" _ >: " , " " )
126
148
.replaceAll(" (\\ w+)\\ (\\ )" , " $1" )
127
149
}
128
-
129
- def defaultInstanceMethodCorrespondence : Map [String , String ] = {
130
- val instanceMethods = getPublicInstanceMethods (typeOf[rx.Observable [_]]).toList.sorted
131
- val tuples = for (javaM <- instanceMethods ) yield (javaM, javaMethodSignatureToScala(javaM))
150
+
151
+ def defaultMethodCorrespondence : Map [String , String ] = {
152
+ val allMethods = getPublicInstanceAndCompanionMethods (typeOf[rx.Observable [_]])
153
+ val tuples = for (javaM <- allMethods ) yield (javaM, javaMethodSignatureToScala(javaM))
132
154
tuples.toMap
133
155
}
134
156
135
- @ Test def printDefaultInstanceMethodCorrespondence : Unit = {
136
- println(" \n Default Instance Method Correspondence" )
137
- println( " --------------------------------------\n " )
138
- val c = SortedMap (defaultInstanceMethodCorrespondence.toSeq : _* )
157
+ @ Ignore // because spams output
158
+ @ Test def printDefaultMethodCorrespondence : Unit = {
159
+ println(" \n Default Method Correspondence" )
160
+ println( " -----------------------------\n " )
161
+ val c = SortedMap (defaultMethodCorrespondence.toSeq : _* )
139
162
val len = c.keys.map(_.length).max + 2
140
163
for ((javaM, scalaM) <- c) {
141
164
println(s """ %- ${len}s -> %s, """ .format(" \" " + javaM + " \" " , " \" " + scalaM + " \" " ))
142
165
}
143
166
}
144
167
168
+ @ Ignore // because spams output
169
+ @ Test def printCorrectedMethodCorrespondence : Unit = {
170
+ println(" \n Corrected Method Correspondence" )
171
+ println( " -------------------------------\n " )
172
+ val c = SortedMap (correspondence.toSeq : _* )
173
+ for ((javaM, scalaM) <- c) {
174
+ println(" %s -> %s," .format(" \" " + javaM + " \" " , " \" " + scalaM + " \" " ))
175
+ }
176
+ }
177
+
145
178
def checkMethodPresence (expectedMethods : Iterable [String ], tp : Type ): Unit = {
146
- val actualMethods = getPublicInstanceMethods (tp).toSet
179
+ val actualMethods = getPublicInstanceAndCompanionMethods (tp).toSet
147
180
val expMethodsSorted = expectedMethods.toList.sorted
148
181
var good = 0
149
182
var bad = 0
@@ -161,7 +194,7 @@ class CompletenessTest extends JUnitSuite {
161
194
println(" \n Testing that all mentioned Scala methods exist" )
162
195
println( " ----------------------------------------------\n " )
163
196
164
- val actualMethods = getPublicInstanceMethods (typeOf[rx.lang.scala.Observable [_]]).toSet
197
+ val actualMethods = getPublicInstanceAndCompanionMethods (typeOf[rx.lang.scala.Observable [_]]).toSet
165
198
var good = 0
166
199
var bad = 0
167
200
for ((javaM, scalaM) <- SortedMap (correspondence.toSeq :_* )) {
@@ -175,18 +208,18 @@ class CompletenessTest extends JUnitSuite {
175
208
}
176
209
}
177
210
val status = if (bad == 0 ) " SUCCESS" else " BAD"
178
- println(s " $status: $bad out of ${bad+ good} methods were not found in Scala Observable " )
211
+ println(s " \n $status: $bad out of ${bad+ good} methods were not found in Scala Observable " )
179
212
}
180
-
181
- @ Ignore // because we prefer the verbose version
182
- @ Test def checkScalaMethodPresence : Unit = {
183
- checkMethodPresence(correspondence.values, typeOf[rx.lang.scala.Observable [_]])
184
- }
185
-
213
+
186
214
@ Test def checkJavaMethodPresence : Unit = {
187
215
println(" \n Testing that all mentioned Java methods exist" )
188
216
println( " ---------------------------------------------\n " )
189
217
checkMethodPresence(correspondence.keys, typeOf[rx.Observable [_]])
190
218
}
191
219
220
+ @ Ignore // because we prefer the verbose version
221
+ @ Test def checkScalaMethodPresence : Unit = {
222
+ checkMethodPresence(correspondence.values, typeOf[rx.lang.scala.Observable [_]])
223
+ }
224
+
192
225
}
0 commit comments