@Test
  public void testAddArtifacts() {
    final PublishArtifact publishArtifactConf1 = createNamedPublishArtifact("conf1");
    Configuration configurationStub1 = createConfigurationStub(publishArtifactConf1);
    final PublishArtifact publishArtifactConf2 = createNamedPublishArtifact("conf2");
    Configuration configurationStub2 = createConfigurationStub(publishArtifactConf2);
    final ArtifactsExtraAttributesStrategy artifactsExtraAttributesStrategyMock =
        context.mock(ArtifactsExtraAttributesStrategy.class);
    final Map<String, String> extraAttributesArtifact1 =
        WrapUtil.toMap("name", publishArtifactConf1.getName());
    final Map<String, String> extraAttributesArtifact2 =
        WrapUtil.toMap("name", publishArtifactConf2.getName());
    context.checking(
        new Expectations() {
          {
            one(artifactsExtraAttributesStrategyMock).createExtraAttributes(publishArtifactConf1);
            will(returnValue(extraAttributesArtifact1));
            one(artifactsExtraAttributesStrategyMock).createExtraAttributes(publishArtifactConf2);
            will(returnValue(extraAttributesArtifact2));
          }
        });
    DefaultModuleDescriptor moduleDescriptor =
        HelperUtil.createModuleDescriptor(
            WrapUtil.toSet(configurationStub1.getName(), configurationStub2.getName()));

    DefaultArtifactsToModuleDescriptorConverter artifactsToModuleDescriptorConverter =
        new DefaultArtifactsToModuleDescriptorConverter(artifactsExtraAttributesStrategyMock);

    artifactsToModuleDescriptorConverter.addArtifacts(
        moduleDescriptor, WrapUtil.toSet(configurationStub1, configurationStub2));

    assertArtifactIsAdded(configurationStub1, moduleDescriptor, extraAttributesArtifact1);
    assertArtifactIsAdded(configurationStub2, moduleDescriptor, extraAttributesArtifact2);
    assertThat(moduleDescriptor.getAllArtifacts().length, equalTo(2));
  }
