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.tools.qdox;
9   
10  import junit.framework.TestCase;
11  import org.codehaus.metaclass.model.Attribute;
12  
13  /***
14   * @author Peter Donald
15   * @version $Revision: 1.2 $ $Date: 2003/11/28 11:14:55 $
16   */
17  public class MulticastInterceptorTestCase
18      extends TestCase
19  {
20      public void testMulticastInterceptorCtorWithNullInterceptors()
21          throws Exception
22      {
23          try
24          {
25              new MulticastInterceptor( null );
26          }
27          catch( final NullPointerException npe )
28          {
29              assertEquals( "npe.message", "interceptors", npe.getMessage() );
30              return;
31          }
32          fail( "Expected to fail due to npe in ctor" );
33      }
34  
35      public void testMulticastInterceptorCtorWithInterceptorsContainingNull()
36          throws Exception
37      {
38          try
39          {
40              new MulticastInterceptor( new QDoxAttributeInterceptor[]{null} );
41          }
42          catch( final NullPointerException npe )
43          {
44              assertEquals( "npe.message", "interceptors[0]", npe.getMessage() );
45              return;
46          }
47          fail( "Expected to fail due to npe in ctor" );
48      }
49  
50      public void testProcessClassAttribute()
51          throws Exception
52      {
53          final String name = "NotDeleteme";
54          final MulticastInterceptor mcInterceptor = createMCInterceptor();
55          final Attribute attribute =
56              mcInterceptor.processClassAttribute( null, new Attribute( name ) );
57          assertNotNull( "attribute", attribute );
58      }
59  
60      public void testProcessClassAttributeThatIsDeleted()
61          throws Exception
62      {
63          final String name = "deleteme";
64          final MulticastInterceptor mcInterceptor = createMCInterceptor();
65          final Attribute attribute =
66              mcInterceptor.processClassAttribute( null, new Attribute( name ) );
67          assertNull( "attribute", attribute );
68      }
69  
70      public void testProcessClassAttributes()
71          throws Exception
72      {
73          final MulticastInterceptor mcInterceptor = createMCInterceptor();
74          final Attribute[] attributes = new Attribute[]{
75              new Attribute( "ignore" )};
76          final Attribute[] result =
77              mcInterceptor.processClassAttributes( null, attributes );
78          assertNotNull( "attributes", result );
79          assertEquals( "attributes.length", attributes.length, result.length );
80      }
81  
82      public void testProcessMethodAttribute()
83          throws Exception
84      {
85          final String name = "NotDeleteme";
86          final MulticastInterceptor mcInterceptor = createMCInterceptor();
87          final Attribute attribute =
88              mcInterceptor.processMethodAttribute( null,
89                                                    new Attribute( name ) );
90          assertNotNull( "attribute", attribute );
91      }
92  
93      public void testProcessMethodAttributeThatIsDeleted()
94          throws Exception
95      {
96          final String name = "deleteme";
97          final MulticastInterceptor mcInterceptor = createMCInterceptor();
98          final Attribute attribute =
99              mcInterceptor.processMethodAttribute( null,
100                                                   new Attribute( name ) );
101         assertNull( "attribute", attribute );
102     }
103 
104     public void testProcessMethodAttributes()
105         throws Exception
106     {
107         final MulticastInterceptor mcInterceptor = createMCInterceptor();
108         final Attribute[] attributes = new Attribute[]{
109             new Attribute( "ignore" )};
110         final Attribute[] result =
111             mcInterceptor.processMethodAttributes( null, attributes );
112         assertNotNull( "attributes", result );
113         assertEquals( "attributes.length", attributes.length, result.length );
114     }
115 
116     public void testProcessFieldAttribute()
117         throws Exception
118     {
119         final String name = "NotDeleteme";
120         final MulticastInterceptor mcInterceptor = createMCInterceptor();
121         final Attribute attribute =
122             mcInterceptor.processFieldAttribute( null, new Attribute( name ) );
123         assertNotNull( "attribute", attribute );
124     }
125 
126     public void testProcessFieldAttributeThatIsDeleted()
127         throws Exception
128     {
129         final String name = "deleteme";
130         final MulticastInterceptor mcInterceptor = createMCInterceptor();
131         final Attribute attribute =
132             mcInterceptor.processFieldAttribute( null, new Attribute( name ) );
133         assertNull( "attribute", attribute );
134     }
135 
136     public void testProcessFieldAttributes()
137         throws Exception
138     {
139         final MulticastInterceptor mcInterceptor = createMCInterceptor();
140         final Attribute[] attributes = new Attribute[]{
141             new Attribute( "ignore" )};
142         final Attribute[] result =
143             mcInterceptor.processFieldAttributes( null, attributes );
144         assertNotNull( "attributes", result );
145         assertEquals( "attributes.length", attributes.length, result.length );
146     }
147 
148     private MulticastInterceptor createMCInterceptor()
149     {
150         return new MulticastInterceptor(
151             new QDoxAttributeInterceptor[]{new DeletingAttributeInterceptor()} );
152     }
153 }