Пример #1
1
 public <T extends AbstractTask> T createTask(Class<T> type, Project project, String name) {
   Task task =
       TASK_FACTORY.createTask(
           (ProjectInternal) project, GUtil.map(Task.TASK_TYPE, type, Task.TASK_NAME, name));
   assertTrue(type.isAssignableFrom(task.getClass()));
   return type.cast(task);
 }
 private <T extends AbstractGolangMojo> T findMojo(
     final Class<T> klazz, final String pomName, final String goal) throws Exception {
   final File pomFile = new File(GolangMojoCfgTest.class.getResource(pomName).toURI());
   final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
   final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
   final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
   final MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
   return klazz.cast(this.lookupConfiguredMojo(project, goal));
 }
Пример #3
0
  private <T extends AstTerm<?>> T loadFirstTermAs(Class<T> termKind) {
    AstScript script = load();
    assertThat(script.models.size(), greaterThanOrEqualTo(1));
    AstModelDefinition<?> firstModel = script.models.get(0);

    List<? extends AstTerm<?>> terms = extract(firstModel.expression);
    assertThat(terms.size(), greaterThanOrEqualTo(1));
    AstTerm<?> term = terms.get(0);

    return termKind.cast(term);
  }
 protected <T extends RuntimeException> T catches(Closure c, Class<T> rex) {
   T t = null;
   try {
     c.f();
   } catch (RuntimeException ex) {
     ex.printStackTrace();
     assertTrue(
         ex.getClass().getName() + " is not assignable to runtime exception " + rex.getName(),
         ex.getClass().isAssignableFrom(rex));
     t = rex.cast(ex);
   }
   assertNotNull("No exception was caught of class " + rex.getName(), t);
   return t;
 }
Пример #5
0
 public boolean temps_equal(Object a, Object b)
     throws IllegalArgumentException, IllegalAccessException {
   for (Field f : temps.getFields())
     if (!f.get(temps.cast(a)).equals(f.get(temps.cast(b)))) return false;
   return true;
 }
Пример #6
0
 public <T> T unwrap(Class<T> clazz) {
   if (clazz.isInstance(this)) {
     return clazz.cast(this);
   }
   return parent.unwrap(clazz);
 }