File: NotificationCenterTest.java

package info (click to toggle)
piccolo 1.2-1.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,668 kB
  • sloc: java: 16,496; xml: 259; sh: 18; makefile: 13
file content (57 lines) | stat: -rw-r--r-- 1,736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import edu.umd.cs.piccolox.event.PNotification;
import edu.umd.cs.piccolox.event.PNotificationCenter;

import junit.framework.TestCase;

public class NotificationCenterTest extends TestCase {

	boolean changed1;
	boolean changed2;
	boolean changed3;
	boolean changed4;

	public NotificationCenterTest(String name) {
		super(name);
	}

	public void testToString() {
		PNotificationCenter center = PNotificationCenter.defaultCenter();
		
		center.addListener(this, "changed1", "propertyChanged", this);
		center.addListener(this, "changed2", null, this);
		center.addListener(this, "changed3", "propertyChanged", null);
		center.addListener(this, "changed4", null, null);
		
		center.postNotification("propertyChanged", this);
		assertTrue(changed1 && changed2 && changed3 && changed4);
		changed1 = changed2 = changed3 = changed4 = false;
		
		center.postNotification("propertyChanged", new Object());
		assertTrue(!changed1 && !changed2 && changed3 && changed4);
		changed1 = changed2 = changed3 = changed4 = false;

		center.postNotification("otherPropertyChanged", this);
		assertTrue(!changed1 && changed2 && !changed3 && changed4);
		changed1 = changed2 = changed3 = changed4 = false;

		center.postNotification("otherPropertyChanged", new Object());
		assertTrue(!changed1 && !changed2 && !changed3 && changed4);
		changed1 = changed2 = changed3 = changed4 = false;
	}
	
	public void changed1(PNotification notification) {
		changed1 = true;
	}

	public void changed2(PNotification notification) {
		changed2 = true;
	}
	
	public void changed3(PNotification notification) {
		changed3 = true;
	}

	public void changed4(PNotification notification) {
		changed4 = true;
	}	
}