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 8692 2012-10-01 14:16:57Z schulte $
33   */
34  public class ContainerTest extends TestCase
35  {
36      //--ContainerTest-----------------------------------------------------------
37  
38      /** The implementation to test. */
39      private Container container;
40  
41      /**
42       * Gets the {@code Container} implementation tests are performed with.
43       *
44       * @return the {@code Container} implementation tests are performed
45       * with.
46       */
47      public Container getContainer()
48      {
49          return this.container;
50      }
51  
52      /**
53       * Sets the {@code Container} implementation to test.
54       *
55       * @param value the {@code Container} implementation to test.
56       */
57      public final void setContainer( final Container value )
58      {
59          this.container = value;
60      }
61  
62      //-----------------------------------------------------------ContainerTest--
63      //--Tests-------------------------------------------------------------------
64  
65      public void testGetDependency() throws Exception
66      {
67          try
68          {
69              this.getContainer().getDependency( (Object) null, "TEST" );
70              throw new AssertionError( "Expected 'NullPointerException' not thrown." );
71          }
72          catch ( NullPointerException e )
73          {
74              Assert.assertNotNull( e.getMessage() );
75              System.out.println( e.toString() );
76          }
77  
78          try
79          {
80              this.getContainer().getDependency( this, null );
81              throw new AssertionError( "Expected 'NullPointerException' not thrown." );
82          }
83          catch ( NullPointerException e )
84          {
85              Assert.assertNotNull( e.getMessage() );
86              System.out.println( e.toString() );
87          }
88      }
89  
90      public void testGetMessage() throws Exception
91      {
92          try
93          {
94              this.getContainer().getMessage( (Object) null, "TEST", Locale.getDefault(), null );
95              throw new AssertionError( "Expected 'NullPointerException' not thrown." );
96          }
97          catch ( NullPointerException e )
98          {
99              Assert.assertNotNull( e.getMessage() );
100             System.out.println( e.toString() );
101         }
102         try
103         {
104             this.getContainer().getMessage( this, null, Locale.getDefault(), null );
105             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
106         }
107         catch ( NullPointerException e )
108         {
109             Assert.assertNotNull( e.getMessage() );
110             System.out.println( e.toString() );
111         }
112         try
113         {
114             this.getContainer().getMessage( this, "TEST", null, null );
115             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
116         }
117         catch ( NullPointerException e )
118         {
119             Assert.assertNotNull( e.getMessage() );
120             System.out.println( e.toString() );
121         }
122     }
123 
124     public void testGetObject() throws Exception
125     {
126         try
127         {
128             this.getContainer().getObject( (Class) null );
129             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
130         }
131         catch ( NullPointerException e )
132         {
133             Assert.assertNotNull( e.getMessage() );
134             System.out.println( e.toString() );
135         }
136 
137         try
138         {
139             this.getContainer().getObject( (Class) null, "TEST" );
140             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
141         }
142         catch ( NullPointerException e )
143         {
144             Assert.assertNotNull( e.getMessage() );
145             System.out.println( e.toString() );
146         }
147         try
148         {
149             this.getContainer().getObject( this.getClass(), null );
150             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
151         }
152         catch ( NullPointerException e )
153         {
154             Assert.assertNotNull( e.getMessage() );
155             System.out.println( e.toString() );
156         }
157     }
158 
159     public void testGetProperty() throws Exception
160     {
161         try
162         {
163             this.getContainer().getProperty( (Object) null, "TEST" );
164             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
165         }
166         catch ( NullPointerException e )
167         {
168             Assert.assertNotNull( e.getMessage() );
169             System.out.println( e.toString() );
170         }
171         try
172         {
173             this.getContainer().getProperty( this, null );
174             throw new AssertionError( "Expected 'NullPointerException' not thrown." );
175         }
176         catch ( NullPointerException e )
177         {
178             Assert.assertNotNull( e.getMessage() );
179             System.out.println( e.toString() );
180         }
181     }
182 
183     //-------------------------------------------------------------------Tests--
184 }