Exemplo n.º 1
0
  private void _classListLocate(Class<?> clazz, List<? extends Annotation> expectedAnnotations) {

    List<Annotation> actualAnnotations = AnnotationLocator.locate(clazz);

    Assert.assertEquals(clazz.getName(), expectedAnnotations.size(), actualAnnotations.size());

    for (int i = 0; i < expectedAnnotations.size(); i++) {
      Annotation expectedAnnotation = expectedAnnotations.get(i);
      Annotation actualAnnotation = actualAnnotations.get(i);

      Assert.assertEquals(
          clazz.getName(), expectedAnnotation.annotationType(), actualAnnotation.annotationType());

      if (expectedAnnotation.annotationType() == Mix.class) {
        Mix expectedMix = (Mix) expectedAnnotation;
        Mix actualMix = (Mix) actualAnnotation;

        Assert.assertEquals("@Mix : " + clazz.getName(), expectedMix.value(), actualMix.value());
      } else {
        Type expectedType = (Type) expectedAnnotation;
        Type actualType = (Type) actualAnnotation;

        Assert.assertEquals("@Type : ", expectedType.value(), actualType.value());
      }
    }
  }
Exemplo n.º 2
0
 public TypeBitmap(Tokenizer st) throws IOException {
   this();
   while (true) {
     Tokenizer.Token t = st.get();
     if (!t.isString()) break;
     int typecode = Type.value(t.value);
     if (typecode < 0) {
       throw st.exception("Invalid type: " + t.value);
     }
     types.add(Mnemonic.toInteger(typecode));
   }
   st.unget();
 }
Exemplo n.º 3
0
  private void _classSingleLocate(Class<?> clazz, int expectedMixValue, int expectedTypeValue) {

    Mix actualMix = AnnotationLocator.locate(clazz, Mix.class);

    if (expectedMixValue == -1) {
      Assert.assertNull("@Mix : " + clazz.getName(), actualMix);
    } else {
      Assert.assertEquals("@Mix : " + clazz.getName(), expectedMixValue, actualMix.value());
    }

    Type actualType = AnnotationLocator.locate(clazz, Type.class);

    if (expectedTypeValue == -1) {
      Assert.assertNull("@Type : " + clazz.getName(), actualType);
    } else {
      Assert.assertEquals("@Type : " + clazz.getName(), expectedTypeValue, actualType.value());
    }
  }
Exemplo n.º 4
0
  private void _methodSingleLocate(
      Class<?> clazz,
      int[] expectedMethodValues,
      int[] expectedMixValues,
      int[] expectedTypeValues) {

    for (int i = 0; i < 6; i++) {
      java.lang.reflect.Method method = _interfaceMethods[i];
      int expectedMethodValue = expectedMethodValues[i];

      Method methodAnnotation = AnnotationLocator.locate(method, clazz, Method.class);

      if (methodAnnotation == null) {
        Assert.assertEquals("@Method : " + clazz.getName(), -1, expectedMethodValue);

        continue;
      }

      Assert.assertEquals(
          "@Method : " + method.getName() + "()@" + clazz.getName(),
          expectedMethodValue,
          methodAnnotation.value());

      try {
        method = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());

        methodAnnotation = AnnotationLocator.locate(method, null, Method.class);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(),
            expectedMethodValue,
            methodAnnotation.value());
      } catch (Exception e) {
      }
    }

    for (int i = 0; i < 6; i++) {
      java.lang.reflect.Method method = _interfaceMethods[i];
      int expectedMixValue = expectedMixValues[i];

      Mix mixAnnotation = AnnotationLocator.locate(method, clazz, Mix.class);

      if (mixAnnotation == null) {
        Assert.assertEquals("@Mix : " + clazz.getName(), -1, expectedMixValue);

        continue;
      }

      Assert.assertEquals(
          "@Mix : " + method.getName() + "()@" + clazz.getName(),
          expectedMixValue,
          mixAnnotation.value());

      try {
        method = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());

        mixAnnotation = AnnotationLocator.locate(method, null, Mix.class);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(), expectedMixValue, mixAnnotation.value());
      } catch (Exception e) {
      }
    }

    for (int i = 0; i < 6; i++) {
      java.lang.reflect.Method method = _interfaceMethods[i];
      int expectedTypeValue = expectedTypeValues[i];

      Type typeAnnotation = AnnotationLocator.locate(method, clazz, Type.class);

      if (typeAnnotation == null) {
        Assert.assertEquals("@Type : " + clazz.getName(), -1, expectedTypeValue);

        continue;
      }

      Assert.assertEquals(
          "@Type : " + method.getName() + "()@" + clazz.getName(),
          expectedTypeValue,
          typeAnnotation.value());

      try {
        method = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());

        typeAnnotation = AnnotationLocator.locate(method, null, Type.class);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(), expectedTypeValue, typeAnnotation.value());
      } catch (Exception e) {
      }
    }
  }
