コード例 #1
0
 @Test
 public void hasAndFindForPluginWithoutId() {
   Plugin plugin = getPluginWithoutId();
   Class<? extends Plugin> pluginType = plugin.getClass();
   addWithType(pluginType);
   assertThat(getPluginContainer().hasPlugin(pluginType.getName()), equalTo(true));
   assertThat(getPluginContainer().hasPlugin(pluginType), equalTo(true));
   assertThat(getPluginContainer().findPlugin(pluginType), sameInstance(plugin));
   assertThat(getPluginContainer().findPlugin(pluginType.getName()), sameInstance(plugin));
 }
コード例 #2
0
  @Test
  public void refToFragmentOfAnotherSchemaIsReadSuccessfully() throws NoSuchMethodException {

    Class<?> aClass = fragmentRefsClass.getMethod("getFragmentOfA").getReturnType();

    assertThat(aClass.getName(), is("com.example.AdditionalPropertyValue"));
  }
コード例 #3
0
  @Test
  public void nestedSelfRefsInStringContentWithoutParentFile()
      throws NoSuchMethodException, ClassNotFoundException, IOException {

    String schemaContents =
        IOUtils.toString(
            CodeGenerationHelper.class.getResource("/schema/ref/nestedSelfRefsReadAsString.json"));
    JCodeModel codeModel = new JCodeModel();
    new SchemaMapper().generate(codeModel, "NestedSelfRefsInString", "com.example", schemaContents);

    codeModel.build(schemaRule.getGenerateDir());

    ClassLoader classLoader = schemaRule.compile();

    Class<?> nestedSelfRefs = classLoader.loadClass("com.example.NestedSelfRefsInString");
    assertThat(
        nestedSelfRefs.getMethod("getThings").getReturnType().getSimpleName(), equalTo("List"));

    Class<?> listEntryType =
        (Class<?>)
            ((ParameterizedType) nestedSelfRefs.getMethod("getThings").getGenericReturnType())
                .getActualTypeArguments()[0];
    assertThat(listEntryType.getName(), equalTo("com.example.Thing"));

    Class<?> thingClass = classLoader.loadClass("com.example.Thing");
    assertThat(
        thingClass.getMethod("getNamespace").getReturnType().getSimpleName(), equalTo("String"));
    assertThat(thingClass.getMethod("getName").getReturnType().getSimpleName(), equalTo("String"));
    assertThat(
        thingClass.getMethod("getVersion").getReturnType().getSimpleName(), equalTo("String"));
  }
コード例 #4
0
  @Test
  public void selfRefUsedInAPropertyIsReadSuccessfully() throws NoSuchMethodException {

    Class<?> aClass = selfRefsClass.getMethod("getChildOfSelf").getReturnType();

    assertThat(aClass.getName(), is("com.example.SelfRefs"));
  }
コード例 #5
0
  @Test
  public void refToFragmentOfSelfIsReadSuccessfully() throws NoSuchMethodException {

    Class<?> aClass = fragmentRefsClass.getMethod("getFragmentOfSelf").getReturnType();

    assertThat(aClass.getName(), is("com.example.A"));
    assertThat(aClass.getMethods(), hasItemInArray(hasProperty("name", equalTo("getPropertyOfA"))));
  }
コード例 #6
0
 @Test
 public void addPluginWithoutId() {
   Class<? extends Plugin> type = getPluginWithoutId().getClass();
   Plugin addedPlugin = addWithType(type);
   assertThat(getPluginWithoutId(), sameInstance(addedPlugin));
   assertThat(addedPlugin, sameInstance((Plugin) addWithType(type)));
   assertThat(addedPlugin, sameInstance(getPluginContainer().findByName(type.getName())));
 }
コード例 #7
0
  @Test
  public void selfRefUsedAsArrayItemsIsReadSuccessfully() throws NoSuchMethodException {

    Type listOfAType = selfRefsClass.getMethod("getArrayOfSelf").getGenericReturnType();
    Class<?> listEntryClass =
        (Class<?>) ((ParameterizedType) listOfAType).getActualTypeArguments()[0];

    assertThat(listEntryClass.getName(), is("com.example.SelfRefs"));
  }
コード例 #8
0
  @Test
  public void selfRefUsedForAdditionalPropertiesIsReadSuccessfully() throws NoSuchMethodException {

    Type additionalPropertiesType =
        selfRefsClass.getMethod("getAdditionalProperties").getGenericReturnType();
    Class<?> mapEntryClass =
        (Class<?>) ((ParameterizedType) additionalPropertiesType).getActualTypeArguments()[1];

    assertThat(mapEntryClass.getName(), is("com.example.SelfRefs"));
  }
コード例 #9
0
 private File createFileForClass(Class<TestFakeProduct> clazz) throws IOException {
   File destFile = InfinitestTestUtils.getFileForClass(altClassDir, clazz.getName());
   assertTrue(destFile.getParentFile().mkdirs());
   assertTrue(destFile.createNewFile());
   return destFile;
 }
コード例 #10
0
 private AnnotationAttributes findMergedAnnotationAttributes(
     AnnotatedElement element, Class<? extends Annotation> annotationType) {
   Assert.notNull(annotationType, "annotationType must not be null");
   return AnnotatedElementUtils.findMergedAnnotationAttributes(
       element, annotationType.getName(), false, false);
 }
コード例 #11
0
 void setTracker(Class<? extends ExecutionTracker> tracker) {
   this.replacement.put("tracker", tracker.getName());
 }