Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Refactored patch, reverted to flexunit 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M Bauer committed Sep 16, 2011
1 parent be1bb02 commit 24dbe62
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
Expand Up @@ -30,7 +30,7 @@
<dependency> <dependency>
<groupId>com.adobe.flexunit</groupId> <groupId>com.adobe.flexunit</groupId>
<artifactId>flexunit</artifactId> <artifactId>flexunit</artifactId>
<version>4.1</version> <version>4.0.0</version>
<type>swc</type> <type>swc</type>
<scope>external</scope> <scope>external</scope>
</dependency> </dependency>
Expand Down
Expand Up @@ -28,7 +28,7 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
private var _testCountUnknowablePriorToExecution:Boolean = false; private var _testCountUnknowablePriorToExecution:Boolean = false;
private var _socketReporter:SocketReporter; private var _socketReporter:SocketReporter;



public function FlexUnit4Listener(socketReporter:SocketReporter = null, testCountUnknown:Boolean = false) public function FlexUnit4Listener(socketReporter:SocketReporter = null, testCountUnknown:Boolean = false)
{ {
_socketReporter = socketReporter; _socketReporter = socketReporter;
Expand All @@ -43,16 +43,12 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
return _testCountUnknowablePriorToExecution; return _testCountUnknowablePriorToExecution;
} }


protected function set testCountUnknowablePriorToExecution(unknowable:Boolean):void {
_testCountUnknowablePriorToExecution = unknowable;
}

public function run( testApp:ITestApplication ):int public function run( testApp:ITestApplication ):int
{ {
var tests:Array = testApp.tests; var tests:Array = testApp.tests;
var count:int = countAllTestCases(tests); var count:int = countAllTestCases(tests);


var listener:FlexUnit4Listener = new FlexUnit4Listener(_socketReporter, testCountUnknowablePriorToExecution); var listener:FlexUnit4Listener = new FlexUnit4Listener(_socketReporter, testCountIsUnknown(count));
var flexUnitCore:FlexUnitCore = new FlexUnitCore(); var flexUnitCore:FlexUnitCore = new FlexUnitCore();


flexUnitCore.addListener( listener ); flexUnitCore.addListener( listener );
Expand All @@ -64,45 +60,45 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
} }


private function countAllTestCases(tests:Array):int { private function countAllTestCases(tests:Array):int {
var count:int = 0; var total:int = 0;


for each (var test:Class in tests) { for each (var test:Class in tests) {
count += countTestCases(test); var testCount:int = countTestCases(test);
}


if (testCountUnknowablePriorToExecution) if (testCountIsUnknown(testCount))
{ return testCount;
count = int.MAX_VALUE;
total += testCount;
} }


return count; return total;
} }

private function countTestCases(test:Class):int private function countTestCases(test:Class):int
{ {
var klassInfo:Klass = new Klass(test); var klassInfo:Klass = new Klass(test);
var count:int = 0; var count:int = 0;


if (testCountUnknowablePriorToExecution if (parameterizedRunnerPresent(klassInfo))
|| parameterizedRunnerPresent(klassInfo))
{ {
testCountUnknowablePriorToExecution = true; count = int.MAX_VALUE;
} }
else if (klassInfo.hasMetaData("Suite")) else if (klassInfo.hasMetaData("Suite"))
{ {
for each (var oneTest:Class in getSuiteClasses(klassInfo)) count = countAllTestCases(getSuiteClasses(klassInfo));
{
count += countTestCases(oneTest);
}
} }
else else // It's a Test
{ // It's a Test ? {
count = computeTestMethods(test).length; count = computeTestMethods(test).length;
} }


return count; return count;
} }


private static function testCountIsUnknown(testCount:int):Boolean {
return testCount == int.MAX_VALUE;
}

/** /**
* @return true if the test class is to be run with the Parameterized runnner * @return true if the test class is to be run with the Parameterized runnner
* i.e. RunWith("org.flexunit.runners.Parameterized") annotation present * i.e. RunWith("org.flexunit.runners.Parameterized") annotation present
Expand All @@ -119,10 +115,10 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4


return present; return present;
} }

/** /**
* Returns the methods that run tests. Default implementation * Returns the methods that run tests. Default implementation
* returns all methods annotated with {@code @Test} on this * returns all methods annotated with {@code @Test} on this
* class and superclasses that are not overridden. * class and superclasses that are not overridden.
*/ */
protected static function computeTestMethods(test:Class):Array protected static function computeTestMethods(test:Class):Array
Expand All @@ -139,7 +135,7 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
resultMethods.push(method); resultMethods.push(method);
} }
} }

return resultMethods; return resultMethods;
} }


