001 /***************************************************************************** 002 * Copyright (C) PicoContainer Organization. All rights reserved. * 003 * ------------------------------------------------------------------------- * 004 * The software in this package is published under the terms of the BSD * 005 * style license a copy of which has been included with this distribution in * 006 * the LICENSE.txt file. * 007 * * 008 * Original code by * 009 *****************************************************************************/ 010 package org.picocontainer.parameters; 011 012 import static org.junit.Assert.*; 013 014 import java.lang.reflect.Constructor; 015 import java.lang.reflect.Type; 016 017 import org.junit.Test; 018 import org.picocontainer.PicoCompositionException; 019 020 021 /** 022 * test that constant parameter behaves well. 023 * @author Konstantin Pribluda 024 */ 025 public class ConstantParameterTestCase { 026 027 /** 028 * constant parameter with instance type shall verify for expected primitives 029 * @throws Exception 030 */ 031 @Test public void testThatInstaceTypeAcceptedForPrimitives() throws Exception { 032 ConstantParameter param = new ConstantParameter(239); 033 try{ 034 param.verify(null,null,Integer.TYPE, null, false, null); 035 } catch(PicoCompositionException ex) { 036 fail("failed verification for primitive / instance "); 037 } 038 } 039 040 @Test 041 public void testClassTypesAllowed() throws Exception { 042 ConstantParameter param = new ConstantParameter(String.class); 043 param.verify(null, null, Class.class, null, false, null); 044 } 045 046 047 public static class ConstantParameterTestClass { 048 public ConstantParameterTestClass(Class<String> type) { 049 assert type != null; 050 } 051 } 052 053 054 @Test 055 public void testParameterizedTypesAllowed() throws Exception { 056 057 Constructor<?>[] ctors = ConstantParameterTestClass.class.getConstructors(); 058 Type[] t = ctors[0].getGenericParameterTypes(); 059 ConstantParameter param = new ConstantParameter(String.class); 060 assertTrue(param.resolve(null, null, null, t[0], null, false, null).isResolved()); 061 062 } 063 064 }