Esempio n. 1
0
  @Test
  public void testGetBundleWithValidJavaScriptResourcesAndMinification() throws Exception {

    getObjectUnderTest().setDoMinification(true);

    final List<Resource> resources = new ArrayList<Resource>();
    resources.add(mockResource);
    resources.add(mockResource2);

    recordExpectationsForResource(
        mockResource, getAnExistingTestJavaScriptFile1(), getGroupTestData().createIPhoneGroup());
    recordExpectationsForLastResource(
        mockResource2,
        getAnExistingTestJavaScriptFile2Classpath(),
        getAnExistingTestJavaScriptFile2(),
        getGroupTestData().createAppleGroup());

    getMockMinifier().minifyJavaScript(EasyMock.isA(Reader.class), EasyMock.isA(Writer.class));

    replay();

    final Resource bundle = getObjectUnderTest().getBundle(resources);

    final String bundleContents = readFileContents(bundle.getNewFile());

    // The minifier is mocked so the bundleContents will simply be empty.
    Assert.assertEquals(
        "bundleContents is wrong after minification", StringUtils.EMPTY, bundleContents);
  }
Esempio n. 2
0
  @Test
  public void testGetBundleWithValidJavaScriptResourcesAndNoMinification() throws Exception {

    getObjectUnderTest().setDoMinification(false);

    final List<Resource> resources = new ArrayList<Resource>();
    resources.add(mockResource);
    resources.add(mockResource2);
    resources.add(mockResource3);

    recordExpectationsForResource(
        mockResource, getAnExistingTestJavaScriptFile1(), getGroupTestData().createIPhoneGroup());
    recordExpectationsForLastResource(
        mockResource2,
        getAnExistingTestJavaScriptFile2Classpath(),
        getAnExistingTestJavaScriptFile2(),
        getGroupTestData().createAppleGroup());
    recordExpectationsForBundleResource(mockResource3, getAnExistingJavaScriptBundleFile());

    replay();

    final Resource bundle = getObjectUnderTest().getBundle(resources);

    final String bundleContents = readFileContents(bundle.getNewFile());

    Assert.assertTrue(
        "generated bundle path is incorrect. Was: '" + bundle.getNewPath() + "'",
        bundle
            .getNewPath()
            .endsWith(
                "/-bundle-"
                    + createExpectedGroupsMd5Sum()
                    + "-"
                    + getAnExistingTestJavaScriptFile2().getName()));
    Assert.assertTrue(
        "generated bundle does not contain contents of file 1",
        bundleContents.contains(JAVASCRIPT_FILE1_CONTENT_EXTRACT));
    Assert.assertTrue(
        "generated bundle does not contain contents of file 2",
        bundleContents.contains(JAVASCRIPT_FILE2_CONTENT_EXTRACT));
  }
Esempio n. 3
0
  private void recordExpectationsForBundleResource(final Resource mockResource, final File newFile)
      throws URISyntaxException {

    EasyMock.expect(mockResource.getNewFile()).andReturn(newFile).atLeastOnce();
  }
Esempio n. 4
0
  private void recordExpectationsForResource(
      final Resource mockResource, final File file, final Group group) throws URISyntaxException {

    EasyMock.expect(mockResource.getNewFile()).andReturn(file).atLeastOnce();
    EasyMock.expect(mockResource.getGroup()).andReturn(group).atLeastOnce();
  }