View Javadoc

1   /*
2    *  jDTAUS Core Test Suite
3    *  Copyright (C) 2005 Christian Schulte
4    *  <cs@schulte.it>
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19   *
20   */
21  package org.jdtaus.core.container.it;
22  
23  import java.util.Locale;
24  import junit.framework.Assert;
25  import junit.framework.TestCase;
26  import org.jdtaus.core.container.Container;
27  
28  /**
29   * Testcase for {@code Container} implementations.
30   *
31   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
32   * @version $JDTAUS: ContainerTest.java 8743 2012-10-07 03:06:20Z schulte $
33   */
34  public class ContainerTest extends TestCase
35  {
36      //--ContainerTest-----------------------------------------------------------
37  
38      /** The implementation to test. */
39      private Container container;
40  
41      /** Creates a new {@code ContainerTest} instance. */
42      public ContainerTest()
43      {
44          super();
45      }
46  
47      /**
48       * Gets the {@code Container} implementation tests are performed with.
49       *
50       * @return the {@code Container} implementation tests are performed
51       * with.
52       */
53      public Container getContainer()
54      {
55          return this.container;
56      }
57  
58      /**
59       * Sets the {@code Container} implementation to test.
60       *
61       * @param value the {@code Container} implementation to test.
62       */
63      public final void setContainer( final Container value )
64      {
65          this.container = value;
66      }
67  
68      //-----------------------------------------------------------ContainerTest--
69      //--Tests-------------------------------------------------------------------
70  
71      public void testGetDependency() throws Exception
72      {
73          try
74          {
75              this.getContainer().getDependency( (Object) null, "TEST" );
76              throw new AssertionError( "Expected 'NullPointerException' not thrown." );
77          }
78          catch ( final NullPointerException e )
79          {
80              Assert.assertNotNull( e.getMessage() );
81              System.out.println( e.toString() );
82          }
83  
84          try
85          {
86              this.getContainer().getDependency( this, null );
87              throw new AssertionError( "Expected 'NullPointerException' not thrown." );
88          }
89          catch ( final NullPointerException e )
90          {
91              Assert.assertNotNull( e.getMessage() );
92              System.out.println( e.toString() );
93          }
94      }
95  
96      public void testGetMessage() throws Exception
97      {
98          try
99          {
100             this.getContainer().getMessage( (Object) null, "TEST", Locale.getDefault(), null );
101             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
102         }
103         catch ( final NullPointerException e )
104         {
105             Assert.assertNotNull( e.getMessage() );
106             System.out.println( e.toString() );
107         }
108         try
109         {
110             this.getContainer().getMessage( this, null, Locale.getDefault(), null );
111             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
112         }
113         catch ( final NullPointerException e )
114         {
115             Assert.assertNotNull( e.getMessage() );
116             System.out.println( e.toString() );
117         }
118         try
119         {
120             this.getContainer().getMessage( this, "TEST", null, null );
121             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
122         }
123         catch ( final NullPointerException e )
124         {
125             Assert.assertNotNull( e.getMessage() );
126             System.out.println( e.toString() );
127         }
128     }
129 
130     public void testGetObject() throws Exception
131     {
132         try
133         {
134             this.getContainer().getObject( (Class) null );
135             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
136         }
137         catch ( final NullPointerException e )
138         {
139             Assert.assertNotNull( e.getMessage() );
140             System.out.println( e.toString() );
141         }
142 
143         try
144         {
145             this.getContainer().getObject( (Class) null, "TEST" );
146             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
147         }
148         catch ( final NullPointerException e )
149         {
150             Assert.assertNotNull( e.getMessage() );
151             System.out.println( e.toString() );
152         }
153         try
154         {
155             this.getContainer().getObject( this.getClass(), null );
156             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
157         }
158         catch ( final NullPointerException e )
159         {
160             Assert.assertNotNull( e.getMessage() );
161             System.out.println( e.toString() );
162         }
163     }
164 
165     public void testGetProperty() throws Exception
166     {
167         try
168         {
169             this.getContainer().getProperty( (Object) null, "TEST" );
170             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
171         }
172         catch ( final NullPointerException e )
173         {
174             Assert.assertNotNull( e.getMessage() );
175             System.out.println( e.toString() );
176         }
177         try
178         {
179             this.getContainer().getProperty( this, null );
180             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
181         }
182         catch ( final NullPointerException e )
183         {
184             Assert.assertNotNull( e.getMessage() );
185             System.out.println( e.toString() );
186         }
187     }
188 
189     //-------------------------------------------------------------------Tests--
190 }