Exemplo n.º 5
0
  private void _methodListLocate(Class<?> clazz, List<Annotation[]> expectedAnnotationsList) {

    for (int i = 0; i < _interfaceMethods.length; i++) {
      Annotation[] expectedAnnotations = expectedAnnotationsList.get(i);

      java.lang.reflect.Method method = _interfaceMethods[i];
      List<Annotation> actualAnnotations = AnnotationLocator.locate(method, clazz);

      Assert.assertEquals(
          method.getName() + "()@" + clazz.getName(),
          expectedAnnotations.length,
          actualAnnotations.size());

      for (int j = 0; j < expectedAnnotations.length; j++) {
        Annotation expectedAnnotation = expectedAnnotations[j];
        Annotation actualAnnotation = actualAnnotations.get(j);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(),
            expectedAnnotation.annotationType(),
            actualAnnotation.annotationType());

        if (expectedAnnotation.annotationType() == Mix.class) {
          Mix expectedMix = (Mix) expectedAnnotation;
          Mix actualMix = (Mix) actualAnnotation;

          Assert.assertEquals(
              "@Mix : " + method.getName() + "()@" + clazz.getName(),
              expectedMix.value(),
              actualMix.value());
        } else if (expectedAnnotation.annotationType() == Method.class) {
          Method expectedType = (Method) expectedAnnotation;
          Method actualMethod = (Method) actualAnnotation;

          Assert.assertEquals(
              "@Method : " + method.getName() + "()@" + clazz.getName(),
              expectedType.value(),
              actualMethod.value());
        } else {
          Type expectedType = (Type) expectedAnnotation;
          Type actualType = (Type) actualAnnotation;

          Assert.assertEquals(
              "@Type : " + method.getName() + "()@" + clazz.getName(),
              expectedType.value(),
              actualType.value());
        }
      }

      try {
        method = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());

        actualAnnotations = AnnotationLocator.locate(method, null);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(),
            expectedAnnotations.length,
            actualAnnotations.size());

        for (int j = 0; j < expectedAnnotations.length; j++) {
          Annotation expectedAnnotation = expectedAnnotations[j];
          Annotation actualAnnotation = actualAnnotations.get(j);

          Assert.assertEquals(
              method.getName() + "()@" + clazz.getName(),
              expectedAnnotation.annotationType(),
              actualAnnotation.annotationType());

          if (expectedAnnotation.annotationType() == Mix.class) {
            Mix expectedMix = (Mix) expectedAnnotation;
            Mix actualMix = (Mix) actualAnnotation;

            Assert.assertEquals(
                "@Mix : " + method.getName() + "()@" + clazz.getName(),
                expectedMix.value(),
                actualMix.value());
          } else if (expectedAnnotation.annotationType() == Method.class) {

            Method expectedType = (Method) expectedAnnotation;
            Method actualMethod = (Method) actualAnnotation;

            Assert.assertEquals(
                "@Method : " + method.getName() + "()@" + clazz.getName(),
                expectedType.value(),
                actualMethod.value());
          } else {
            Type expectedType = (Type) expectedAnnotation;
            Type actualType = (Type) actualAnnotation;

            Assert.assertEquals(
                "@Type : " + method.getName() + "()@" + clazz.getName(),
                expectedType.value(),
                actualType.value());
          }
        }
      } catch (Exception e) {
      }
    }
  }