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 8743 2012-10-07 03:06:20Z schulte $ 033 */ 034public class ContainerTest extends TestCase 035{ 036 //--ContainerTest----------------------------------------------------------- 037 038 /** The implementation to test. */ 039 private Container container; 040 041 /** Creates a new {@code ContainerTest} instance. */ 042 public ContainerTest() 043 { 044 super(); 045 } 046 047 /** 048 * Gets the {@code Container} implementation tests are performed with. 049 * 050 * @return the {@code Container} implementation tests are performed 051 * with. 052 */ 053 public Container getContainer() 054 { 055 return this.container; 056 } 057 058 /** 059 * Sets the {@code Container} implementation to test. 060 * 061 * @param value the {@code Container} implementation to test. 062 */ 063 public final void setContainer( final Container value ) 064 { 065 this.container = value; 066 } 067 068 //-----------------------------------------------------------ContainerTest-- 069 //--Tests------------------------------------------------------------------- 070 071 public void testGetDependency() throws Exception 072 { 073 try 074 { 075 this.getContainer().getDependency( (Object) null, "TEST" ); 076 throw new AssertionError( "Expected 'NullPointerException' not thrown." ); 077 } 078 catch ( final NullPointerException e ) 079 { 080 Assert.assertNotNull( e.getMessage() ); 081 System.out.println( e.toString() ); 082 } 083 084 try 085 { 086 this.getContainer().getDependency( this, null ); 087 throw new AssertionError( "Expected 'NullPointerException' not thrown." ); 088 } 089 catch ( final NullPointerException e ) 090 { 091 Assert.assertNotNull( e.getMessage() ); 092 System.out.println( e.toString() ); 093 } 094 } 095 096 public void testGetMessage() throws Exception 097 { 098 try 099 { 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}