use spock framework for unit tests
This commit is contained in:
+4
-2
@@ -5,6 +5,7 @@ apply plugin: 'sonar-runner'
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'groovy'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'coveralls'
|
||||
|
||||
@@ -30,8 +31,10 @@ subprojects {
|
||||
|
||||
dependencies {
|
||||
compile 'org.slf4j:slf4j-api:1.7.7'
|
||||
|
||||
testCompile 'junit:junit:4.11'
|
||||
testCompile 'org.mockito:mockito-core:1.9.5'
|
||||
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
|
||||
testCompile 'ch.qos.logback:logback-classic:1.1.2'
|
||||
}
|
||||
|
||||
@@ -47,14 +50,13 @@ subprojects {
|
||||
}
|
||||
}
|
||||
|
||||
// setup coveralls (http://coveralls.io/)
|
||||
// see http://github.com/kt3k/coveralls-gradle-plugin
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// setup coveralls (http://coveralls.io/) see http://github.com/kt3k/coveralls-gradle-plugin
|
||||
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:0.4.0'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,3 +5,8 @@ dependencies {
|
||||
runtime files(jadxClasspath)
|
||||
}
|
||||
|
||||
task packTests(type: Jar) {
|
||||
classifier = 'tests'
|
||||
from sourceSets.test.output
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ public class SignatureParser {
|
||||
*/
|
||||
public Map<ArgType, List<ArgType>> consumeGenericMap() {
|
||||
if (!lookAhead('<')) {
|
||||
return null;
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<ArgType, List<ArgType>> map = new LinkedHashMap<ArgType, List<ArgType>>(2);
|
||||
consume('<');
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package jadx.tests
|
||||
|
||||
import jadx.core.dex.instructions.args.ArgType
|
||||
import jadx.core.dex.nodes.parser.SignatureParser
|
||||
import spock.lang.Specification
|
||||
|
||||
import static jadx.core.dex.instructions.args.ArgType.*
|
||||
|
||||
class TestSignatureParser extends Specification {
|
||||
def "simple types"() {
|
||||
expect:
|
||||
new SignatureParser(str).consumeType() == result
|
||||
|
||||
where:
|
||||
str | result
|
||||
"" | null
|
||||
"I" | INT
|
||||
"[I" | array(INT)
|
||||
"Ljava/lang/Object;" | OBJECT
|
||||
"[Ljava/lang/Object;" | array(OBJECT)
|
||||
"[[I" | array(array(INT))
|
||||
}
|
||||
|
||||
def "generics"() {
|
||||
expect:
|
||||
new SignatureParser(str).consumeType() == result
|
||||
|
||||
where:
|
||||
str | result
|
||||
"TD;" | genericType("D")
|
||||
"La<TV;Lb;>;" | generic("La;", genericType("V"), object("b"))
|
||||
"La<Lb<Lc;>;>;" | generic("La;", generic("Lb;", object("Lc;")))
|
||||
"La<TD;>.c;" | genericInner(generic("La;", genericType("D")), "c", null)
|
||||
"La<Lb;>.c<TV;>;" | genericInner(generic("La;", object("Lb;")), "c", genericType("V"))
|
||||
}
|
||||
|
||||
def "inner generic"() {
|
||||
expect:
|
||||
new SignatureParser(str).consumeType().getObject() == result
|
||||
|
||||
where:
|
||||
str | result
|
||||
"La<TV;>.LinkedHashIterator<Lb\$c<Ls;TV;>;>;" | "a\$LinkedHashIterator"
|
||||
}
|
||||
|
||||
def "wildcards"() {
|
||||
expect:
|
||||
new SignatureParser("La<$s>;").consumeType() == generic("La;", r as ArgType[])
|
||||
|
||||
where:
|
||||
s | r
|
||||
"*" | wildcard()
|
||||
"+Lb;" | wildcard(object("b"), 1)
|
||||
"-Lb;" | wildcard(object("b"), -1)
|
||||
"+TV;" | wildcard(genericType("V"), 1)
|
||||
"-TV;" | wildcard(genericType("V"), -1)
|
||||
|
||||
"**" | [wildcard(), wildcard()]
|
||||
"*Lb;" | [wildcard(), object("b")]
|
||||
"*TV;" | [wildcard(), genericType("V")]
|
||||
"TV;*" | [genericType("V"), wildcard()]
|
||||
"Lb;*" | [object("b"), wildcard()]
|
||||
|
||||
"***" | [wildcard(), wildcard(), wildcard()]
|
||||
"*Lb;*" | [wildcard(), object("b"), wildcard()]
|
||||
}
|
||||
|
||||
def "generic map"() {
|
||||
expect:
|
||||
new SignatureParser(str).consumeGenericMap() == result.collectEntries { [genericType(it.key), it.value] }
|
||||
|
||||
where:
|
||||
str | result
|
||||
"" | [:]
|
||||
"<T:Ljava/lang/Object;>" | ["T": []]
|
||||
"<K:Ljava/lang/Object;LongType:Ljava/lang/Object;>" | ["K": [], "LongType": []]
|
||||
"<ResultT:Ljava/lang/Exception;:Ljava/lang/Object;>" | ["ResultT": [object("java.lang.Exception")]]
|
||||
}
|
||||
|
||||
def "method args"() {
|
||||
when:
|
||||
def argTypes = new SignatureParser("(Ljava/util/List<*>;)V").consumeMethodArgs()
|
||||
then:
|
||||
argTypes.size() == 1
|
||||
argTypes.get(0) == generic("Ljava/util/List;", wildcard())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package jadx.tests
|
||||
|
||||
import jadx.core.utils.StringUtils
|
||||
import spock.lang.Specification
|
||||
|
||||
class TestStringUtils extends Specification {
|
||||
|
||||
def "unescape string"() {
|
||||
expect:
|
||||
StringUtils.unescapeString(input) == "\"$expected\""
|
||||
|
||||
where:
|
||||
input | expected
|
||||
"" | ""
|
||||
"'" | "'"
|
||||
"a" | "a"
|
||||
"\n" | "\\n"
|
||||
"\t" | "\\t"
|
||||
"\r" | "\\r"
|
||||
"\b" | "\\b"
|
||||
"\f" | "\\f"
|
||||
"\\" | "\\\\"
|
||||
"\"" | "\\\""
|
||||
"\u1234" | "\\u1234"
|
||||
}
|
||||
|
||||
def "unescape char"() {
|
||||
expect:
|
||||
StringUtils.unescapeChar(input as char) == "'$expected'"
|
||||
|
||||
where:
|
||||
input | expected
|
||||
'a' | "a"
|
||||
'\n' | "\\n"
|
||||
'\'' | "\\\'"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user