001/*
002 *  jDTAUS Core Test Suite
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.core.container.it;
022
023import java.util.Locale;
024import junit.framework.Assert;
025import junit.framework.TestCase;
026import org.jdtaus.core.container.Container;
027
028/**
029 * Testcase for {@code Container} implementations.
030 *
031 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
032 * @version $JDTAUS: ContainerTest.java 8692 2012-10-01 14:16:57Z schulte $
033 */
034public class ContainerTest extends TestCase
035{
036    //--ContainerTest-----------------------------------------------------------
037
038    /** The implementation to test. */
039    private Container container;
040
041    /**
042     * Gets the {@code Container} implementation tests are performed with.
043     *
044     * @return the {@code Container} implementation tests are performed
045     * with.
046     */
047    public Container getContainer()
048    {
049        return this.container;
050    }
051
052    /**
053     * Sets the {@code Container} implementation to test.
054     *
055     * @param value the {@code Container} implementation to test.
056     */
057    public final void setContainer( final Container value )
058    {
059        this.container = value;
060    }
061
062    //-----------------------------------------------------------ContainerTest--
063    //--Tests-------------------------------------------------------------------
064
065    public void testGetDependency() throws Exception
066    {
067        try
068        {
069            this.getContainer().getDependency( (Object) null, "TEST" );
070            throw new AssertionError( "Expected 'NullPointerException' not thrown." );
071        }
072        catch ( NullPointerException e )
073        {
074            Assert.assertNotNull( e.getMessage() );
075            System.out.println( e.toString() );
076        }
077
078        try
079        {
080            this.getContainer().getDependency( this, null );
081            throw new AssertionError( "Expected 'NullPointerException' not thrown." );
082        }
083        catch ( NullPointerException e )
084        {
085            Assert.assertNotNull( e.getMessage() );
086            System.out.println( e.toString() );
087        }
088    }
089
090    public void testGetMessage() throws Exception
091    {
092        try
093        {
094            this.getContainer().getMessage( (Object) null, "TEST", Locale.getDefault(), null );
095            throw new AssertionError( "Expected 'NullPointerException' not thrown." );
096        }
097        catch ( NullPointerException e )
098        {
099            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}