KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > getters > BooleanAttributeValueTest


1 /*
2  * BooleanAttributeValueTest.java
3  *
4  * Created on April 6, 2006, 1:06 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.jmi.javamodel.getters;
11
12 import java.io.PrintStream JavaDoc;
13 import java.util.List JavaDoc;
14 import org.netbeans.jmi.javamodel.Annotation;
15 import org.netbeans.jmi.javamodel.AttributeValue;
16 import org.netbeans.jmi.javamodel.BooleanLiteral;
17 import org.netbeans.jmi.javamodel.JavaClass;
18 import org.netbeans.jmi.javamodel.JavaModelPackage;
19 import org.netbeans.jmi.javamodel.PrimitiveTypeKindEnum;
20 import org.netbeans.jmi.javamodel.codegen.*;
21 import org.netbeans.junit.NbTestCase;
22 import org.netbeans.junit.NbTestSuite;
23 import org.openide.filesystems.FileStateInvalidException;
24
25 /**
26  *
27  * @author Pavel Flaska
28  */

29 public class BooleanAttributeValueTest extends NbTestCase {
30     
31     JavaClass clazz;
32     JavaModelPackage pkg;
33     
34     /** Creates a new instance of BooleanAttributeValueTest */
35     public BooleanAttributeValueTest() {
36         super("BooleanAttributeValueTest");
37     }
38     
39     public static NbTestSuite suite() {
40         NbTestSuite suite = new NbTestSuite(BooleanAttributeValueTest.class);
41         return suite;
42     }
43     
44     protected void setUp() {
45         clazz = (JavaClass) Utility.findClass("org.netbeans.test.getters.BooleanAttributeValue");
46         pkg = (JavaModelPackage) clazz.refImmediatePackage();
47     }
48     
49     public void testGetAttrBoolValue() throws java.io.IOException JavaDoc, FileStateInvalidException {
50         PrintStream JavaDoc log = getLog();
51         Utility.beginTrans(false);
52         boolean result = false;
53         try {
54             List JavaDoc l = clazz.getAnnotations();
55             log.println("Class BooleanAttributeValue has " + l.size() + " annotations.");
56             if (l.size() > 0) { // be sure there is an annotation
57
Annotation ann = (Annotation) l.get(0);
58                 List JavaDoc attrs = ann.getAttributeValues();
59                 if (attrs.size() > 0) { // be sure annotation contain attribute
60
AttributeValue attrVal = (AttributeValue) ann.getAttributeValues().get(0);
61                     log.print("\tAttribute '" + attrVal.getDefinition().getName() + "' has the following value: '");
62                     if (attrVal.getValue() instanceof BooleanLiteral) {
63                         BooleanLiteral bool = (BooleanLiteral) attrVal.getValue();
64                         result = bool.isValue();
65                         log.println(bool.isValue() + "'.");
66                     } else {
67                         log.println(attrVal.getValue() + "'.");
68                     }
69                 }
70             }
71         } finally {
72             Utility.endTrans();
73         }
74         assertEquals(result, true);
75     }
76     
77     
78 }
79
Popular Tags