Skip to content

Commit 4076ad1

Browse files
extract static methods in completeness test
1 parent 435a279 commit 4076ad1

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

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

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import rx.util.functions._
77
import scala.collection.SortedSet
88
import scala.collection.SortedMap
99
import org.junit.Ignore
10+
import java.lang.reflect.Modifier
1011

1112
class CompletenessTest extends JUnitSuite {
1213

@@ -65,22 +66,50 @@ class CompletenessTest extends JUnitSuite {
6566
// declarations: => only those declared in Observable
6667
// members => also those of superclasses
6768
methodMembersToMethodStrings(tp.declarations.filter(m => m.isMethod && m.isPublic))
69+
// TODO how can we filter out instance methods which were put into companion because
70+
// of extends AnyVal in a way which does not depend on implementation-chosen name '$extension'?
71+
.filter(! _.contains("$extension"))
6872
}
6973

70-
def getStaticMethods(tp: Type): Iterable[String] = {
71-
???
72-
}
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+
}
80+
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+
89+
def printMethodSet(title: String, tp: Type) {
90+
println("\n" + title)
91+
println(title.map(_ => '-') + "\n")
92+
getPublicInstanceMethods(tp).toList.sorted.foreach(println(_))
93+
}
7394

7495
@Test def printJavaInstanceMethods: Unit = {
75-
println("\nInstance methods of rx.Observable")
76-
println( "---------------------------------\n")
77-
getPublicInstanceMethods(typeOf[rx.Observable[_]]).toList.sorted.foreach(println(_))
96+
printMethodSet("Instance methods of rx.Observable",
97+
typeOf[rx.Observable[_]])
7898
}
7999

80100
@Test def printScalaInstanceMethods: Unit = {
81-
println("\nInstance methods of rx.lang.scala.Observable")
82-
println( "--------------------------------------------\n")
83-
getPublicInstanceMethods(typeOf[rx.lang.scala.Observable[_]]).toList.sorted.foreach(s => println(s))
101+
printMethodSet("Instance methods of rx.lang.scala.Observable",
102+
typeOf[rx.lang.scala.Observable[_]])
103+
}
104+
105+
@Test def printJavaStaticMethods: Unit = {
106+
printMethodSet("Static methods of rx.Observable",
107+
typeOf[rx.Observable[_]].typeSymbol.companionSymbol.typeSignature)
108+
}
109+
110+
@Test def printScalaCompanionMethods: Unit = {
111+
printMethodSet("Companion methods of rx.lang.scala.Observable",
112+
typeOf[rx.lang.scala.Observable.type])
84113
}
85114

86115
def javaMethodSignatureToScala(s: String): String = {
@@ -113,13 +142,6 @@ class CompletenessTest extends JUnitSuite {
113142
}
114143
}
115144

116-
@Ignore // Does not yet work
117-
@Test def printJavaStaticMethods: Unit = {
118-
println("\nStatic methods of rx.Observable")
119-
println( "-------------------------------\n")
120-
getStaticMethods(typeOf[rx.Observable[_]]).toList.sorted.foreach(println(_))
121-
}
122-
123145
def checkMethodPresence(expectedMethods: Iterable[String], tp: Type): Unit = {
124146
val actualMethods = getPublicInstanceMethods(tp).toSet
125147
val expMethodsSorted = expectedMethods.toList.sorted

0 commit comments

Comments
 (0)