1 package org.codehaus.mojo.javascript.compress;
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 junit.framework.TestCase;
22
23 import org.codehaus.plexus.util.FileUtils;
24
25
26
27
28 public class ShrinksafeCompressorTest
29 extends TestCase
30 {
31 private JSCompressor compressor = new ShrinksafeCompressor();
32
33
34
35
36
37
38 public void testCompress()
39 throws Exception
40 {
41 File input = new File( "src/test/resources/test1.js" );
42 File output = new File( "target/test-out.js" );
43
44 compressor.compress( input, output, JSCompressor.MAX, JSCompressor.JAVASCRIPT_1_3 );
45
46 assertTrue( "exepected file not found", output.exists() );
47 assertTrue( "no compression occured", output.length() < input.length() );
48 }
49
50
51
52
53 public void testMultipleCompress()
54 throws Exception
55 {
56
57
58
59 File output = new File( "target/test-out.js" );
60 File input = null;
61 for ( int i = 1; i <= 3; i++ )
62 {
63 input = new File( "src/test/resources/test" + i + ".js" );
64 compressor.compress( input, output, JSCompressor.MAX, JSCompressor.JAVASCRIPT_1_3 );
65 }
66
67 assertTrue( "exepected file not found", output.exists() );
68 assertTrue( "no compression occured", output.length() < input.length() );
69 String out = FileUtils.fileRead( output );
70 assertTrue( "test1.js code present in test3 compressed", out.indexOf( "test1" ) < 0 );
71 }
72 }