Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1753b182b0e3bcd31cec852ebeab44088ecd6ff8 (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
/*******************************************************************************
 * Copyright (c) 2005, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ua.tests.cheatsheet.composite;

import org.eclipse.ui.cheatsheets.CheatSheetListener;
import org.eclipse.ui.cheatsheets.ICheatSheetEvent;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;

import junit.framework.TestCase;

public class TestCheatSheetManagerEvents extends TestCase {
	
	private CheatSheetElement element;
	private CheatSheetManager manager;
	private int handler1Calls;
	private int handler2Calls;
	
	private class Handler1 extends CheatSheetListener {
		@Override
		public void cheatSheetEvent(ICheatSheetEvent event) {
			handler1Calls++;		
		}	
	}
	
	private class Handler2 extends CheatSheetListener {
		@Override
		public void cheatSheetEvent(ICheatSheetEvent event) {
			handler2Calls++;		
		}	
	}

	@Override
	protected void setUp() throws Exception {
		element = new CheatSheetElement("Name");
		manager = new CheatSheetManager(element);
		handler1Calls = 0;
		handler2Calls = 0;
	}
	
	public void testNoHandler() {
		manager.fireEvent(ICheatSheetEvent.CHEATSHEET_STARTED);
	}
	
	public void testOneHandler() {
		manager.addListener(new Handler1());
		manager.fireEvent(ICheatSheetEvent.CHEATSHEET_STARTED);
		assertEquals(1, handler1Calls);
	}
	
	public void testTwoHandlers() {
		manager.addListener(new Handler1());
		manager.addListener(new Handler2());
		manager.fireEvent(ICheatSheetEvent.CHEATSHEET_STARTED);
		assertEquals(1, handler1Calls);
		assertEquals(1, handler2Calls);
	}

}

Back to the top