Expand All @@ -156,7 +152,7 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
try try
{ {
classRef = klassInfo.fields[i].type; classRef = klassInfo.fields[i].type;
classArray.push(classRef); classArray.push(classRef);
} }
catch ( e:Error ) catch ( e:Error )
{ {
Expand All @@ -166,8 +162,8 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
} }
} }
} }


/*** /***
<variable name="two" type="suite.cases::TestTwo"/> <variable name="two" type="suite.cases::TestTwo"/>
<variable name="one" type="suite.cases::TestOne"/> <variable name="one" type="suite.cases::TestOne"/>
Expand All @@ -185,7 +181,7 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
{ {
running = true; running = true;
} }

public function testRunFinished( result:Result ):void public function testRunFinished( result:Result ):void
{ {
if (testCountUnknowablePriorToExecution) if (testCountUnknowablePriorToExecution)
Expand All @@ -195,7 +191,7 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4


running = false; running = false;
} }

/** /**
* Called when a Test starts. * Called when a Test starts.
*/ */
Expand All @@ -205,7 +201,7 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
_socketReporter.addMethod( descriptor.path + "." + descriptor.suite, descriptor.method ); _socketReporter.addMethod( descriptor.path + "." + descriptor.suite, descriptor.method );
trace("FlexUnit4: Test " + descriptor.method + " in " + descriptor.path + "." + descriptor.suite + " started"); trace("FlexUnit4: Test " + descriptor.method + " in " + descriptor.path + "." + descriptor.suite + " started");
} }

/** /**
* Called when a Test ends. * Called when a Test ends.
*/ */
Expand All @@ -215,7 +211,7 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
_socketReporter.testFinished(descriptor.path + "." + descriptor.suite); _socketReporter.testFinished(descriptor.path + "." + descriptor.suite);
trace("FlexUnit4: Test " + descriptor.method + " in " + descriptor.path + "." + descriptor.suite + " finished"); trace("FlexUnit4: Test " + descriptor.method + " in " + descriptor.path + "." + descriptor.suite + " finished");
} }

/** /**
* Called when a Failure occurs. * Called when a Failure occurs.
*/ */
Expand Down Expand Up @@ -245,20 +241,20 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
_socketReporter.addFailure(descriptor.path + "." + descriptor.suite, descriptor.method, errorReport); _socketReporter.addFailure(descriptor.path + "." + descriptor.suite, descriptor.method, errorReport);
trace("FlexUnit4: Assumption Failure on Test " + descriptor.method + " in " + descriptor.path + "." + descriptor.suite); trace("FlexUnit4: Assumption Failure on Test " + descriptor.method + " in " + descriptor.path + "." + descriptor.suite);
} }

public function testIgnored( description:IDescription ):void public function testIgnored( description:IDescription ):void
{ {
var descriptor:Descriptor = getDescriptorFromDescription(description); var descriptor:Descriptor = getDescriptorFromDescription(description);
trace("FlexUnit4: Test " + descriptor.method + " in " + descriptor.path + "." + descriptor.suite + " ignored"); trace("FlexUnit4: Test " + descriptor.method + " in " + descriptor.path + "." + descriptor.suite + " ignored");
} }

/* This method comes from the FlexUnit4UIRunner org.flexunit.flexui.data.TestRunnerBasePresentationModel class */ /* This method comes from the FlexUnit4UIRunner org.flexunit.flexui.data.TestRunnerBasePresentationModel class */
private function getDescriptorFromDescription(description:IDescription):Descriptor private function getDescriptorFromDescription(description:IDescription):Descriptor
{ {
var descriptor:Descriptor = new Descriptor(); var descriptor:Descriptor = new Descriptor();
var descriptionArray:Array = description.displayName.split("::"); var descriptionArray:Array = description.displayName.split("::");
descriptor.path = descriptionArray[0]; descriptor.path = descriptionArray[0];

//This code was assuming things would be in a package, which is a good call, but it crashed //This code was assuming things would be in a package, which is a good call, but it crashed
//badly on anything in the default package //badly on anything in the default package
//It also assumes that every test would be in a suite. Also not a valid assumption //It also assumes that every test would be in a suite. Also not a valid assumption
Expand All @@ -268,7 +264,7 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4
{ {
classMethodArray = classMethod.split("."); classMethodArray = classMethod.split(".");
} }
else else
{ {
classMethod = descriptionArray[0]; classMethod = descriptionArray[0];
classMethodArray = classMethod.split("."); classMethodArray = classMethod.split(".");
Expand All @@ -282,3 +278,4 @@ package org.sonatype.flexmojos.unitestingsupport.flexunit4


} }
} }

0 comments on commit 24dbe62

Please sign in to comment.