@Test
public void shouldReuseGroupNameMappingFileWithIncrementalBuild()
throws Exception {
final File groupNameMappingFile = WroUtil.createTempFile();
final Resource g1Resource = spy(Resource.create("1.js"));
try {
final WroModel model = new WroModel();
model.addGroup(new Group("g1").addResource(g1Resource));
model.addGroup(new Group("g2").addResource(Resource.create("2.js")));
victim = new Wro4jMojo() {
@Override
protected WroManagerFactory newWroManagerFactory()
throws MojoExecutionException {
final DefaultStandaloneContextAwareManagerFactory managerFactory = new DefaultStandaloneContextAwareManagerFactory();
managerFactory.setUriLocatorFactory(WroTestUtils.createResourceMockingLocatorFactory());
managerFactory.setModelFactory(WroTestUtils.simpleModelFactory(model));
managerFactory.setNamingStrategy(new DefaultHashEncoderNamingStrategy());
return managerFactory;
}
};
setUpMojo(victim);
victim.setGroupNameMappingFile(groupNameMappingFile);
assertEquals(2, victim.getTargetGroupsAsList().size());
victim.execute();
// Now mark it as incremental
when(mockBuildContext.isIncremental()).thenReturn(true);
final Properties groupNames = new Properties();
groupNames.load(new FileInputStream(groupNameMappingFile));
assertEquals(4, groupNames.entrySet().size());
// change the uri of the resource from group a (equivalent to changing its content).
when(g1Resource.getUri()).thenReturn("1a.js");
assertEquals(1, victim.getTargetGroupsAsList().size());
victim.execute();
groupNames.load(new FileInputStream(groupNameMappingFile));