View Javadoc

1   /*
2    *   Copyright (C) Christian Schulte, 2005-206
3    *   All rights reserved.
4    *
5    *   Redistribution and use in source and binary forms, with or without
6    *   modification, are permitted provided that the following conditions
7    *   are met:
8    *
9    *     o Redistributions of source code must retain the above copyright
10   *       notice, this list of conditions and the following disclaimer.
11   *
12   *     o Redistributions in binary form must reproduce the above copyright
13   *       notice, this list of conditions and the following disclaimer in
14   *       the documentation and/or other materials provided with the
15   *       distribution.
16   *
17   *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18   *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19   *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20   *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
21   *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22   *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23   *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24   *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25   *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26   *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27   *
28   *   $JOMC: ResourceFileProcessorTest.java 3838 2011-10-08 20:15:41Z schulte2005 $
29   *
30   */
31  package org.jomc.tools.test;
32  
33  import java.io.File;
34  import java.io.IOException;
35  import org.jomc.model.Implementation;
36  import org.jomc.model.Module;
37  import org.jomc.model.Specification;
38  import org.jomc.tools.ResourceFileProcessor;
39  import org.junit.Test;
40  import static org.junit.Assert.assertNotNull;
41  import static org.junit.Assert.assertTrue;
42  import static org.junit.Assert.fail;
43  
44  /**
45   * Test cases for class {@code org.jomc.tools.ResourceFileProcessor}.
46   *
47   * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
48   * @version $JOMC: ResourceFileProcessorTest.java 3838 2011-10-08 20:15:41Z schulte2005 $
49   */
50  public class ResourceFileProcessorTest extends JomcToolTest
51  {
52  
53      /** Creates a new {@code ResourceFileProcessorTest} instance. */
54      public ResourceFileProcessorTest()
55      {
56          super();
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public ResourceFileProcessor getJomcTool()
62      {
63          return (ResourceFileProcessor) super.getJomcTool();
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      protected ResourceFileProcessor newJomcTool()
69      {
70          return new ResourceFileProcessor();
71      }
72  
73      @Test
74      public final void testResourceFileProcessorNullPointerException() throws Exception
75      {
76          try
77          {
78              this.getJomcTool().getResourceBundleResources( (Specification) null );
79              fail( "Expected NullPointerException not thrown." );
80          }
81          catch ( final NullPointerException e )
82          {
83              assertNullPointerException( e );
84          }
85  
86          try
87          {
88              this.getJomcTool().getResourceBundleResources( (Implementation) null );
89              fail( "Expected NullPointerException not thrown." );
90          }
91          catch ( final NullPointerException e )
92          {
93              assertNullPointerException( e );
94          }
95  
96          try
97          {
98              this.getJomcTool().writeResourceBundleResourceFiles( null );
99              fail( "Expected NullPointerException not thrown." );
100         }
101         catch ( final NullPointerException e )
102         {
103             assertNullPointerException( e );
104         }
105 
106         try
107         {
108             this.getJomcTool().writeResourceBundleResourceFiles( (Module) null, new File( "/" ) );
109             fail( "Expected NullPointerException not thrown." );
110         }
111         catch ( final NullPointerException e )
112         {
113             assertNullPointerException( e );
114         }
115 
116         try
117         {
118             this.getJomcTool().writeResourceBundleResourceFiles( new Module(), null );
119             fail( "Expected NullPointerException not thrown." );
120         }
121         catch ( final NullPointerException e )
122         {
123             assertNullPointerException( e );
124         }
125 
126         try
127         {
128             this.getJomcTool().writeResourceBundleResourceFiles( (Specification) null, new File( "/" ) );
129             fail( "Expected NullPointerException not thrown." );
130         }
131         catch ( final NullPointerException e )
132         {
133             assertNullPointerException( e );
134         }
135 
136         try
137         {
138             this.getJomcTool().writeResourceBundleResourceFiles( new Specification(), null );
139             fail( "Expected NullPointerException not thrown." );
140         }
141         catch ( final NullPointerException e )
142         {
143             assertNullPointerException( e );
144         }
145 
146         try
147         {
148             this.getJomcTool().writeResourceBundleResourceFiles( (Implementation) null, new File( "/" ) );
149             fail( "Expected NullPointerException not thrown." );
150         }
151         catch ( final NullPointerException e )
152         {
153             assertNullPointerException( e );
154         }
155 
156         try
157         {
158             this.getJomcTool().writeResourceBundleResourceFiles( new Implementation(), null );
159             fail( "Expected NullPointerException not thrown." );
160         }
161         catch ( final NullPointerException e )
162         {
163             assertNullPointerException( e );
164         }
165     }
166 
167     @Test
168     public final void testResourceFileProcessorNotNull() throws Exception
169     {
170         assertNotNull( this.getJomcTool().getResourceBundleDefaultLocale() );
171         assertNotNull( this.getJomcTool().getResourceBundleResources(
172             this.getJomcTool().getModules().getSpecification( "Specification" ) ) );
173 
174         assertNotNull( this.getJomcTool().getResourceBundleResources(
175             this.getJomcTool().getModules().getImplementation( "Implementation" ) ) );
176 
177     }
178 
179     @Test
180     public final void testResourceBundleDefaultLocale() throws Exception
181     {
182         this.getJomcTool().setResourceBundleDefaultLocale( null );
183         assertNotNull( this.getJomcTool().getResourceBundleDefaultLocale() );
184         this.getJomcTool().setResourceBundleDefaultLocale( null );
185     }
186 
187     @Test
188     public final void testWriteResourceBundleResourceFiles() throws Exception
189     {
190         final File nonExistentDirectory = this.getNextOutputDirectory();
191 
192         try
193         {
194             this.getJomcTool().writeResourceBundleResourceFiles( nonExistentDirectory );
195             fail( "Expected IOException not thrown." );
196         }
197         catch ( final IOException e )
198         {
199             assertNotNull( e.getMessage() );
200             System.out.println( e );
201         }
202 
203         try
204         {
205             this.getJomcTool().writeResourceBundleResourceFiles(
206                 this.getJomcTool().getModules().getModule( "Module" ), nonExistentDirectory );
207 
208             fail( "Expected IOException not thrown." );
209         }
210         catch ( final IOException e )
211         {
212             assertNotNull( e.getMessage() );
213             System.out.println( e );
214         }
215 
216         try
217         {
218             this.getJomcTool().writeResourceBundleResourceFiles(
219                 this.getJomcTool().getModules().getSpecification( "Specification" ), nonExistentDirectory );
220 
221             fail( "Expected IOException not thrown." );
222         }
223         catch ( final IOException e )
224         {
225             assertNotNull( e.getMessage() );
226             System.out.println( e );
227         }
228 
229         try
230         {
231             this.getJomcTool().writeResourceBundleResourceFiles(
232                 this.getJomcTool().getModules().getImplementation( "Implementation" ), nonExistentDirectory );
233 
234             fail( "Expected IOException not thrown." );
235         }
236         catch ( final IOException e )
237         {
238             assertNotNull( e.getMessage() );
239             System.out.println( e );
240         }
241 
242         File resourcesDirectory = this.getNextOutputDirectory();
243         assertTrue( resourcesDirectory.mkdirs() );
244         this.getJomcTool().writeResourceBundleResourceFiles( resourcesDirectory );
245 
246         resourcesDirectory = this.getNextOutputDirectory();
247         assertTrue( resourcesDirectory.mkdirs() );
248         this.getJomcTool().writeResourceBundleResourceFiles(
249             this.getJomcTool().getModules().getModule( "Module" ), resourcesDirectory );
250 
251         resourcesDirectory = this.getNextOutputDirectory();
252         assertTrue( resourcesDirectory.mkdirs() );
253         this.getJomcTool().writeResourceBundleResourceFiles(
254             this.getJomcTool().getModules().getSpecification( "Specification" ), resourcesDirectory );
255 
256         resourcesDirectory = this.getNextOutputDirectory();
257         assertTrue( resourcesDirectory.mkdirs() );
258         this.getJomcTool().writeResourceBundleResourceFiles(
259             this.getJomcTool().getModules().getImplementation( "Implementation" ), resourcesDirectory );
260 
261     }
262 
263     @Test
264     public final void testCopyConstructor() throws Exception
265     {
266         try
267         {
268             new ResourceFileProcessor( null );
269             fail( "Expected NullPointerException not thrown." );
270         }
271         catch ( final NullPointerException e )
272         {
273             assertNotNull( e.getMessage() );
274             System.out.println( e.toString() );
275         }
276 
277         new ResourceFileProcessor( this.getJomcTool() );
278     }
279 
280 }