### Question:
Wro4jMojo extends AbstractWro4jMojo { void setGroupNameMappingFile(final File groupNameMappingFile) { this.groupNameMappingFile = groupNameMappingFile; }  void setBuildFinalName(final File buildFinalName);  }### Answer:
@Test public void shouldGenerateGroupMappingUsingNoOpNamingStrategy() throws Exception { setWroWithValidResources(); final File groupNameMappingFile = new File(FileUtils.getTempDirectory(), "groupMapping-" + new Date().getTime()); victim.setGroupNameMappingFile(groupNameMappingFile); victim.setIgnoreMissingResources(true); victim.execute(); final Properties groupNames = new Properties(); groupNames.load(new FileInputStream(groupNameMappingFile)); LOG.debug("groupNames: {}", groupNames); assertEquals("g1.js", groupNames.get("g1.js")); FileUtils.deleteQuietly(groupNameMappingFile); }
@Test public void shouldGenerateGroupMappingUsingCustomNamingStrategy() throws Exception { setWroWithValidResources(); final File groupNameMappingFile = new File(FileUtils.getTempDirectory(), "groupMapping-" + new Date().getTime()); victim.setWroManagerFactory(CustomNamingStrategyWroManagerFactory.class.getName()); victim.setGroupNameMappingFile(groupNameMappingFile); victim.setIgnoreMissingResources(true); victim.execute(); final Properties groupNames = new Properties(); groupNames.load(new FileInputStream(groupNameMappingFile)); LOG.debug("groupNames: {}", groupNames); Assert.assertEquals(CustomNamingStrategyWroManagerFactory.PREFIX + "g1.js", groupNames.get("g1.js")); FileUtils.deleteQuietly(groupNameMappingFile); }
@Test public void shouldCreateMissingFolderForGroupNameMappingFile() throws Exception { final File parentFolder = new File(FileUtils.getTempDirectory(), "wro4j-" + UUID.randomUUID()); try { setWroWithValidResources(); final File groupNameMappingFile = new File(parentFolder, "groupMapping-" + new Date().getTime()); victim.setWroManagerFactory(CustomNamingStrategyWroManagerFactory.class.getName()); victim.setGroupNameMappingFile(groupNameMappingFile); victim.setIgnoreMissingResources(true); victim.execute(); } finally { FileUtils.deleteQuietly(parentFolder); } }
@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(); when(mockBuildContext.isIncremental()).thenReturn(true); final Properties groupNames = new Properties(); groupNames.load(new FileInputStream(groupNameMappingFile)); assertEquals(4, groupNames.entrySet().size()); when(g1Resource.getUri()).thenReturn("1a.js"); assertEquals(1, victim.getTargetGroupsAsList().size()); victim.execute(); groupNames.load(new FileInputStream(groupNameMappingFile)); assertEquals(4, groupNames.entrySet().size()); } finally { FileUtils.deleteQuietly(groupNameMappingFile); } }