001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.annotations; 016 017 import java.lang.reflect.Method; 018 019 import org.apache.hivemind.Location; 020 import org.apache.tapestry.enhance.EnhancementOperation; 021 import org.apache.tapestry.enhance.InjectObjectWorker; 022 import org.apache.tapestry.services.InjectedValueProvider; 023 import org.apache.tapestry.spec.IComponentSpecification; 024 import org.testng.annotations.Test; 025 026 /** 027 * Tests for {@link org.apache.tapestry.annotations.InjectObjectAnnotationWorker}. 028 * 029 * @author Howard M. Lewis Ship 030 * @since 4.0 031 */ 032 @Test 033 public class TestInjectObjectAnnotationWorker extends BaseAnnotationTestCase 034 { 035 public void testDefault() 036 { 037 InjectObjectAnnotationWorker worker = new InjectObjectAnnotationWorker(); 038 039 assertNotNull(worker._delegate); 040 } 041 042 public void testDelegation() 043 { 044 Location l = newLocation(); 045 046 EnhancementOperation op = newOp(); 047 IComponentSpecification spec = newSpec(); 048 049 InjectObjectWorker delegate = org.easymock.classextension.EasyMock.createNiceMock(InjectObjectWorker.class); 050 051 InjectedValueProvider provider = newMock(InjectedValueProvider.class); 052 053 delegate.setProvider(provider); 054 055 replay(); 056 org.easymock.classextension.EasyMock.replay(delegate); 057 058 InjectObjectAnnotationWorker worker = new InjectObjectAnnotationWorker(delegate); 059 worker.setProvider(provider); 060 061 verify(); 062 org.easymock.classextension.EasyMock.verify(delegate); 063 064 Method m = findMethod(AnnotatedPage.class, "getInjectedObject"); 065 066 delegate.injectObject(op, "barney", "injectedObject", l); 067 068 replay(); 069 070 worker.performEnhancement(op, spec, m, l); 071 072 verify(); 073 org.easymock.classextension.EasyMock.verify(delegate); 074 } 075 076 }