1 15 package org.apache.tapestry.components; 16 17 import org.apache.tapestry.IBinding; 18 import org.apache.tapestry.IComponent; 19 import org.apache.tapestry.IMarkupWriter; 20 import org.apache.tapestry.IRender; 21 import org.apache.tapestry.IRequestCycle; 22 import org.easymock.MockControl; 23 24 30 public class TestBlock extends BaseComponentTestCase 31 { 32 public void testRender() 33 { 34 final IComponent invoker = newComponent(); 35 36 final Block block = (Block) newInstance(Block.class); 37 38 IMarkupWriter writer = newWriter(); 39 IRequestCycle cycle = newCycle(); 40 41 replayControls(); 42 43 IRender body = new IRender() 44 { 45 public void render(IMarkupWriter writer, IRequestCycle cycle) 46 { 47 assertSame(block.getInvoker(), invoker); 48 assertSame(block.getInserter(), invoker); 49 } 50 }; 51 52 assertNull(block.getInvoker()); 53 54 block.addBody(body); 55 56 block.renderForComponent(writer, cycle, invoker); 57 58 assertNull(block.getInvoker()); 59 60 verifyControls(); 61 } 62 63 public void testGetParameter() 64 { 65 Object parameterValue = new Object (); 66 67 IBinding binding = newBinding(parameterValue); 68 69 MockControl control = newControl(IComponent.class); 70 IComponent component = (IComponent) control.getMock(); 71 72 component.getBinding("fred"); 73 control.setReturnValue(binding); 74 75 replayControls(); 76 77 Block block = (Block) newInstance(Block.class); 78 79 block.setInvoker(component); 80 81 assertSame(parameterValue, block.getParameter("fred")); 82 83 verifyControls(); 84 } 85 86 private IComponent newComponent() 87 { 88 return (IComponent) newMock(IComponent.class); 89 } 90 91 } 92 | Popular Tags |