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: JomcToolTest.java 4527 2012-05-23 00:43:20Z schulte2005 $
29   *
30   */
31  package org.jomc.tools.test;
32  
33  import java.io.File;
34  import java.io.FileNotFoundException;
35  import java.io.FileOutputStream;
36  import java.io.IOException;
37  import java.util.Calendar;
38  import java.util.Locale;
39  import java.util.Properties;
40  import java.util.logging.Level;
41  import org.apache.commons.io.FileUtils;
42  import org.jomc.model.Argument;
43  import org.jomc.model.Dependency;
44  import org.jomc.model.Implementation;
45  import org.jomc.model.Message;
46  import org.jomc.model.ModelObject;
47  import org.jomc.model.Module;
48  import org.jomc.model.Modules;
49  import org.jomc.model.Property;
50  import org.jomc.model.Specification;
51  import org.jomc.model.SpecificationReference;
52  import org.jomc.model.Text;
53  import org.jomc.model.Texts;
54  import org.jomc.model.modlet.DefaultModelProvider;
55  import org.jomc.model.modlet.ModelHelper;
56  import org.jomc.modlet.Model;
57  import org.jomc.modlet.ModelContext;
58  import org.jomc.modlet.ModelContextFactory;
59  import org.jomc.modlet.ModelException;
60  import org.jomc.tools.JomcTool;
61  import org.junit.Test;
62  import static org.junit.Assert.assertEquals;
63  import static org.junit.Assert.assertNotNull;
64  import static org.junit.Assert.assertTrue;
65  import static org.junit.Assert.fail;
66  
67  /**
68   * Test cases for class {@code org.jomc.tools.JomcTool}.
69   *
70   * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
71   * @version $JOMC: JomcToolTest.java 4527 2012-05-23 00:43:20Z schulte2005 $
72   */
73  public class JomcToolTest
74  {
75  
76      /** Constant for the name of the system property holding the name of the encoding of resources backing the test. */
77      private static final String RESOURCE_ENCODING_PROPERTY_NAME = "jomc.test.resourceEncoding";
78  
79      /** Constant for the name of the system property holding the output directory for the test. */
80      private static final String OUTPUT_DIRECTORY_PROPERTY_NAME = "jomc.test.outputDirectory";
81  
82      /** The {@code JomcTool} instance tests are performed with. */
83      private JomcTool jomcTool;
84  
85      /** The {@code ModelContext} of the instance. */
86      private ModelContext modelContext;
87  
88      /** The {@code Model} of the instance. */
89      private Model model;
90  
91      /** The name of the encoding to use when reading or writing resources. */
92      private String resourceEncoding;
93  
94      /** The output directory of the instance. */
95      private File outputDirectory;
96  
97      /** Serial number of next output directories. */
98      private volatile int outputDirectoryId;
99  
100     /** Creates a new {@code JomcToolTest} instance. */
101     public JomcToolTest()
102     {
103         super();
104     }
105 
106     /**
107      * Gets the name of the encoding used when reading resources.
108      *
109      * @return The name of the encoding used when reading resources.
110      *
111      * @see #setResourceEncoding(java.lang.String)
112      */
113     public final String getResourceEncoding()
114     {
115         if ( this.resourceEncoding == null )
116         {
117             this.resourceEncoding = System.getProperty( RESOURCE_ENCODING_PROPERTY_NAME );
118             assertNotNull( "Expected '" + RESOURCE_ENCODING_PROPERTY_NAME + "' system property not found.",
119                            this.resourceEncoding );
120 
121         }
122 
123         return this.resourceEncoding;
124     }
125 
126     /**
127      * Sets the name of the encoding to use when reading resources.
128      *
129      * @param value The new name of the encoding to use when reading resources or {@code null}.
130      *
131      * @see #getResourceEncoding()
132      */
133     public final void setResourceEncoding( final String value )
134     {
135         this.resourceEncoding = value;
136     }
137 
138     /**
139      * Gets the output directory of instance.
140      *
141      * @return The output directory of instance.
142      *
143      * @see #setOutputDirectory(java.io.File)
144      */
145     public final File getOutputDirectory()
146     {
147         if ( this.outputDirectory == null )
148         {
149             final String name = System.getProperty( OUTPUT_DIRECTORY_PROPERTY_NAME );
150             assertNotNull( "Expected '" + OUTPUT_DIRECTORY_PROPERTY_NAME + "' system property not found.", name );
151             this.outputDirectory = new File( new File( name ), this.getClass().getSimpleName() );
152             assertTrue( "Expected '" + OUTPUT_DIRECTORY_PROPERTY_NAME + "' system property to hold an absolute path.",
153                         this.outputDirectory.isAbsolute() );
154 
155             if ( !this.outputDirectory.exists() )
156             {
157                 assertTrue( this.outputDirectory.mkdirs() );
158             }
159         }
160 
161         return this.outputDirectory;
162     }
163 
164     /**
165      * Sets the output directory of instance.
166      *
167      * @param value The new output directory of instance or {@code null}.
168      *
169      * @see #getOutputDirectory()
170      */
171     public final void setOutputDirectory( final File value )
172     {
173         if ( value != null )
174         {
175             assertTrue( "Expected absolute 'outputDirectory'.", value.isAbsolute() );
176         }
177 
178         this.outputDirectory = value;
179     }
180 
181     /**
182      * Gets the next output directory of the instance.
183      *
184      * @return The next output directory of the instance.
185      */
186     public final File getNextOutputDirectory()
187     {
188         try
189         {
190             final File nextOutputDirectory =
191                 new File( this.getOutputDirectory(), Integer.toString( this.outputDirectoryId++ ) );
192 
193             assertTrue( nextOutputDirectory.isAbsolute() );
194             if ( nextOutputDirectory.exists() )
195             {
196                 FileUtils.deleteDirectory( nextOutputDirectory );
197             }
198 
199             return nextOutputDirectory;
200         }
201         catch ( final IOException e )
202         {
203             throw new AssertionError( e );
204         }
205     }
206 
207     /**
208      * Gets the {@code JomcTool} instance tests are performed with.
209      *
210      * @return The {@code JomcTool} instance tests are performed with.
211      *
212      * @see #newJomcTool()
213      */
214     public JomcTool getJomcTool()
215     {
216         if ( this.jomcTool == null )
217         {
218             this.jomcTool = this.newJomcTool();
219             this.jomcTool.setModel( this.getModel() );
220             this.jomcTool.getListeners().add( new JomcTool.Listener()
221             {
222 
223                 @Override
224                 public void onLog( final Level level, final String message, final Throwable throwable )
225                 {
226                     super.onLog( level, message, throwable );
227                     System.out.println( "[" + level.getLocalizedName() + "] " + message );
228 
229                     if ( throwable != null )
230                     {
231                         throwable.printStackTrace( System.out );
232                     }
233                 }
234 
235             } );
236 
237         }
238 
239         return this.jomcTool;
240     }
241 
242     /**
243      * Creates a new {@code JomcTool} instance to test.
244      *
245      * @return A new {@code JomcTool} instance to test.
246      *
247      * @see #getJomcTool()
248      */
249     protected JomcTool newJomcTool()
250     {
251         return new JomcTool();
252     }
253 
254     /**
255      * Gets the {@code ModelContext} instance backing the test.
256      *
257      * @return The {@code ModelContext} instance backing the test.
258      *
259      * @see #newModelContext()
260      */
261     public ModelContext getModelContext()
262     {
263         if ( this.modelContext == null )
264         {
265             this.modelContext = this.newModelContext();
266             this.modelContext.getListeners().add( new ModelContext.Listener()
267             {
268 
269                 @Override
270                 public void onLog( final Level level, String message, Throwable t )
271                 {
272                     super.onLog( level, message, t );
273                     System.out.println( "[" + level.getLocalizedName() + "] " + message );
274 
275                     if ( t != null )
276                     {
277                         t.printStackTrace( System.out );
278                     }
279                 }
280 
281             } );
282 
283         }
284 
285         return this.modelContext;
286     }
287 
288     /**
289      * Creates a new {@code ModelContext} instance backing the test.
290      *
291      * @return A new {@code ModelContext} instance backing the test.
292      *
293      * @see #getModelContext()
294      */
295     protected ModelContext newModelContext()
296     {
297         return ModelContextFactory.newInstance().newModelContext();
298     }
299 
300     /**
301      * Gets the {@code Model} instance backing the test.
302      *
303      * @return The {@code Model} instance backing the test.
304      *
305      * @see #newModel()
306      */
307     public Model getModel()
308     {
309         if ( this.model == null )
310         {
311             this.model = this.newModel();
312         }
313 
314         return this.model;
315     }
316 
317     /**
318      * Creates a new {@code Model} instance backing the test.
319      *
320      * @return A new {@code Model} instance backing the test.
321      *
322      * @see #getModel()
323      */
324     protected Model newModel()
325     {
326         try
327         {
328             DefaultModelProvider.setDefaultModuleLocation( this.getClass().getPackage().getName().replace( '.', '/' )
329                                                            + "/jomc.xml" );
330 
331             Model m = this.getModelContext().findModel( ModelObject.MODEL_PUBLIC_ID );
332 
333             if ( m != null )
334             {
335                 final Modules modules = ModelHelper.getModules( m );
336 
337                 if ( modules != null )
338                 {
339                     final Module cp = modules.getClasspathModule( Modules.getDefaultClasspathModuleName(),
340                                                                   this.getClass().getClassLoader() );
341 
342                     if ( cp != null )
343                     {
344                         modules.getModule().add( cp );
345                     }
346                 }
347 
348                 m = this.getModelContext().processModel( m );
349             }
350 
351             return m;
352         }
353         catch ( final ModelException e )
354         {
355             throw new AssertionError( e );
356         }
357         finally
358         {
359             DefaultModelProvider.setDefaultModuleLocation( null );
360         }
361     }
362 
363     @Test
364     @SuppressWarnings( "deprecation" )
365     public final void testJomcToolNullPointerException() throws Exception
366     {
367         assertNotNull( this.getJomcTool() );
368 
369         try
370         {
371             this.getJomcTool().getDisplayLanguage( null );
372             fail( "Expected NullPointerException not thrown." );
373         }
374         catch ( final NullPointerException e )
375         {
376             assertNullPointerException( e );
377         }
378 
379         try
380         {
381             this.getJomcTool().getImplementedJavaTypeNames( null, false );
382             fail( "Expected NullPointerException not thrown." );
383         }
384         catch ( final NullPointerException e )
385         {
386             assertNullPointerException( e );
387         }
388 
389         try
390         {
391             this.getJomcTool().getJavaClasspathLocation( (Implementation) null );
392             fail( "Expected NullPointerException not thrown." );
393         }
394         catch ( final NullPointerException e )
395         {
396             assertNullPointerException( e );
397         }
398 
399         try
400         {
401             this.getJomcTool().getJavaClasspathLocation( (Specification) null );
402             fail( "Expected NullPointerException not thrown." );
403         }
404         catch ( final NullPointerException e )
405         {
406             assertNullPointerException( e );
407         }
408 
409         try
410         {
411             this.getJomcTool().getJavaGetterMethodName( (Dependency) null );
412             fail( "Expected NullPointerException not thrown." );
413         }
414         catch ( final NullPointerException e )
415         {
416             assertNullPointerException( e );
417         }
418 
419         try
420         {
421             this.getJomcTool().getJavaGetterMethodName( (Message) null );
422             fail( "Expected NullPointerException not thrown." );
423         }
424         catch ( final NullPointerException e )
425         {
426             assertNullPointerException( e );
427         }
428 
429         try
430         {
431             this.getJomcTool().getJavaGetterMethodName( (Property) null );
432             fail( "Expected NullPointerException not thrown." );
433         }
434         catch ( final NullPointerException e )
435         {
436             assertNullPointerException( e );
437         }
438 
439         try
440         {
441             this.getJomcTool().getJavaMethodParameterName( (Argument) null );
442             fail( "Expected NullPointerException not thrown." );
443         }
444         catch ( final NullPointerException e )
445         {
446             assertNullPointerException( e );
447         }
448 
449         try
450         {
451             this.getJomcTool().getJavaMethodParameterName( (Dependency) null );
452             fail( "Expected NullPointerException not thrown." );
453         }
454         catch ( final NullPointerException e )
455         {
456             assertNullPointerException( e );
457         }
458 
459         try
460         {
461             this.getJomcTool().getJavaMethodParameterName( (Message) null );
462             fail( "Expected NullPointerException not thrown." );
463         }
464         catch ( final NullPointerException e )
465         {
466             assertNullPointerException( e );
467         }
468 
469         try
470         {
471             this.getJomcTool().getJavaMethodParameterName( (Property) null );
472             fail( "Expected NullPointerException not thrown." );
473         }
474         catch ( final NullPointerException e )
475         {
476             assertNullPointerException( e );
477         }
478 
479         try
480         {
481             this.getJomcTool().getJavaInterfaceNames( null, false );
482             fail( "Expected NullPointerException not thrown." );
483         }
484         catch ( final NullPointerException e )
485         {
486             assertNullPointerException( e );
487         }
488 
489         try
490         {
491             this.getJomcTool().getJavaModifierName( null, (Dependency) null );
492             fail( "Expected NullPointerException not thrown." );
493         }
494         catch ( final NullPointerException e )
495         {
496             assertNullPointerException( e );
497         }
498         try
499         {
500             this.getJomcTool().getJavaModifierName( new Implementation(), (Dependency) null );
501             fail( "Expected NullPointerException not thrown." );
502         }
503         catch ( final NullPointerException e )
504         {
505             assertNullPointerException( e );
506         }
507 
508         try
509         {
510             this.getJomcTool().getJavaModifierName( null, (Message) null );
511             fail( "Expected NullPointerException not thrown." );
512         }
513         catch ( final NullPointerException e )
514         {
515             assertNullPointerException( e );
516         }
517         try
518         {
519             this.getJomcTool().getJavaModifierName( new Implementation(), (Message) null );
520             fail( "Expected NullPointerException not thrown." );
521         }
522         catch ( final NullPointerException e )
523         {
524             assertNullPointerException( e );
525         }
526 
527         try
528         {
529             this.getJomcTool().getJavaModifierName( null, (Property) null );
530             fail( "Expected NullPointerException not thrown." );
531         }
532         catch ( final NullPointerException e )
533         {
534             assertNullPointerException( e );
535         }
536         try
537         {
538             this.getJomcTool().getJavaModifierName( new Implementation(), (Property) null );
539             fail( "Expected NullPointerException not thrown." );
540         }
541         catch ( final NullPointerException e )
542         {
543             assertNullPointerException( e );
544         }
545 
546         try
547         {
548             this.getJomcTool().getJavaPackageName( (Implementation) null );
549             fail( "Expected NullPointerException not thrown." );
550         }
551         catch ( final NullPointerException e )
552         {
553             assertNullPointerException( e );
554         }
555 
556         try
557         {
558             this.getJomcTool().getJavaPackageName( (Specification) null );
559             fail( "Expected NullPointerException not thrown." );
560         }
561         catch ( final NullPointerException e )
562         {
563             assertNullPointerException( e );
564         }
565 
566         try
567         {
568             this.getJomcTool().getJavaPackageName( (SpecificationReference) null );
569             fail( "Expected NullPointerException not thrown." );
570         }
571         catch ( final NullPointerException e )
572         {
573             assertNullPointerException( e );
574         }
575 
576         try
577         {
578             this.getJomcTool().getJavaSetterMethodName( (Dependency) null );
579             fail( "Expected NullPointerException not thrown." );
580         }
581         catch ( final NullPointerException e )
582         {
583             assertNullPointerException( e );
584         }
585 
586         try
587         {
588             this.getJomcTool().getJavaSetterMethodName( (Message) null );
589             fail( "Expected NullPointerException not thrown." );
590         }
591         catch ( final NullPointerException e )
592         {
593             assertNullPointerException( e );
594         }
595 
596         try
597         {
598             this.getJomcTool().getJavaSetterMethodName( (Property) null );
599             fail( "Expected NullPointerException not thrown." );
600         }
601         catch ( final NullPointerException e )
602         {
603             assertNullPointerException( e );
604         }
605 
606         try
607         {
608             this.getJomcTool().getJavaTypeName( (Argument) null );
609             fail( "Expected NullPointerException not thrown." );
610         }
611         catch ( final NullPointerException e )
612         {
613             assertNullPointerException( e );
614         }
615 
616         try
617         {
618             this.getJomcTool().getJavaTypeName( (Dependency) null );
619             fail( "Expected NullPointerException not thrown." );
620         }
621         catch ( final NullPointerException e )
622         {
623             assertNullPointerException( e );
624         }
625 
626         try
627         {
628             this.getJomcTool().getJavaTypeName( (Implementation) null, true );
629             fail( "Expected NullPointerException not thrown." );
630         }
631         catch ( final NullPointerException e )
632         {
633             assertNullPointerException( e );
634         }
635 
636         try
637         {
638             this.getJomcTool().getJavaTypeName( (Property) null, true );
639             fail( "Expected NullPointerException not thrown." );
640         }
641         catch ( final NullPointerException e )
642         {
643             assertNullPointerException( e );
644         }
645 
646         try
647         {
648             this.getJomcTool().getJavaTypeName( (Specification) null, true );
649             fail( "Expected NullPointerException not thrown." );
650         }
651         catch ( final NullPointerException e )
652         {
653             assertNullPointerException( e );
654         }
655 
656         try
657         {
658             this.getJomcTool().getJavaTypeName( (SpecificationReference) null, true );
659             fail( "Expected NullPointerException not thrown." );
660         }
661         catch ( final NullPointerException e )
662         {
663             assertNullPointerException( e );
664         }
665 
666         try
667         {
668             this.getJomcTool().getJavadocComment( (Text) null, 0, "\n" );
669             fail( "Expected NullPointerException not thrown." );
670         }
671         catch ( final NullPointerException e )
672         {
673             assertNullPointerException( e );
674         }
675         try
676         {
677             this.getJomcTool().getJavadocComment( new Text(), 0, null );
678             fail( "Expected NullPointerException not thrown." );
679         }
680         catch ( final NullPointerException e )
681         {
682             assertNullPointerException( e );
683         }
684         try
685         {
686             this.getJomcTool().getJavadocComment( new Text(), Integer.MIN_VALUE, "\n" );
687             fail( "Expected IllegalArgumentException not thrown." );
688         }
689         catch ( final IllegalArgumentException e )
690         {
691             assertIllegalArgumentException( e );
692         }
693 
694         try
695         {
696             this.getJomcTool().getJavadocComment( (Texts) null, 0, "\n" );
697             fail( "Expected NullPointerException not thrown." );
698         }
699         catch ( final NullPointerException e )
700         {
701             assertNullPointerException( e );
702         }
703         try
704         {
705             this.getJomcTool().getJavadocComment( new Texts(), 0, null );
706             fail( "Expected NullPointerException not thrown." );
707         }
708         catch ( final NullPointerException e )
709         {
710             assertNullPointerException( e );
711         }
712         try
713         {
714             this.getJomcTool().getJavadocComment( new Texts(), Integer.MIN_VALUE, "\n" );
715             fail( "Expected IllegalArgumentException not thrown." );
716         }
717         catch ( final IllegalArgumentException e )
718         {
719             assertIllegalArgumentException( e );
720         }
721 
722         try
723         {
724             this.getJomcTool().getLongDate( null );
725             fail( "Expected NullPointerException not thrown." );
726         }
727         catch ( final NullPointerException e )
728         {
729             assertNullPointerException( e );
730         }
731 
732         try
733         {
734             this.getJomcTool().getLongDateTime( null );
735             fail( "Expected NullPointerException not thrown." );
736         }
737         catch ( final NullPointerException e )
738         {
739             assertNullPointerException( e );
740         }
741 
742         try
743         {
744             this.getJomcTool().getLongTime( null );
745             fail( "Expected NullPointerException not thrown." );
746         }
747         catch ( final NullPointerException e )
748         {
749             assertNullPointerException( e );
750         }
751 
752         try
753         {
754             this.getJomcTool().getMediumDate( null );
755             fail( "Expected NullPointerException not thrown." );
756         }
757         catch ( final NullPointerException e )
758         {
759             assertNullPointerException( e );
760         }
761 
762         try
763         {
764             this.getJomcTool().getMediumDateTime( null );
765             fail( "Expected NullPointerException not thrown." );
766         }
767         catch ( final NullPointerException e )
768         {
769             assertNullPointerException( e );
770         }
771 
772         try
773         {
774             this.getJomcTool().getMediumTime( null );
775             fail( "Expected NullPointerException not thrown." );
776         }
777         catch ( final NullPointerException e )
778         {
779             assertNullPointerException( e );
780         }
781 
782         try
783         {
784             this.getJomcTool().getShortDate( null );
785             fail( "Expected NullPointerException not thrown." );
786         }
787         catch ( final NullPointerException e )
788         {
789             assertNullPointerException( e );
790         }
791 
792         try
793         {
794             this.getJomcTool().getShortDateTime( null );
795             fail( "Expected NullPointerException not thrown." );
796         }
797         catch ( final NullPointerException e )
798         {
799             assertNullPointerException( e );
800         }
801 
802         try
803         {
804             this.getJomcTool().getShortTime( null );
805             fail( "Expected NullPointerException not thrown." );
806         }
807         catch ( final NullPointerException e )
808         {
809             assertNullPointerException( e );
810         }
811 
812         try
813         {
814             this.getJomcTool().getVelocityTemplate( null );
815             fail( "Expected NullPointerException not thrown." );
816         }
817         catch ( final NullPointerException e )
818         {
819             assertNullPointerException( e );
820         }
821 
822         try
823         {
824             this.getJomcTool().getYears( null, Calendar.getInstance() );
825             fail( "Expected NullPointerException not thrown." );
826         }
827         catch ( final NullPointerException e )
828         {
829             assertNullPointerException( e );
830         }
831 
832         try
833         {
834             this.getJomcTool().getYears( Calendar.getInstance(), null );
835             fail( "Expected NullPointerException not thrown." );
836         }
837         catch ( final NullPointerException e )
838         {
839             assertNullPointerException( e );
840         }
841 
842         try
843         {
844             this.getJomcTool().isJavaDefaultPackage( (Implementation) null );
845             fail( "Expected NullPointerException not thrown." );
846         }
847         catch ( final NullPointerException e )
848         {
849             assertNullPointerException( e );
850         }
851 
852         try
853         {
854             this.getJomcTool().isJavaDefaultPackage( (Specification) null );
855             fail( "Expected NullPointerException not thrown." );
856         }
857         catch ( final NullPointerException e )
858         {
859             assertNullPointerException( e );
860         }
861 
862         try
863         {
864             this.getJomcTool().isJavaPrimitiveType( null );
865             fail( "Expected NullPointerException not thrown." );
866         }
867         catch ( final NullPointerException e )
868         {
869             assertNullPointerException( e );
870         }
871 
872         try
873         {
874             this.getJomcTool().isLoggable( null );
875             fail( "Expected NullPointerException not thrown." );
876         }
877         catch ( final NullPointerException e )
878         {
879             assertNullPointerException( e );
880         }
881 
882         try
883         {
884             this.getJomcTool().getIsoDate( null );
885             fail( "Expected NullPointerException not thrown." );
886         }
887         catch ( final NullPointerException e )
888         {
889             assertNullPointerException( e );
890         }
891 
892         try
893         {
894             this.getJomcTool().getIsoTime( null );
895             fail( "Expected NullPointerException not thrown." );
896         }
897         catch ( final NullPointerException e )
898         {
899             assertNullPointerException( e );
900         }
901 
902         try
903         {
904             this.getJomcTool().getIsoDateTime( null );
905             fail( "Expected NullPointerException not thrown." );
906         }
907         catch ( final NullPointerException e )
908         {
909             assertNullPointerException( e );
910         }
911     }
912 
913     @Test
914     @SuppressWarnings( "deprecation" )
915     public final void testJomcToolNotNull() throws Exception
916     {
917         final Specification specification = new Specification();
918         specification.setClazz( "java.lang.Object" );
919         specification.setIdentifier( "java.lang.Object" );
920 
921         final Specification defaultPackageSpecification = new Specification();
922         defaultPackageSpecification.setClazz( "Object" );
923         defaultPackageSpecification.setIdentifier( "Object" );
924 
925         final Implementation implementation = new Implementation();
926         implementation.setIdentifier( "java.lang.Object" );
927         implementation.setName( "java.lang.Object" );
928         implementation.setClazz( "java.lang.Object" );
929 
930         final Implementation defaultPackageImplementation = new Implementation();
931         defaultPackageImplementation.setIdentifier( "Object" );
932         defaultPackageImplementation.setName( "Object" );
933         defaultPackageImplementation.setClazz( "Object" );
934 
935         final Dependency d = new Dependency();
936         d.setIdentifier( "java.util.Locale" );
937         d.setName( "locale" );
938         d.setImplementationName( "default" );
939 
940         final Property p = new Property();
941         p.setName( "property" );
942         p.setValue( "Test" );
943 
944         final Message m = new Message();
945         m.setName( "message" );
946 
947         final Calendar now = Calendar.getInstance();
948         final Calendar nextYear = Calendar.getInstance();
949         nextYear.set( Calendar.YEAR, nextYear.get( Calendar.YEAR ) + 1 );
950 
951         assertNotNull( this.getJomcTool().getListeners() );
952         assertNotNull( this.getJomcTool().getInputEncoding() );
953         assertNotNull( this.getJomcTool().getModel() );
954         assertNotNull( this.getJomcTool().getModules() );
955         assertNotNull( this.getJomcTool().getOutputEncoding() );
956         assertNotNull( this.getJomcTool().getTemplateProfile() );
957         assertNotNull( this.getJomcTool().getTemplateEncoding() );
958         assertNotNull( this.getJomcTool().getTemplateParameters() );
959         assertNotNull( this.getJomcTool().getIndentation() );
960         assertNotNull( this.getJomcTool().getLineSeparator() );
961         assertNotNull( this.getJomcTool().getVelocityContext() );
962         assertNotNull( this.getJomcTool().getVelocityEngine() );
963         assertNotNull( JomcTool.getDefaultLogLevel() );
964         assertNotNull( this.getJomcTool().getLongDate( now ) );
965         assertNotNull( this.getJomcTool().getLongDateTime( now ) );
966         assertNotNull( this.getJomcTool().getLongTime( now ) );
967         assertNotNull( this.getJomcTool().getMediumDate( now ) );
968         assertNotNull( this.getJomcTool().getMediumDateTime( now ) );
969         assertNotNull( this.getJomcTool().getMediumTime( now ) );
970         assertNotNull( this.getJomcTool().getShortDate( now ) );
971         assertNotNull( this.getJomcTool().getShortDateTime( now ) );
972         assertNotNull( this.getJomcTool().getShortTime( now ) );
973         assertNotNull( this.getJomcTool().getIsoDate( now ) );
974         assertNotNull( this.getJomcTool().getIsoDateTime( now ) );
975         assertNotNull( this.getJomcTool().getIsoTime( now ) );
976         assertNotNull( this.getJomcTool().getYears( now, now ) );
977         assertNotNull( this.getJomcTool().getYears( now, nextYear ) );
978         assertNotNull( this.getJomcTool().getYears( nextYear, now ) );
979         assertNotNull( this.getJomcTool().getDisplayLanguage( "en" ) );
980 
981         assertEquals( this.getJomcTool().getYears( now, nextYear ), this.getJomcTool().getYears( nextYear, now ) );
982         assertEquals( Locale.getDefault().getDisplayLanguage(),
983                       this.getJomcTool().getDisplayLanguage( Locale.getDefault().getLanguage() ) );
984 
985         assertEquals( "java/lang/Object", this.getJomcTool().getJavaClasspathLocation( implementation ) );
986         assertEquals( "Object", this.getJomcTool().getJavaClasspathLocation( defaultPackageImplementation ) );
987         assertEquals( "java/lang/Object", this.getJomcTool().getJavaClasspathLocation( specification ) );
988         assertEquals( "Object", this.getJomcTool().getJavaClasspathLocation( defaultPackageSpecification ) );
989         assertEquals( "getLocale", this.getJomcTool().getJavaGetterMethodName( d ) );
990         assertEquals( "getMessage", this.getJomcTool().getJavaGetterMethodName( m ) );
991         assertEquals( "getProperty", this.getJomcTool().getJavaGetterMethodName( p ) );
992         assertEquals( 0, this.getJomcTool().getJavaInterfaceNames( implementation, true ).size() );
993         assertEquals( 0, this.getJomcTool().getImplementedJavaTypeNames( implementation, true ).size() );
994         assertEquals( "private", this.getJomcTool().getJavaModifierName( implementation, d ) );
995         assertEquals( "private", this.getJomcTool().getJavaModifierName( implementation, m ) );
996         assertEquals( "private", this.getJomcTool().getJavaModifierName( implementation, p ) );
997         assertEquals( "java.lang", this.getJomcTool().getJavaPackageName( implementation ) );
998         assertEquals( "", this.getJomcTool().getJavaPackageName( defaultPackageImplementation ) );
999         assertEquals( "java.lang", this.getJomcTool().getJavaPackageName( specification ) );
1000         assertEquals( "", this.getJomcTool().getJavaPackageName( defaultPackageSpecification ) );
1001         assertEquals( "java.util", this.getJomcTool().getJavaPackageName( d ) );
1002         assertEquals( "", this.getJomcTool().getJavaString( "" ) );
1003         assertEquals( this.getJomcTool().getIndentation(), this.getJomcTool().getIndentation( 1 ) );
1004     }
1005 
1006     @Test
1007     public final void testVelocityTemplates() throws Exception
1008     {
1009         assertNotNull( this.getJomcTool().getVelocityTemplate( "Implementation.java.vm" ) );
1010         this.getJomcTool().setTemplateProfile( "DOES_NOT_EXIST" );
1011         assertNotNull( this.getJomcTool().getVelocityTemplate( "Implementation.java.vm" ) );
1012         this.getJomcTool().setTemplateProfile( null );
1013 
1014         try
1015         {
1016             this.getJomcTool().getVelocityTemplate( "DOES_NOT_EXIST" );
1017             fail( "Expected IOException not thrown." );
1018         }
1019         catch ( final IOException e )
1020         {
1021             assertNotNull( e.getMessage() );
1022             System.out.println( e.toString() );
1023         }
1024 
1025         try
1026         {
1027             this.getJomcTool().setTemplateProfile( "DOES_NOT_EXIST" );
1028             this.getJomcTool().getVelocityTemplate( "DOES_NOT_EXIST" );
1029             fail( "Expected IOException not thrown." );
1030         }
1031         catch ( final IOException e )
1032         {
1033             assertNotNull( e.getMessage() );
1034             System.out.println( e.toString() );
1035         }
1036     }
1037 
1038     @Test
1039     public final void testDefaultLogLevel() throws Exception
1040     {
1041         final String testLogLevel = System.getProperty( "org.jomc.tools.JomcTool.defaultLogLevel" );
1042 
1043         assertNotNull( JomcTool.getDefaultLogLevel() );
1044         JomcTool.setDefaultLogLevel( null );
1045         System.setProperty( "org.jomc.tools.JomcTool.defaultLogLevel", "OFF" );
1046         assertEquals( Level.OFF, JomcTool.getDefaultLogLevel() );
1047 
1048         if ( testLogLevel != null )
1049         {
1050             System.setProperty( "org.jomc.tools.JomcTool.defaultLogLevel", testLogLevel );
1051         }
1052         else
1053         {
1054             System.clearProperty( "org.jomc.tools.JomcTool.defaultLogLevel" );
1055         }
1056 
1057         JomcTool.setDefaultLogLevel( null );
1058     }
1059 
1060     @Test
1061     public final void testLogLevel() throws Exception
1062     {
1063         JomcTool.setDefaultLogLevel( null );
1064         this.getJomcTool().setLogLevel( null );
1065         assertNotNull( this.getJomcTool().getLogLevel() );
1066 
1067         JomcTool.setDefaultLogLevel( Level.OFF );
1068         this.getJomcTool().setLogLevel( null );
1069         assertEquals( Level.OFF, this.getJomcTool().getLogLevel() );
1070 
1071         JomcTool.setDefaultLogLevel( null );
1072         this.getJomcTool().setLogLevel( null );
1073     }
1074 
1075     @Test
1076     @SuppressWarnings( "deprecation" )
1077     public final void testDefaultTemplateProfile() throws Exception
1078     {
1079         assertNotNull( JomcTool.getDefaultTemplateProfile() );
1080         System.setProperty( "org.jomc.tools.JomcTool.defaultTemplateProfile", "TEST" );
1081         JomcTool.setDefaultTemplateProfile( null );
1082         assertEquals( "TEST", JomcTool.getDefaultTemplateProfile() );
1083         System.clearProperty( "org.jomc.tools.JomcTool.defaultTemplateProfile" );
1084         JomcTool.setDefaultTemplateProfile( null );
1085     }
1086 
1087     @Test
1088     @SuppressWarnings( "deprecation" )
1089     public final void testTemplateProfile() throws Exception
1090     {
1091         JomcTool.setDefaultTemplateProfile( null );
1092         this.getJomcTool().setTemplateProfile( null );
1093         assertNotNull( this.getJomcTool().getTemplateProfile() );
1094 
1095         JomcTool.setDefaultTemplateProfile( "TEST" );
1096         this.getJomcTool().setTemplateProfile( null );
1097         assertEquals( "TEST", this.getJomcTool().getTemplateProfile() );
1098 
1099         JomcTool.setDefaultTemplateProfile( null );
1100         this.getJomcTool().setTemplateProfile( null );
1101     }
1102 
1103     @Test
1104     public final void testIndentation() throws Exception
1105     {
1106         assertEquals( "", this.getJomcTool().getIndentation( 0 ) );
1107         assertEquals( this.getJomcTool().getIndentation(), this.getJomcTool().getIndentation( 1 ) );
1108 
1109         try
1110         {
1111             this.getJomcTool().getIndentation( Integer.MIN_VALUE );
1112             fail( "Expected IllegalArgumentException not thrown." );
1113         }
1114         catch ( final IllegalArgumentException e )
1115         {
1116             assertIllegalArgumentException( e );
1117         }
1118 
1119         this.getJomcTool().setIndentation( "    TEST    " );
1120         assertEquals( "    TEST    ", this.getJomcTool().getIndentation() );
1121         assertEquals( "    TEST    ", this.getJomcTool().getIndentation( 1 ) );
1122         this.getJomcTool().setIndentation( null );
1123     }
1124 
1125     @Test
1126     public final void testModel() throws Exception
1127     {
1128         final Model m = this.getJomcTool().getModel();
1129         this.getJomcTool().setModel( null );
1130         assertNotNull( this.getJomcTool().getModel() );
1131         this.getJomcTool().setModel( m );
1132     }
1133 
1134     @Test
1135     public final void testVelocityEngine() throws Exception
1136     {
1137         this.getJomcTool().setVelocityEngine( null );
1138         assertNotNull( this.getJomcTool().getVelocityEngine() );
1139         this.getJomcTool().setVelocityEngine( null );
1140     }
1141 
1142     @Test
1143     public final void testTemplateEncoding() throws Exception
1144     {
1145         this.getJomcTool().setTemplateEncoding( null );
1146         assertNotNull( this.getJomcTool().getTemplateEncoding() );
1147         this.getJomcTool().setTemplateEncoding( null );
1148     }
1149 
1150     @Test
1151     public final void testInputEncoding() throws Exception
1152     {
1153         this.getJomcTool().setInputEncoding( null );
1154         assertNotNull( this.getJomcTool().getInputEncoding() );
1155         this.getJomcTool().setInputEncoding( null );
1156     }
1157 
1158     @Test
1159     public final void testOutputEncoding() throws Exception
1160     {
1161         this.getJomcTool().setOutputEncoding( null );
1162         assertNotNull( this.getJomcTool().getOutputEncoding() );
1163         this.getJomcTool().setOutputEncoding( null );
1164     }
1165 
1166     @Test
1167     public final void testLineSeparator() throws Exception
1168     {
1169         this.getJomcTool().setLineSeparator( null );
1170         assertNotNull( this.getJomcTool().getLineSeparator() );
1171         this.getJomcTool().setLineSeparator( null );
1172     }
1173 
1174     public static void assertNullPointerException( final NullPointerException e )
1175     {
1176         assertNotNull( e );
1177         assertNotNull( e.getMessage() );
1178         System.out.println( e.toString() );
1179     }
1180 
1181     public static void assertIllegalArgumentException( final IllegalArgumentException e )
1182     {
1183         assertNotNull( e );
1184         assertNotNull( e.getMessage() );
1185         System.out.println( e.toString() );
1186     }
1187 
1188 }