Ejemplo n.º 2
0
  @Test
  public void originalObjectIsSetAsDelegateForClosure() {
    Closure closure = HelperUtil.toClosure("{ substring(1, 3) }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("ri"));
  }
Ejemplo n.º 3
0
 @Before
 public void setUp() throws Exception {
   generator = context.mock(Runnable.class);
   renderer = context.mock(ProjectReportRenderer.class);
   task = HelperUtil.createTask(TestReportTask.class, project);
   task.setGenerator(generator);
   task.setRenderer(renderer);
 }
Ejemplo n.º 4
0
  @Test
  public void usesOriginalObjectWhenClosureReturnsObjectOfUnexpectedType() {
    Closure closure = HelperUtil.toClosure("{ 9 }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("original"));
  }
Ejemplo n.º 5
0
  @Test
  public void closureCanTransformAStringIntoAGString() {
    Closure closure = HelperUtil.toClosure("{ \"[$it]\" }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("[original]"));
  }
Ejemplo n.º 6
0
  @Test
  public void usesOriginalObjectWhenClosureReturnsNull() {
    Closure closure = HelperUtil.toClosure("{ null }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("original"));
  }
Ejemplo n.º 7
0
  @Test
  public void canUseAClosureAsATransformer() {
    Closure closure = HelperUtil.toClosure("{ it + ' transformed' }");

    transformer.add(closure);

    assertThat(transformer.transform("original"), equalTo("original transformed"));
  }
Ejemplo n.º 8
0
  @Test
  public void testPath() {
    DefaultProject rootProject = HelperUtil.createRootProject();
    DefaultProject childProject = HelperUtil.createChildProject(rootProject, "child");
    childProject.getProjectDir().mkdirs();
    DefaultProject childchildProject = HelperUtil.createChildProject(childProject, "childchild");
    childchildProject.getProjectDir().mkdirs();

    Task task = createTask(rootProject, TEST_TASK_NAME);
    assertEquals(Project.PATH_SEPARATOR + TEST_TASK_NAME, task.getPath());
    task = createTask(childProject, TEST_TASK_NAME);
    assertEquals(
        Project.PATH_SEPARATOR + "child" + Project.PATH_SEPARATOR + TEST_TASK_NAME, task.getPath());
    task = createTask(childchildProject, TEST_TASK_NAME);
    assertEquals(
        Project.PATH_SEPARATOR
            + "child"
            + Project.PATH_SEPARATOR
            + "childchild"
            + Project.PATH_SEPARATOR
            + TEST_TASK_NAME,
        task.getPath());
  }
Ejemplo n.º 9
0
 @Before
 public void setUp() {
   super.setUp();
   projectDependencyMock = context.mock(DefaultProjectDependency.class);
   testProject = HelperUtil.createRootProject(new File("dependent"));
   context.checking(
       new Expectations() {
         {
           allowing(projectDependencyMock).getDependencyProject();
           will(returnValue(testProject));
         }
       });
   eclipseWtp = createTask(EclipseWtp.class);
 }
Ejemplo n.º 10
0
  @Test
  public void getSizeReturnsSizeOfFilteredContent() {
    final FileCopyDetails mappedDetails = expectActionExecutedWhenFileVisited();

    context.checking(
        new Expectations() {
          {
            one(details).open();
            will(returnValue(new ByteArrayInputStream("content".getBytes())));
          }
        });

    mappedDetails.filter(HelperUtil.toClosure("{ 'PREFIX: ' + it } "));

    assertThat(mappedDetails.getSize(), equalTo(15L));
  }
Ejemplo n.º 11
0
  @org.junit.Test
  public void notifiesListenerBeforeTest() {
    final TestClosure closure = context.mock(TestClosure.class);
    test.beforeTest(HelperUtil.toClosure(closure));

    final TestDescriptor testDescriptor = context.mock(TestDescriptor.class);

    context.checking(
        new Expectations() {
          {
            one(closure).call(testDescriptor);
          }
        });

    test.getTestListenerBroadcaster().getSource().beforeTest(testDescriptor);
  }
Ejemplo n.º 12
0
  @Test
  public void addsTaskWithNameAndConfigureClosure() {
    final Closure action = HelperUtil.toClosure("{ description = 'description' }");
    final Map<String, ?> options = GUtil.map(Task.TASK_NAME, "task");
    final Task task = task("task");

    context.checking(
        new Expectations() {
          {
            one(taskFactory).createTask(project, options);
            will(returnValue(task));
            one(task).configure(action);
            will(returnValue(task));
          }
        });
    assertThat(container.add("task", action), sameInstance(task));
  }
Ejemplo n.º 13
0
  @Test
  public void copyActionCanFilterContentWhenFileIsCopiedToStream() {
    final FileCopyDetails mappedDetails = expectActionExecutedWhenFileVisited();

    context.checking(
        new Expectations() {
          {
            one(details).open();
            will(returnValue(new ByteArrayInputStream("content".getBytes())));
          }
        });

    mappedDetails.filter(HelperUtil.toClosure("{ 'PREFIX: ' + it } "));

    ByteArrayOutputStream outstr = new ByteArrayOutputStream();
    mappedDetails.copyTo(outstr);
    assertThat(new String(outstr.toByteArray()), equalTo("PREFIX: content"));
  }
Ejemplo n.º 14
0
  @Test
  public void copyActionCanFilterContentWhenFileIsCopiedToFile() {
    final FileCopyDetails mappedDetails = expectActionExecutedWhenFileVisited();

    context.checking(
        new Expectations() {
          {
            one(details).open();
            will(returnValue(new ByteArrayInputStream("content".getBytes())));
            one(details).isDirectory();
            will(returnValue(false));
            one(details).getLastModified();
            will(returnValue(90L));
          }
        });

    mappedDetails.filter(HelperUtil.toClosure("{ 'PREFIX: ' + it } "));

    TestFile destDir = tmpDir.getDir().file("test.txt");
    mappedDetails.copyTo(destDir);
    destDir.assertContents(equalTo("PREFIX: content"));
  }
Ejemplo n.º 15
0
// todo Make test stronger
public class OsgiPluginTest {
  private final Project project = HelperUtil.createRootProject();
  private final OsgiPlugin osgiPlugin = new OsgiPlugin();

  @Test
  public void appliesTheJavaPlugin() {
    osgiPlugin.apply(project, new PluginRegistry(), null);

    assertTrue(project.getAppliedPlugins().contains(JavaPlugin.class));
  }

  @Test
  public void addsAnOsgiManifestToEachJar() {
    osgiPlugin.apply(project, new PluginRegistry(), null);

    Task task = project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME);
    assertThat(task.property("osgi"), is(OsgiManifest.class));

    task = project.getTasks().add("otherJar", Jar.class);
    assertThat(task.property("osgi"), is(OsgiManifest.class));
  }
}
Ejemplo n.º 16
0
 @Before
 public void setUp() {
   project = HelperUtil.createRootProject();
 }
Ejemplo n.º 17
0
 @Test
 public void testCanSpecifyOnlyIfPredicateUsingClosure() {
   AbstractTask task = getTask();
   task.onlyIf(HelperUtil.toClosure("{ task -> false }"));
   assertFalse(task.getOnlyIf().isSatisfiedBy(task));
 }