1 package com.tonbeller.wcf.controller; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import junit.framework.TestCase; 7 8 10 11 public class DispatcherTest extends TestCase { 12 13 DispatcherSupport disp; 14 int count; 15 16 class MyListener implements RequestListener { 17 public void request(RequestContext context) { 18 ++ count; 19 } 20 } 21 22 public DispatcherTest(String name) { 23 super(name); 24 } 25 public static void main(String [] args) { 26 junit.textui.TestRunner.run(DispatcherTest.class); 27 } 28 29 public void setUp() { 30 disp = new DispatcherSupport(); 31 count = 0; 32 } 33 34 public void testLookup() throws Exception { 35 disp.addRequestListener("name1", "value1", new MyListener()); 36 disp.addRequestListener(null, "value2", new MyListener()); 37 disp.addRequestListener("name3", null, new MyListener()); 38 disp.addRequestListener(null, null, new MyListener()); 39 disp.addRequestListener("name5", null, new MyListener()); 40 41 check("name1", "value1", 2); 42 check("xxx", "value2", 2); 43 check("name3", "xxx", 2); 44 check("xxx", "xxx", 1); 45 check("name5", "123", 2); 46 check("name5.x", "123", 2); 48 } 49 50 private void check(String name, String value, int size) { 51 Map map = new HashMap (); 52 map.put(name, new String []{value}); 53 assertEquals(size, disp.findAll(map).size()); 54 } 55 } | Popular Tags |