Skip to content

Commit

Permalink
JUnitTestRunner: improved exception handling, reduced class checking …
Browse files Browse the repository at this point in the history
…overhead.

	Change on 2015/07/14 by tball <tball@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=98224510
  • Loading branch information
tomball committed Jul 17, 2015
1 parent 53e5bb8 commit a6fb057
Showing 1 changed file with 25 additions and 31 deletions.
Expand Up @@ -197,17 +197,12 @@ private String getSortKey(Class cls, SortOrder sortOrder) {
/*-[
// Returns true if |cls| conforms to the NSObject protocol.
BOOL IsNSObjectClass(Class cls) {
@try {
while (cls != nil) {
if (class_conformsToProtocol(cls, @protocol(NSObject))) {
return YES;
}
// class_conformsToProtocol() does not examine superclasses.
cls = class_getSuperclass(cls);
while (cls != nil) {
if (class_conformsToProtocol(cls, @protocol(NSObject))) {
return YES;
}
}
@catch (JavaLangThrowable *t) {
// Ignore any exceptions thrown by class initialization.
// class_conformsToProtocol() does not examine superclasses.
cls = class_getSuperclass(cls);
}
return NO;
}
Expand All @@ -222,13 +217,18 @@ private native Set<Class> getAllTestClasses() /*-[
objc_getClassList(classes, classCount);
id<JavaUtilSet> result = [ComGoogleCommonCollectSets newHashSet];
for (int i = 0; i < classCount; i++) {
Class cls = classes[i];
if (IsNSObjectClass(cls)) {
IOSClass *javaClass = IOSClass_fromClass(cls);
if ([self isJUnitTestClassWithIOSClass:javaClass]) {
[result addWithId:javaClass];
@try {
Class cls = classes[i];
if (IsNSObjectClass(cls)) {
IOSClass *javaClass = IOSClass_fromClass(cls);
if ([self isJUnitTestClassWithIOSClass:javaClass]) {
[result addWithId:javaClass];
}
}
}
@catch (JavaLangThrowable *t) {
// Ignore any exceptions thrown by class initialization.
}
}
free(classes);
return result;
Expand All @@ -238,26 +238,19 @@ private native Set<Class> getAllTestClasses() /*-[
* @return true if {@param cls} is either a JUnit 3 or JUnit 4 test.
*/
protected boolean isJUnitTestClass(Class cls) {
return isJUnit3TestClass(cls) || isJUnit4TestSuite(cls) || isJUnit4TestClass(cls);
return isJUnit3TestClass(cls) || isJUnit4TestClass(cls);
}

/**
* @return true if {@param cls} derives from {@link Test} and is not part of the
* {@link junit.framework} package.
*/
protected boolean isJUnit3TestClass(Class cls) {
return Test.class.isAssignableFrom(cls)
&& !getPackageName(cls).startsWith("junit.framework")
&& !getPackageName(cls).startsWith("junit.extensions");
}

/**
* @return true if {@param cls} derives from {@link Suite} and is not part of the
* {@link org.junit} package.
*/
protected boolean isJUnit4TestSuite(Class cls) {
// TODO: implement - check for the RunWith class annotation with a value of Suite.class:
// http://www.vogella.com/tutorials/JUnit/article.html#juniteclipse_testsuite
if (Test.class.isAssignableFrom(cls)) {
String packageName = getPackageName(cls);
return !packageName.startsWith("junit.framework")
&& !packageName.startsWith("junit.extensions");
}
return false;
}

Expand All @@ -273,7 +266,8 @@ protected boolean isJUnit4TestClass(Class cls) {
Annotation annotation = cls.getAnnotation(RunWith.class);
if (annotation != null) {
RunWith runWith = (RunWith) annotation;
if (runWith.value().equals(JUnit4.class)) {
Object value = runWith.value();
if (value.equals(JUnit4.class) || value.equals(Suite.class)) {
return true;
}
}
Expand Down Expand Up @@ -342,9 +336,9 @@ private void loadProperties(InputStream stream) {
for (String key : propertyNames) {
String value = properties.getProperty(key);
try {
if (key == "outputFormat") {
if (key.equals("outputFormat")) {
outputFormat = OutputFormat.valueOf(value);
} else if (key == "sortOrder") {
} else if (key.equals("sortOrder")) {
sortOrder = SortOrder.valueOf(value);
} else if (value.equals(TestInclusion.INCLUDE.name())) {
includePatterns.add(key);
Expand Down

0 comments on commit a6fb057

Please sign in to comment.