001 /* 002 * Copyright (C) Christian Schulte, 2005-206 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without 006 * modification, are permitted provided that the following conditions 007 * are met: 008 * 009 * o Redistributions of source code must retain the above copyright 010 * notice, this list of conditions and the following disclaimer. 011 * 012 * o Redistributions in binary form must reproduce the above copyright 013 * notice, this list of conditions and the following disclaimer in 014 * the documentation and/or other materials provided with the 015 * distribution. 016 * 017 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 018 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 019 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 020 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, 021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 027 * 028 * $JOMC: ResourceFileProcessorTest.java 3838 2011-10-08 20:15:41Z schulte2005 $ 029 * 030 */ 031 package org.jomc.tools.test; 032 033 import java.io.File; 034 import java.io.IOException; 035 import org.jomc.model.Implementation; 036 import org.jomc.model.Module; 037 import org.jomc.model.Specification; 038 import org.jomc.tools.ResourceFileProcessor; 039 import org.junit.Test; 040 import static org.junit.Assert.assertNotNull; 041 import static org.junit.Assert.assertTrue; 042 import static org.junit.Assert.fail; 043 044 /** 045 * Test cases for class {@code org.jomc.tools.ResourceFileProcessor}. 046 * 047 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 048 * @version $JOMC: ResourceFileProcessorTest.java 3838 2011-10-08 20:15:41Z schulte2005 $ 049 */ 050 public class ResourceFileProcessorTest extends JomcToolTest 051 { 052 053 /** Creates a new {@code ResourceFileProcessorTest} instance. */ 054 public ResourceFileProcessorTest() 055 { 056 super(); 057 } 058 059 /** {@inheritDoc} */ 060 @Override 061 public ResourceFileProcessor getJomcTool() 062 { 063 return (ResourceFileProcessor) super.getJomcTool(); 064 } 065 066 /** {@inheritDoc} */ 067 @Override 068 protected ResourceFileProcessor newJomcTool() 069 { 070 return new ResourceFileProcessor(); 071 } 072 073 @Test 074 public final void testResourceFileProcessorNullPointerException() throws Exception 075 { 076 try 077 { 078 this.getJomcTool().getResourceBundleResources( (Specification) null ); 079 fail( "Expected NullPointerException not thrown." ); 080 } 081 catch ( final NullPointerException e ) 082 { 083 assertNullPointerException( e ); 084 } 085 086 try 087 { 088 this.getJomcTool().getResourceBundleResources( (Implementation) null ); 089 fail( "Expected NullPointerException not thrown." ); 090 } 091 catch ( final NullPointerException e ) 092 { 093 assertNullPointerException( e ); 094 } 095 096 try 097 { 098 this.getJomcTool().writeResourceBundleResourceFiles( null ); 099 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 }