AbstractDefineResourcesMojo extends AbstractWOMojo { static Resource findOrCreateResource(final List<Resource> resources, final String resourceDirectory) { if (resourceDirectory == null) { throw new IllegalArgumentException("The resource directory argument cannot be null"); } for (Resource resource : resources) { if (resourceDirectory.equals(resource.getDirectory())) { return resource; } } Resource resource = new Resource(); resource.setDirectory(resourceDirectory); return resource; } AbstractDefineResourcesMojo(); void execute(); Boolean flattenResources(); abstract boolean hasContentsFolder(); abstract boolean includesVersionInArtifactName(); void setFlattingResources(final Boolean flattenResources);  }
@Test public void testCreateNewResourceIfCannotFindOne() throws Exception { Resource resource = AbstractDefineResourcesMojo.findOrCreateResource(resources, RESOURCES_DIRECTORY); assertThat(resource, is(mockResource)); }
@Test public void testDirectoryForNewResource() throws Exception { String resourceDirectoryNotAvailable = "src/main/another-folder"; Resource resource = AbstractDefineResourcesMojo.findOrCreateResource(resources, resourceDirectoryNotAvailable); assertThat(resource.getDirectory(), is(resourceDirectoryNotAvailable)); }
@Test(expected = IllegalArgumentException.class) public void testExceptionForNullResourceDirectory() throws Exception { try { AbstractDefineResourcesMojo.findOrCreateResource(resources, null); fail("Resources directory cannot be null. Must throw an exception."); } catch (IllegalArgumentException exception) { } }
@Test public void testFindAlreadyDefinedResource() throws Exception { Resource resource = AbstractDefineResourcesMojo.findOrCreateResource(resources, "src/main/another-folder"); assertThat(resource, not(mockResource)); assertThat(resource, notNullValue()); }