Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a46bc62f16b2825887b170cdc860b5fcc38bd2b1 (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
/*******************************************************************************
 * Copyright (c) 2016, 2018 Obeo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors: Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.eef.tests.internal.controllers;

import java.util.concurrent.atomic.AtomicBoolean;

import org.eclipse.eef.EEFLabelDescription;
import org.eclipse.eef.core.api.controllers.IEEFLabelController;
import org.eclipse.eef.core.internal.controllers.EEFLabelController;
import org.eclipse.eef.tests.internal.EEFDataTests;
import org.eclipse.emf.ecore.EClassifier;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

import static org.junit.Assert.assertTrue;

/**
 * Unit tests for the {@link IEEFLabelController}.
 *
 * @author sbegaudeau
 */
@SuppressWarnings({ "checkstyle:javadocmethod" })
public class EEFLabelControllerTests extends AbstractEEFControllerTests {
	/**
	 * The name of the Project EClass.
	 */
	private static final String PROJECT_ECLASS_NAME = "Project"; //$NON-NLS-1$

	private IEEFLabelController labelController(String modelPath) {
		EClassifier eClassifier = this.ePackage(DART_ECORE, 0).getEClassifier(PROJECT_ECLASS_NAME);
		EEFLabelDescription description = widget(group(page(modelPath, 0), 0), EEFLabelDescription.class, 0);
		return new EEFLabelController(description, newVariableManager(eClassifier), this.interpreter, this.contextAdapter);
	}

	@Test
	public void testLabel() {
		testLabel(labelController(EEFDataTests.EEFLABELCONTROLLERTESTS_LABEL), "Documentation:"); //$NON-NLS-1$
	}

	@Test
	public void testHelp() {
		testHelp(labelController(EEFDataTests.EEFLABELCONTROLLERTESTS_HELP), "Documentation Help"); //$NON-NLS-1$
	}

	@Test
	public void testBody() {
		AtomicBoolean atomicBoolean = new AtomicBoolean(false);
		IEEFLabelController controller = this.labelController(EEFDataTests.EEFLABELCONTROLLERTESTS_BODY);
		controller.onNewValue(label -> {
			assertThat(label, is("This is the documentation of the project")); //$NON-NLS-1$
			atomicBoolean.set(true);
		});
		controller.refresh();
		assertTrue(atomicBoolean.get());
	}
}

Back to the top