Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c3d6a09c9d95b6a932fe35274c7cee58c3cf6143 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2018 Angelo ZERR.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 * Angelo Zerr <angelo.zerr@gmail.com> - [minimap] Initialize minimap view - Bug 535450
 *******************************************************************************/
package org.eclipse.ui.workbench.texteditor.tests.minimap;

import org.junit.Assert;
import org.junit.Test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.TextViewer;

import org.eclipse.ui.internal.views.minimap.MinimapPage;

import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.StatusTextEditor;

/**
 * Test create of Minimap page which is possible only if {@link ITextViewer} can be get from the
 * {@link ITextEditor}.
 *
 * @since 3.11
 */
public class MinimapPageTest {

	enum TextVieverAdapterKind {
		None, ITextViewer, ITextOperationTarget
	}

	static class MyTextEditor extends StatusTextEditor {

		private final TextVieverAdapterKind kind;

		public MyTextEditor(TextVieverAdapterKind kind) {
			this.kind= kind;
		}

		@Override
		public <T> T getAdapter(Class<T> required) {
			switch (kind) {
				case ITextViewer:
					if (ITextViewer.class.equals(required)) {
						Composite parent= new Shell();
						return required.cast(new TextViewer(parent, SWT.NONE));
					}
				case ITextOperationTarget:
					if (ITextOperationTarget.class.equals(required)) {
						Composite parent= new Shell();
						return required.cast(new TextViewer(parent, SWT.NONE));
					}
				case None:
				default:
					return null;
			}
		}
	}

	@Test
	public void createNoneMinimapPage() {
		ITextEditor textEditor= new MyTextEditor(TextVieverAdapterKind.None);
		MinimapPage page= MinimapPage.createMinimapPage(textEditor);
		Assert.assertNull(page);
	}

	@Test
	public void createMinimapPageWithITextViewerAdapter() {
		ITextEditor textEditor= new MyTextEditor(TextVieverAdapterKind.ITextViewer);
		MinimapPage page= MinimapPage.createMinimapPage(textEditor);
		Assert.assertNotNull(page);
	}

	@Test
	public void createMinimapPageWithITextOperationTargetAdapter() {
		ITextEditor textEditor= new MyTextEditor(TextVieverAdapterKind.ITextOperationTarget);
		MinimapPage page= MinimapPage.createMinimapPage(textEditor);
		Assert.assertNotNull(page);
	}
}

Back to the top