1 15 package org.apache.tapestry; 16 17 import org.apache.hivemind.Messages; 18 import org.apache.hivemind.test.HiveMindTestCase; 19 import org.apache.tapestry.test.Creator; 20 import org.easymock.MockControl; 21 22 30 public class TestComponentMessageAccess extends HiveMindTestCase 31 { 32 private AbstractComponent newComponent(Messages messages) 33 { 34 Creator c = new Creator(); 35 36 return (AbstractComponent) c.newInstance(AbstractComponent.class, new Object [] 37 { "messages", messages }); 38 } 39 40 public void testGetMessage() 41 { 42 MockControl control = newControl(Messages.class); 43 Messages m = (Messages) control.getMock(); 44 45 m.getMessage("fred"); 46 control.setReturnValue("flintstone"); 47 48 AbstractComponent ac = newComponent(m); 49 50 replayControls(); 51 52 assertEquals("flintstone", ac.getMessage("fred")); 53 54 verifyControls(); 55 } 56 57 public void testFormat() 58 { 59 MockControl control = newControl(Messages.class); 60 Messages m = (Messages) control.getMock(); 61 62 m.format("fred", "flintstone"); 63 control.setReturnValue("Fred Flintstone"); 64 65 AbstractComponent ac = newComponent(m); 66 67 replayControls(); 68 69 assertEquals("Fred Flintstone", ac.format("fred", "flintstone")); 70 71 verifyControls(); 72 73 m.format("fred", "wilma", "dino"); 74 control.setReturnValue("flintstone family"); 75 76 replayControls(); 77 78 assertEquals("flintstone family", ac.format("fred", "wilma", "dino")); 79 80 verifyControls(); 81 82 m.format("fred", "wilma", "dino", "pebbles"); 83 control.setReturnValue("flintstone family 2"); 84 85 replayControls(); 86 87 assertEquals("flintstone family 2", ac.format("fred", "wilma", "dino", "pebbles")); 88 89 verifyControls(); 90 91 Object [] arguments = new String [] 92 { "flinstone" }; 93 94 m.format("fred", arguments); 95 control.setReturnValue("flintstone family 3"); 96 97 replayControls(); 98 99 assertEquals("flintstone family 3", ac.format("fred", arguments)); 100 101 verifyControls(); 102 103 } 104 } 105 | Popular Tags |