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.enhance; 016 017 import static org.easymock.EasyMock.expect; 018 019 import org.apache.tapestry.BaseComponentTestCase; 020 import org.apache.tapestry.IComponent; 021 import org.apache.tapestry.spec.IComponentSpecification; 022 import org.testng.annotations.Test; 023 024 /** 025 * Tests for {@link TestInjectListenerRegistrationWorker}. 026 * 027 * @author Howard M. Lewis Ship 028 * @since 4.0 029 */ 030 @Test 031 public class TestInjectListenerRegistrationWorker extends BaseComponentTestCase 032 { 033 034 public void testNonMatch() 035 { 036 EnhancementOperation op = newMock(EnhancementOperation.class); 037 038 IComponentSpecification spec = newSpec(); 039 040 expect(op.implementsInterface(Runnable.class)).andReturn(false); 041 042 replay(); 043 044 InjectListenerRegistrationWorker w = new InjectListenerRegistrationWorker(); 045 w.setListenerInterface(Runnable.class); 046 047 w.performEnhancement(op, spec); 048 049 verify(); 050 } 051 052 public void testMatch() 053 { 054 EnhancementOperation op = newMock(EnhancementOperation.class); 055 056 IComponentSpecification spec = newSpec(); 057 058 expect(op.implementsInterface(IComponent.class)).andReturn(true); 059 060 op.extendMethodImplementation( 061 IComponent.class, 062 EnhanceUtils.FINISH_LOAD_SIGNATURE, 063 "getPage().addThisComponentAsListener(this);"); 064 065 replay(); 066 067 InjectListenerRegistrationWorker w = new InjectListenerRegistrationWorker(); 068 w.setListenerInterface(IComponent.class); 069 w.setRegisterMethodName("addThisComponentAsListener"); 070 071 w.performEnhancement(op, spec); 072 073 verify(); 074 } 075 076 }