1 19 package org.apache.mina.example.haiku; 20 21 import org.apache.mina.common.IoHandler; 22 import org.apache.mina.common.IoSession; 23 import org.jmock.Mock; 24 import org.jmock.MockObjectTestCase; 25 26 30 public class HaikuValidatorIoHandlerTest extends MockObjectTestCase { 31 private IoHandler handler; 32 33 @Override 34 protected void setUp() throws Exception { 35 super.setUp(); 36 37 handler = new HaikuValidatorIoHandler(); 38 } 39 40 public void testValidHaiku() throws Exception { 41 Mock session = mock(IoSession.class); 42 session.expects(once()).method("write").with(eq("HAIKU!")); 43 IoSession sessionProxy = (IoSession) session.proxy(); 44 45 handler.messageReceived(sessionProxy, new Haiku( 46 "Oh, I drank too much.", "Why, oh why did I sign up", 47 "For an eight thirty?")); 48 } 49 50 public void testInvalidHaiku() throws Exception { 51 Mock session = mock(IoSession.class); 52 session.expects(once()).method("write").with( 53 eq("NOT A HAIKU: phrase 1, 'foo' had 1 syllables, not 5")); 54 IoSession sessionProxy = (IoSession) session.proxy(); 55 56 handler.messageReceived(sessionProxy, 57 new Haiku("foo", "a haiku", "poo")); 58 } 59 } 60 | Popular Tags |