1   /*
2    * Copyright (C) The MetaClass Group. All rights reserved.
3    *
4    * This software is published under the terms of the Spice
5    * Software License version 1.1, a copy of which has been included
6    * with this distribution in the LICENSE.txt file.
7    */
8   package org.codehaus.metaclass.model;
9   
10  import junit.framework.TestCase;
11  
12  /***
13   * @author Peter Donald
14   * @version $Revision: 1.2 $ $Date: 2003/11/28 11:14:54 $
15   */
16  public class FeatureDescriptorTestCase
17      extends TestCase
18  {
19      public void testFeatureDescriptor()
20          throws Exception
21      {
22          final Attribute[] attributes = new Attribute[]{new Attribute( "moo" )};
23          final MockFeature feature = new MockFeature( attributes, attributes );
24          assertEquals( "declared.length vs actual.length",
25                        feature.getDeclaredAttributes().length,
26                        feature.getAttributes().length );
27      }
28  
29      public void testFeatureDescriptorWithInheritedAttribute()
30          throws Exception
31      {
32          final Attribute[] declaredAttributes = new Attribute[]{
33              new Attribute( "moo" )};
34          final Attribute[] attributes = new Attribute[]
35          {
36              new Attribute( "baz" ),
37              declaredAttributes[ 0 ],
38              new Attribute( "bar" )
39          };
40          final MockFeature feature = new MockFeature( declaredAttributes,
41                                                       attributes );
42          assertEquals( "declared.length + 2 == actual.length",
43                        feature.getDeclaredAttributes().length + 2,
44                        feature.getAttributes().length );
45      }
46  
47      public void testNullDeclaredAttributesPassedToCtor()
48          throws Exception
49      {
50          try
51          {
52              new MockFeature( null, Attribute.EMPTY_SET );
53          }
54          catch( final NullPointerException npe )
55          {
56              assertEquals( "npe.getMessage()",
57                            "declaredAttributes",
58                            npe.getMessage() );
59              return;
60          }
61          fail(
62              "Expected to fail due to null DeclaredAttributes passed into Ctor" );
63      }
64  
65      public void testNullInDeclaredAttributesPassedToCtor()
66          throws Exception
67      {
68          try
69          {
70              new MockFeature( new Attribute[]{null}, Attribute.EMPTY_SET );
71          }
72          catch( final NullPointerException npe )
73          {
74              assertEquals( "npe.getMessage()",
75                            "declaredAttributes[0]",
76                            npe.getMessage() );
77              return;
78          }
79          fail(
80              "Expected to fail due to null in DeclaredAttributes passed into Ctor" );
81      }
82  
83      public void testNullAttributesPassedToCtor()
84          throws Exception
85      {
86          try
87          {
88              new MockFeature( Attribute.EMPTY_SET, null );
89          }
90          catch( final NullPointerException npe )
91          {
92              assertEquals( "npe.getMessage()", "attributes", npe.getMessage() );
93              return;
94          }
95          fail( "Expected to fail due to null Attributes passed into Ctor" );
96      }
97  
98      public void testNullInAttributesPassedToCtor()
99          throws Exception
100     {
101         try
102         {
103             new MockFeature( Attribute.EMPTY_SET, new Attribute[]{null} );
104         }
105         catch( final NullPointerException npe )
106         {
107             assertEquals( "npe.getMessage()",
108                           "attributes[0]",
109                           npe.getMessage() );
110             return;
111         }
112         fail( "Expected to fail due to null in Attributes passed into Ctor" );
113     }
114 
115     public void testDeclaredAttributesNotAnAttribute()
116         throws Exception
117     {
118         try
119         {
120             final Attribute[] declaredAttributes = new Attribute[]
121             {
122                 new Attribute( "baz" )
123             };
124             new MockFeature( declaredAttributes, Attribute.EMPTY_SET );
125         }
126         catch( final IllegalArgumentException iae )
127         {
128             assertEquals( "iae.getMessage()",
129                           "declaredAttribute[0] not an attribute",
130                           iae.getMessage() );
131             return;
132         }
133         fail(
134             "Expected to fail due to DeclaredAttributes not an attribute passed into Ctor" );
135     }
136 }