KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > control > PropertyPollingTest


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.monitor.control;
5
6 import java.util.Map JavaDoc;
7
8 import junit.framework.TestCase;
9
10 import org.oddjob.monitor.model.DetailModel;
11 import org.oddjob.monitor.model.ExplorerContext;
12 import org.oddjob.monitor.model.ExplorerModel;
13 import org.oddjob.monitor.model.PropertyModel;
14
15 public class PropertyPollingTest extends TestCase {
16
17     public static class Comp {
18         public String JavaDoc getFruit() {
19             return "apples";
20         }
21     }
22     
23     /**
24      * Test what happens when the property tab
25      * is selected.
26      *
27      */

28     public void testSelected() {
29         
30         PropertyModel model = new PropertyModel();
31         
32         PropertyPolling test = new PropertyPolling(this);
33         test.setPropertyModel(model);
34
35         DetailModel detailModel = new DetailModel();
36         detailModel.addObserver(test);
37         detailModel.setTabSelected(DetailModel.PROPERTIES_TAB);
38
39         Comp sample = new Comp();
40         ExplorerModel em = new ExplorerModel();
41         em.setRoot(sample);
42         ExplorerContext ec = new ExplorerContext(em);
43         detailModel.select(ec, sample);
44         
45         test.poll();
46         
47         String JavaDoc result = (String JavaDoc) model.getProperties().get("fruit");
48         assertEquals("apples", result);
49     }
50     
51     /**
52      * Test what happens when the property tab
53      * is unselected.
54      *
55      */

56     public void testNotSelected() {
57         
58         PropertyModel model = new PropertyModel();
59         
60         PropertyPolling test = new PropertyPolling(this);
61         test.setPropertyModel(model);
62
63         DetailModel detailModel = new DetailModel();
64         detailModel.addObserver(test);
65
66         Object JavaDoc root = new Object JavaDoc();
67         ExplorerModel em = new ExplorerModel();
68         em.setRoot(root);
69         ExplorerContext ec = new ExplorerContext(em);
70         detailModel.select(ec, null);
71         
72         test.poll();
73         
74         Map JavaDoc props = model.getProperties();
75         assertEquals(0, props.size());
76     }
77     
78 }
79
Popular Tags