@Test public void testPostProcessSimpleJS() throws Exception { String src = FileUtils.readClassPathFile("postprocessor/js/uglify/simpleJS.js"); StringBuffer sb = new StringBuffer(src); BundleProcessingStatus status = new BundleProcessingStatus( BundleProcessingStatus.BUNDLE_PROCESSING_TYPE, bundle, null, config); StringBuffer ret = processor.postProcessBundle(status, sb); String expected = FileUtils.readClassPathFile("postprocessor/js/uglify/simpleJS_expected.js"); assertEquals(expected, ret.toString()); }
@Test public void testPostProcessWithOutputOptions() throws Exception { String src = FileUtils.readClassPathFile("postprocessor/js/uglify/simpleJS.js"); StringBuffer sb = new StringBuffer(src); when(config.getProperty(JawrConstant.UGLIFY_POSTPROCESSOR_OPTIONS, "{}")) .thenReturn("{output : {comments : /@preserve/ }}"); BundleProcessingStatus status = new BundleProcessingStatus( BundleProcessingStatus.BUNDLE_PROCESSING_TYPE, bundle, null, config); StringBuffer ret = processor.postProcessBundle(status, sb); String expected = FileUtils.readClassPathFile( "postprocessor/js/uglify/simpleJS_WithOutputOptions_expected.js"); assertEquals(expected, ret.toString()); }
@Test public void testPostProcessSimple() { String script = "//comment\n \talert('áéñí')"; Charset charset = Charset.forName("UTF-8"); StringBuffer sb = new StringBuffer(); try { sb.append(script.getBytes(charset.name())); } catch (UnsupportedEncodingException ignore) { fail("UnsupportedEncodingException that will never be thrown"); } // getBundle("/myBundle.js") BundleProcessingStatus status = new BundleProcessingStatus( BundleProcessingStatus.BUNDLE_PROCESSING_TYPE, bundle, null, config); StringBuffer ret = processor.postProcessBundle(status, new StringBuffer(script)); // Not really testing JSMin, that is supposed to work. assertEquals("alert(\"áéñí\");", ret.toString()); }