Skip to content

Commit 42d779e

Browse files
committed
Create a test to cover test-swf goal
1 parent 5844d0a commit 42d779e

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ target/
2323
# Other
2424
.svn/
2525
bin/
26+
27+
.scala_dependencies
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.sonatype.flexmojos.tests.concept;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.not;
5+
6+
import java.io.File;
7+
import java.io.IOException;
8+
9+
import org.apache.maven.it.VerificationException;
10+
import org.hamcrest.Matcher;
11+
import org.sonatype.flexmojos.test.FMVerifier;
12+
import org.sonatype.flexmojos.tests.AbstractFlexMojosTests;
13+
import org.sonatype.flexmojos.tests.matcher.ClassMatcher;
14+
import org.testng.annotations.Test;
15+
16+
public class TestSwfTest
17+
extends AbstractFlexMojosTests
18+
{
19+
20+
@SuppressWarnings( "all" )
21+
private static final Matcher<File> TEST_CLASS = ClassMatcher.hasClass( "flexunit.framework:TestSuite" );
22+
23+
@Test
24+
public void testSwf()
25+
throws Exception
26+
{
27+
File main = compile( "flexmojos:compile-swf", "hello-world-1.0-SNAPSHOT.swf" );
28+
assertThat( main, not( TEST_CLASS ) );
29+
30+
main = compile( "flexmojos:test-swf", "hello-world-1.0-SNAPSHOT-test.swf" );
31+
assertThat( main, TEST_CLASS );
32+
}
33+
34+
private File compile( String goal, String file )
35+
throws VerificationException, IOException, Exception
36+
{
37+
FMVerifier v = test( getProject( "intro/hello-world" ), goal, "-DisIt=true" );
38+
String dir = v.getBasedir();
39+
40+
File target = new File( dir, "target" );
41+
File main = new File( target, file );
42+
43+
assertSeftExit( main, 3539, v );
44+
return main;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.sonatype.flexmojos.tests.matcher
2+
import apparat.abc._
3+
import apparat.bytecode._
4+
import apparat.swf._
5+
import java.io.{
6+
File => JFile
7+
}
8+
import org.hamcrest.{ TypeSafeMatcher, Description, Matcher }
9+
10+
object ClassMatcher {
11+
def hasClass(classname: String): Matcher[JFile] = {
12+
return new ClassMatcher(classname);
13+
}
14+
}
15+
class ClassMatcher(classnames: String*) extends TypeSafeMatcher[JFile] {
16+
17+
private var fileTested: JFile = null;
18+
private var found = new StringBuilder();
19+
20+
def matchesSafely(file: JFile): Boolean = {
21+
fileTested = file;
22+
for {
23+
tag <- Swf fromFile file
24+
abc <- Abc fromTag tag
25+
nominal <- abc.types
26+
} {
27+
var foundName = nominal.name.namespace.name.name + ":" + nominal.name.name.name;
28+
if (classnames contains foundName) {
29+
return true;
30+
} else {
31+
found append foundName
32+
found append ", "
33+
}
34+
}
35+
false;
36+
}
37+
38+
def describeTo(desc: Description): Unit = {
39+
desc.appendText(" contains ");
40+
for (classname <- classnames) {
41+
desc.appendValue(classname);
42+
desc.appendText(", ");
43+
}
44+
desc.appendValue(" instead found ");
45+
desc.appendText(found.toString)
46+
}
47+
48+
}

0 commit comments

Comments
 (0)