Skip to content

Commit 28104ea

Browse files
some documentation for CompletenessTest
1 parent 5940acd commit 28104ea

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

language-adaptors/rxjava-scala/src/test/scala/rx/lang/scala/CompletenessTest.scala

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,55 @@
11
package rx.lang.scala
22

3-
import scala.reflect.runtime.universe._
4-
import org.scalatest.junit.JUnitSuite
5-
import org.junit.Test
6-
import rx.util.functions._
7-
import scala.collection.SortedSet
3+
import java.util.Calendar
4+
85
import scala.collection.SortedMap
6+
import scala.reflect.runtime.universe
7+
import scala.reflect.runtime.universe.Symbol
8+
import scala.reflect.runtime.universe.Type
9+
import scala.reflect.runtime.universe.typeOf
10+
911
import org.junit.Ignore
10-
import java.lang.reflect.Modifier
11-
import java.util.Date
12-
import java.util.Calendar
12+
import org.junit.Test
13+
import org.scalatest.junit.JUnitSuite
1314

15+
/**
16+
* These tests can be used to check if all methods of the Java Observable have a corresponding
17+
* method in the Scala Observable.
18+
*
19+
* These tests don't contain any assertions, so they will always succeed, but they print their
20+
* results to stdout.
21+
*/
1422
class CompletenessTest extends JUnitSuite {
1523

24+
// some frequently used comments:
1625
val unnecessary = "[considered unnecessary in Scala land]"
17-
1826
val deprecated = "[deprecated in RxJava]"
19-
2027
val averageProblem = "[We can't have a general average method because Scala's `Numeric` does not have " +
2128
"scalar multiplication (we would need to calculate `(1.0/numberOfElements)*sum`). " +
2229
"You can use `fold` instead to accumulate `sum` and `numberOfElements` and divide at the end.]"
23-
2430
val commentForFirstWithPredicate = "[use `.filter(condition).first`]"
25-
2631
val fromFuture = "[TODO: Decide how Scala Futures should relate to Observables. Should there be a " +
2732
"common base interface for Future and Observable? And should Futures also have an unsubscribe method?]"
2833

29-
val correspondence = defaultMethodCorrespondence ++ Map(
34+
/**
35+
* Maps each method from the Java Observable to its corresponding method in the Scala Observable
36+
*/
37+
val correspondence = defaultMethodCorrespondence ++ correspondenceChanges // ++ overrides LHS with RHS
38+
39+
/**
40+
* Creates default method correspondence mappings, assuming that Scala methods have the same
41+
* name and the same argument types as in Java
42+
*/
43+
def defaultMethodCorrespondence: Map[String, String] = {
44+
val allMethods = getPublicInstanceAndCompanionMethods(typeOf[rx.Observable[_]])
45+
val tuples = for (javaM <- allMethods) yield (javaM, javaMethodSignatureToScala(javaM))
46+
tuples.toMap
47+
}
48+
49+
/**
50+
* Manually added mappings from Java Observable methods to Scala Observable methods
51+
*/
52+
def correspondenceChanges = Map(
3053
// manually added entries for Java instance methods
3154
"aggregate(Func2[T, T, T])" -> "reduce((U, U) => U)",
3255
"aggregate(R, Func2[R, _ >: T, R])" -> "foldLeft(R)((R, T) => R)",
@@ -158,8 +181,7 @@ class CompletenessTest extends JUnitSuite {
158181
def getPublicInstanceAndCompanionMethods(tp: Type): Iterable[String] =
159182
getPublicInstanceMethods(tp) ++
160183
getPublicInstanceMethods(tp.typeSymbol.companionSymbol.typeSignature)
161-
162-
184+
163185
def printMethodSet(title: String, tp: Type) {
164186
println("\n" + title)
165187
println(title.map(_ => '-') + "\n")
@@ -204,12 +226,6 @@ class CompletenessTest extends JUnitSuite {
204226
.replaceAll("(\\w+)\\(\\)", "$1")
205227
}
206228

207-
def defaultMethodCorrespondence: Map[String, String] = {
208-
val allMethods = getPublicInstanceAndCompanionMethods(typeOf[rx.Observable[_]])
209-
val tuples = for (javaM <- allMethods) yield (javaM, javaMethodSignatureToScala(javaM))
210-
tuples.toMap
211-
}
212-
213229
@Ignore // because spams output
214230
@Test def printDefaultMethodCorrespondence: Unit = {
215231
println("\nDefault Method Correspondence")

0 commit comments

Comments
 (0)