Skip to content

Commit

Permalink
dsldevkit#51: Autocorrect to add check to configuration does not put …
Browse files Browse the repository at this point in the history
…string

params in quotes

* Use @BeforeAll and @afterall instead of @BeforeClass and @afterclass.
* Remove SimpleEnumTemplateVariableResolverTest.testResolveValuesWithNoParams().
  Since TemplateVariableType cannot be mocked, and TemplateVariable
  cannot be created with 0 values, this test case is untestable.
* Add missing @throws documentation to
  TemplateVariableResolverTestHelper.createTemplateVariable().
* XtextUiTestSuite.launch now runs tests in alphanumeric order to match
  the order used by Maven, to make it easier to reproduce failures
  locally.

Issue-Id: dsldevkit#51
  • Loading branch information
GrahamPearsonAvaloq committed Feb 15, 2018
1 parent 21349b2 commit 39feba2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion com.avaloq.tools.ddk.xtext.ui.test/XtextUiTestSuite.launch
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.avaloq.tools.ddk.xtext.ui.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcom.avaloq.test.sorter=alphanumeric&#13;&#10;-ea"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
<booleanAttribute key="show_selected_only" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@
import org.eclipse.xtext.XtextRuntimeModule;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.editor.templates.XtextTemplateContext;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;

import com.avaloq.tools.ddk.test.core.AfterAll;
import com.avaloq.tools.ddk.test.core.BeforeAll;
import com.avaloq.tools.ddk.test.core.junit.runners.ClassRunner;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;


@RunWith(ClassRunner.class)
public class ResourceNameTemplateVariableResolverTest {

private static final Object[] FILE = new Object[] {"file"}; //$NON-NLS-1$
Expand All @@ -40,8 +43,8 @@ public class ResourceNameTemplateVariableResolverTest {

private static ResourceNameTemplateVariableResolver resolver;

@BeforeClass
public static void beforeClass() {
@BeforeAll
public void beforeAll() {
mockContext = Mockito.mock(XtextTemplateContext.class);
mockDocument = Mockito.mock(IXtextDocument.class);
mockFile = Mockito.mock(IFile.class);
Expand All @@ -54,8 +57,8 @@ public static void beforeClass() {
Mockito.when(mockDocument.getAdapter(IFile.class)).thenReturn(mockFile);
}

@AfterClass
public static void afterClass() {
@AfterAll
public void afterAll() {
mockContext = null;
mockDocument = null;
mockFile = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,31 @@
import org.eclipse.jface.text.templates.TemplateVariable;
import org.eclipse.xtext.XtextRuntimeModule;
import org.eclipse.xtext.ui.editor.templates.XtextTemplateContext;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.avaloq.tools.ddk.test.core.AfterAll;
import com.avaloq.tools.ddk.test.core.BeforeAll;
import com.avaloq.tools.ddk.test.core.junit.runners.ClassRunner;
import com.google.inject.Guice;


@RunWith(ClassRunner.class)
public class SimpleEnumTemplateVariableResolverTest {

private static XtextTemplateContext mockContext;
private static TemplateVariableResolverTestHelper helper;
private static SimpleEnumTemplateVariableResolver resolver;

@BeforeClass
public static void beforeClass() {
@BeforeAll
public void beforeAll() {
mockContext = mock(XtextTemplateContext.class);
helper = Guice.createInjector(new XtextRuntimeModule()).getInstance(TemplateVariableResolverTestHelper.class);
resolver = new SimpleEnumTemplateVariableResolver();
}

@AfterClass
public static void afterClass() {
@AfterAll
public void afterAll() {
mockContext = null;
helper = null;
resolver = null;
Expand All @@ -52,14 +55,12 @@ public void testResolveValuesWithNullVariable() {
resolver.resolveValues(null, mockContext);
}

public void testResolveValuesWithNoParams() throws TemplateException {
testResolveValues();
}

@Test
public void testResolveValuesWithOneParam() throws TemplateException {
testResolveValues("Value"); //$NON-NLS-1$
}

@Test
public void testResolveValuesWithMultipleParams() throws TemplateException {
testResolveValues("Value 1", "Value 2", "Value 3"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

package com.avaloq.tools.ddk.xtext.ui.templates

import com.avaloq.tools.ddk.test.core.AfterAll
import com.avaloq.tools.ddk.test.core.BeforeAll
import com.avaloq.tools.ddk.test.core.junit.runners.ClassRunner
import com.google.inject.Guice
import org.eclipse.jface.text.IDocument
import org.eclipse.jface.text.IRegion
Expand All @@ -19,9 +22,8 @@ import org.eclipse.jface.text.templates.Template
import org.eclipse.xtext.XtextRuntimeModule
import org.eclipse.xtext.ui.editor.templates.XtextTemplateContext
import org.eclipse.xtext.ui.editor.templates.XtextTemplateContextType
import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith

import static org.junit.Assert.assertArrayEquals
import static org.junit.Assert.assertEquals
Expand All @@ -31,6 +33,7 @@ import static org.mockito.Mockito.spy
import static org.mockito.Mockito.verify
import static org.mockito.Mockito.when

@RunWith(ClassRunner)
public class TemplateProposalProviderHelperTest {

static val SIMPLE_ENUM_VARIABLE_TYPE = new SimpleEnumTemplateVariableResolver().type
Expand All @@ -50,8 +53,8 @@ public class TemplateProposalProviderHelperTest {

static var TemplateProposalProviderHelper helper

@BeforeClass
def static void beforeClass() {
@BeforeAll
def void beforeAll() {
mockDocument = mock(IDocument)
mockPosition = mock(Position)
mockRegion = mock(IRegion)
Expand All @@ -66,8 +69,8 @@ public class TemplateProposalProviderHelperTest {
when(mockDocument.get(anyInt, anyInt)).thenReturn("")
}

@AfterClass
def static void afterClass() {
@AfterAll
def void afterAll() {
mockDocument = null
mockPosition = null
mockRegion = null
Expand All @@ -87,6 +90,7 @@ public class TemplateProposalProviderHelperTest {
helper.createLiteralValuePattern("Contains whitespace", 42)
}

@Test
def void testCreateLiteralValuePatternWithNullDefaultValue() {
testCreateLiteralValuePattern(null, RETURNED_PATTERN, RETURNED_PATTERN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ public class TemplateVariableResolverTestHelper {
* @param values
* the values available at this variable, non-empty, may not be {@code null}
* @return a {@link TemplateVariable}
* @throws TemplateException
* @throws {@link
* NullPointerException} if resolver.getType(), name or values is null
* @throws {@link
* IllegalArgumentException} if resolver.getType() or name contains whitespace or values is empty
* @throws {@link
* TemplateException}
* if translation failed
*/
public TemplateVariable createTemplateVariable(final TemplateVariableResolver resolver, final String name, final Object... values) throws TemplateException {
public TemplateVariable createTemplateVariable(final TemplateVariableResolver resolver, final String name, final Object... values) throws NullPointerException, IllegalArgumentException, TemplateException {

// Jump through hoops to create a real TemplateVariable because TemplateVariableType is final thus cannot be mocked,
// and has protected constructors thus cannot be directly instantiated
Expand Down

0 comments on commit 39feba2

Please sign in to comment.