diff --git a/com.avaloq.tools.ddk.xtext.ui.test/XtextUiTestSuite.launch b/com.avaloq.tools.ddk.xtext.ui.test/XtextUiTestSuite.launch index c60b25100..5228b2a3f 100644 --- a/com.avaloq.tools.ddk.xtext.ui.test/XtextUiTestSuite.launch +++ b/com.avaloq.tools.ddk.xtext.ui.test/XtextUiTestSuite.launch @@ -28,7 +28,7 @@ - + diff --git a/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/ResourceNameTemplateVariableResolverTest.java b/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/ResourceNameTemplateVariableResolverTest.java index 04e969e33..d74fdd6f1 100644 --- a/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/ResourceNameTemplateVariableResolverTest.java +++ b/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/ResourceNameTemplateVariableResolverTest.java @@ -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$ @@ -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); @@ -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; diff --git a/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/SimpleEnumTemplateVariableResolverTest.java b/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/SimpleEnumTemplateVariableResolverTest.java index 2c1959c2d..cf0f49b34 100644 --- a/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/SimpleEnumTemplateVariableResolverTest.java +++ b/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/SimpleEnumTemplateVariableResolverTest.java @@ -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; @@ -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$ } diff --git a/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/TemplateProposalProviderHelperTest.xtend b/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/TemplateProposalProviderHelperTest.xtend index 3b7032bd5..cdc930c52 100644 --- a/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/TemplateProposalProviderHelperTest.xtend +++ b/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/TemplateProposalProviderHelperTest.xtend @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 @@ -87,6 +90,7 @@ public class TemplateProposalProviderHelperTest { helper.createLiteralValuePattern("Contains whitespace", 42) } + @Test def void testCreateLiteralValuePatternWithNullDefaultValue() { testCreateLiteralValuePattern(null, RETURNED_PATTERN, RETURNED_PATTERN) } diff --git a/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/TemplateVariableResolverTestHelper.java b/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/TemplateVariableResolverTestHelper.java index 277d3313d..bb7f5497f 100644 --- a/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/TemplateVariableResolverTestHelper.java +++ b/com.avaloq.tools.ddk.xtext.ui.test/src/com/avaloq/tools/ddk/xtext/ui/templates/TemplateVariableResolverTestHelper.java @@ -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