You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AnnotationDefaultAttributeTest.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement - initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.apache.bcel.classfile.tests;
  13. import org.aspectj.apache.bcel.classfile.AnnotationDefault;
  14. import org.aspectj.apache.bcel.classfile.JavaClass;
  15. import org.aspectj.apache.bcel.classfile.Method;
  16. import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
  17. import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue;
  18. public class AnnotationDefaultAttributeTest extends BcelTestCase {
  19. protected void setUp() throws Exception {
  20. super.setUp();
  21. }
  22. /**
  23. * For values in an annotation that have default values, we should be able to
  24. * query the AnnotationDefault attribute against the method to discover the
  25. * default value that was originally declared.
  26. */
  27. public void testMethodAnnotations() throws ClassNotFoundException {
  28. JavaClass clazz = getClassFromJar("SimpleAnnotation");
  29. Method m = getMethod(clazz,"fruit");
  30. AnnotationDefault a = (AnnotationDefault) findAttribute("AnnotationDefault",m.getAttributes());
  31. SimpleElementValue val = (SimpleElementValue) a.getElementValue();
  32. assertTrue("Should be STRING but is "+val.getElementValueType(),
  33. val.getElementValueType()==ElementValue.STRING);
  34. assertTrue("Should have default of bananas but default is "+val.getValueString(),
  35. val.getValueString().equals("bananas"));
  36. }
  37. protected void tearDown() throws Exception {
  38. super.tearDown();
  39. }
  40. }