コード例 #1
0
  /** Test Normal on not generated existing / Marker on generated */
  @Test
  public void testNormalNotGeneratedExisitingMarkerGenerated() {
    String resultContent = null;

    // Read initial content, final content and call Java merger
    try {
      Set<String> predefinedAnnotations = new HashSet<String>(6);
      predefinedAnnotations.add("javax.annotation.Resource");
      predefinedAnnotations.add("Resource");
      predefinedAnnotations.add("javax.xml.ws.BindingType");
      predefinedAnnotations.add("BindingType");
      predefinedAnnotations.add("javax.xml.bind.annotation.XmlMimeType");
      predefinedAnnotations.add("XmlMimeType");
      resultContent =
          new JavaCodeMerger(predefinedAnnotations)
              .merge(
                  getFileContent(INPUT_TEST_PATH + "AnnotationUsageTestClass.java"),
                  getFileContent(OUTPUT_TEST_PATH + "AnnotationUsageTestClass.java"));
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    // Check the result of the merge process
    JavaCodeChecker jcc = new JavaCodeChecker(resultContent);
    String typeName = "AnnotationUsageTestClass10";
    TypeChecker tc = (TypeChecker) jcc.getTypeChecker(typeName);

    // Test type normal annotation availability
    java.util.Map<String, Object> expectedContent = new java.util.HashMap<String, Object>(3);
    expectedContent.put("name", "foo");

    assertTrue(
        typeName + " doesn't contain normal annotation javax.annotation.Resource",
        tc.isAnnotated("javax.annotation.Resource", expectedContent));

    String fieldName = "annotationUsageTestField10";
    FieldChecker fc = jcc.getTypeChecker(typeName).getFieldChecker(fieldName);

    // Test field normal annotation availability
    expectedContent = new java.util.HashMap<String, Object>(3);
    expectedContent.put("name", "foo");

    assertTrue(
        fieldName + " doesn't contain normal annotation javax.annotation.Resource",
        fc.isAnnotated("javax.annotation.Resource", expectedContent));

    String methodName = "annotationUsageTestMethod10";
    MethodChecker mc = jcc.getTypeChecker(typeName).getMethodChecker(methodName);

    // Test method normal annotation availability
    expectedContent = new java.util.HashMap<String, Object>(3);
    expectedContent.put("name", "foo");

    assertTrue(
        methodName + " doesn't contain normal annotation javax.annotation.Resource",
        mc.isAnnotated("javax.annotation.Resource", expectedContent));
  }
コード例 #2
0
  /** Test Empty on not generated existing / Single Member on generated */
  @Test
  public void testEmptyNotGeneratedExisitingSingleMemberGenerated() {
    String resultContent = null;

    // Read initial content, final content and call Java merger
    try {
      Set<String> predefinedAnnotations = new HashSet<String>(6);
      predefinedAnnotations.add("javax.annotation.Resource");
      predefinedAnnotations.add("Resource");
      predefinedAnnotations.add("javax.xml.ws.BindingType");
      predefinedAnnotations.add("BindingType");
      predefinedAnnotations.add("javax.xml.bind.annotation.XmlMimeType");
      predefinedAnnotations.add("XmlMimeType");
      resultContent =
          new JavaCodeMerger(predefinedAnnotations)
              .merge(
                  getFileContent(INPUT_TEST_PATH + "AnnotationUsageTestClass.java"),
                  getFileContent(OUTPUT_TEST_PATH + "AnnotationUsageTestClass.java"));
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    // Check the result of the merge process
    JavaCodeChecker jcc = new JavaCodeChecker(resultContent);
    String typeName = "AnnotationUsageTestClass23";
    TypeChecker tc = (TypeChecker) jcc.getTypeChecker(typeName);

    // Test type single member annotation availability
    assertFalse(
        typeName + " contains single member annotation javax.xml.ws.BindingType(\"bar\")",
        tc.isAnnotated("javax.xml.ws.BindingType", "bar"));

    String fieldName = "annotationUsageTestField23";
    FieldChecker fc = jcc.getTypeChecker(typeName).getFieldChecker(fieldName);

    // Test field single member annotation availability
    assertFalse(
        fieldName
            + " contains single member annotation javax.xml.bind.annotation.XmlMimeType(\"bar\")",
        fc.isAnnotated("javax.xml.bind.annotation.XmlMimeType", "bar"));

    String methodName = "annotationUsageTestMethod23";
    MethodChecker mc = jcc.getTypeChecker(typeName).getMethodChecker(methodName);

    // Test method single member annotation availability
    assertFalse(
        methodName
            + " contains single member annotation javax.xml.bind.annotation.XmlMimeType(\"bar\")",
        mc.isAnnotated("javax.xml.bind.annotation.XmlMimeType", "bar"));
  }
コード例 #3
0
  /** Test Single Member on existing / Empty on generated / Not predefined */
  @Test
  public void testSingleMemberExisitingEmptyGeneratedNotPredefined() {
    String resultContent = null;

    // Read initial content, final content and call Java merger
    try {
      resultContent =
          new JavaCodeMerger()
              .merge(
                  getFileContent(INPUT_TEST_PATH + "AnnotationUsageTestClass.java"),
                  getFileContent(OUTPUT_TEST_PATH + "AnnotationUsageTestClass.java"));
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    // Check the result of the merge process
    JavaCodeChecker jcc = new JavaCodeChecker(resultContent);
    String typeName = "AnnotationUsageTestClass17";
    TypeChecker tc = (TypeChecker) jcc.getTypeChecker(typeName);

    // Test type single member annotation availability
    assertTrue(
        typeName + " doesn't contain single member annotation javax.xml.ws.BindingType(\"foo\")",
        tc.isAnnotated("javax.xml.ws.BindingType", "foo"));

    String fieldName = "annotationUsageTestField17";
    FieldChecker fc = jcc.getTypeChecker(typeName).getFieldChecker(fieldName);

    // Test field single member annotation availability
    assertTrue(
        fieldName
            + " doesn't contain single member annotation javax.xml.bind.annotation.XmlMimeType(\"foo\")",
        fc.isAnnotated("javax.xml.bind.annotation.XmlMimeType", "foo"));

    String methodName = "annotationUsageTestMethod17";
    MethodChecker mc = jcc.getTypeChecker(typeName).getMethodChecker(methodName);

    // Test method single member annotation availability
    assertTrue(
        methodName
            + " doesn't contain single member annotation javax.xml.bind.annotation.XmlMimeType(\"foo\")",
        mc.isAnnotated("javax.xml.bind.annotation.XmlMimeType", "foo"));
  }