1 package org.codehaus.mojo.javascript;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.File;
20
21 import org.apache.maven.plugin.Mojo;
22 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
23 import org.codehaus.plexus.util.FileUtils;
24
25
26
27
28 public class CompileMojoTest
29 extends AbstractMojoTestCase
30 {
31 public void testCompileAndAssemble()
32 throws Exception
33 {
34 File testPom = new File( getBasedir(), "src/test/resources/compile.pom" );
35 Mojo mojo = (Mojo) lookupMojo( "compile", testPom );
36 assertNotNull( "Failed to configure the plugin", mojo );
37
38 mojo.execute();
39
40 File expected = new File( "./target/test-target/compile/scriptaculous.js" );
41 assertTrue( "expected file not found " + expected.getName(), expected.exists() );
42
43 expected = new File( "./target/test-target/compile/prototype.js" );
44 assertTrue( "expected file not found " + expected.getName(), expected.exists() );
45
46 String merged = FileUtils.fileRead( expected );
47 assertTrue( "builder not merged", merged.contains( "var Builder = {" ) );
48 assertTrue( "slider not merged", merged.contains( "Slider.prototype = {" ) );
49
50 File unexpected = new File( "./target/test-target/compile/builder.js" );
51 assertTrue( "unexpected file found " + unexpected.getName(), !unexpected.exists() );
52
53 unexpected = new File( "./target/test-target/compile/slider.js" );
54 assertTrue( "unexpected file found " + unexpected.getName(), !unexpected.exists() );
55 }
56 }