forked from dsldevkit/dsl-devkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dsldevkit#51: Autocorrect to add check to configuration does not put …
…string params in quotes * Extract the code for creating a literal-value template pattern from CheckCfgTemplateProposalProvider into a new helper, TemplateProposalProviderHelper, where it can be unit tested. * Avoid getting a JvmType representation of String just to check the type of a Check parameter. * CheckConfiguration template now gets the check configuration name from the filename instead of using hardwired value "name". * Move ResourceNameTemplateVariableResolver from ddk.check.ui to ddk.xtext.ui so CheckCfgTemplateProposalProvider can use it. Changed its 'catalog' parameter value to 'file' to better reflect its meaning. * Add unit tests for ** ResourceNameTemplateVariableResolver (only when resolving a filename; resolving a package name looks much less testable and hasn't been touched) ** SimpleEnumTemplateVariableResolver ** TemplateProposalProviderHelper Issue-Id: dsldevkit#51
- Loading branch information
1 parent
b8d3463
commit 2261b4b
Showing
21 changed files
with
688 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="output" path="bin"/> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="src" path="xtend-gen"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
source.. = src/ | ||
source.. = src/,\ | ||
xtend-gen/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
. |
126 changes: 126 additions & 0 deletions
126
...src/com/avaloq/tools/ddk/xtext/ui/templates/ResourceNameTemplateVariableResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 Avaloq Evolution AG 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: | ||
* Avaloq Evolution AG - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package com.avaloq.tools.ddk.xtext.ui.templates; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.jface.text.templates.TemplateException; | ||
import org.eclipse.jface.text.templates.TemplateVariable; | ||
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.mockito.Mockito; | ||
|
||
import com.google.common.collect.Iterables; | ||
import com.google.inject.Guice; | ||
|
||
|
||
public class ResourceNameTemplateVariableResolverTest { | ||
|
||
private static final Object[] FILE = new Object[] {"file"}; //$NON-NLS-1$ | ||
private static final String FILENAME = "filename"; //$NON-NLS-1$ | ||
|
||
private static XtextTemplateContext mockContext; | ||
private static IXtextDocument mockDocument; | ||
private static IFile mockFile; | ||
|
||
private static TemplateVariableResolverTestHelper helper; | ||
|
||
private static ResourceNameTemplateVariableResolver resolver; | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
mockContext = Mockito.mock(XtextTemplateContext.class); | ||
mockDocument = Mockito.mock(IXtextDocument.class); | ||
mockFile = Mockito.mock(IFile.class); | ||
|
||
helper = Guice.createInjector(new XtextRuntimeModule()).getInstance(TemplateVariableResolverTestHelper.class); | ||
|
||
resolver = new ResourceNameTemplateVariableResolver(); | ||
|
||
Mockito.when(mockContext.getDocument()).thenReturn(mockDocument); | ||
Mockito.when(mockDocument.getAdapter(IFile.class)).thenReturn(mockFile); | ||
} | ||
|
||
@AfterClass | ||
public static void afterClass() { | ||
mockContext = null; | ||
mockDocument = null; | ||
mockFile = null; | ||
|
||
helper = null; | ||
|
||
resolver = null; | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public void testResolveValuesWithNullVariable() { | ||
resolver.resolveValues(null, mockContext); | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public void testResolveValuesWithNullContext() { | ||
resolver.resolveValues(Mockito.mock(TemplateVariable.class), null); | ||
} | ||
|
||
@Test | ||
public void testResolveValuesWithFileWithoutExtension() throws TemplateException { | ||
final String filename = "filenamewithnoextension"; //$NON-NLS-1$ | ||
testResolveValues(FILE, filename, filename); | ||
} | ||
|
||
@Test | ||
public void testResolveValuesWithFileWithExtension() throws TemplateException { | ||
testResolveValues(FILE, "filename.with.extension", "filename.with"); //$NON-NLS-1$//$NON-NLS-2$ | ||
} | ||
|
||
@Test | ||
public void testResolveValuesWithExtraParams() throws TemplateException { | ||
testResolveValues(new Object[] {FILE[0], "other", "random", "values"}, FILENAME, FILENAME); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | ||
} | ||
|
||
@Test | ||
public void testResolveValuesWithUnknownParam() throws TemplateException { | ||
testResolveValues(new Object[] {"This is not the parameter you are looking for"}, FILENAME); //$NON-NLS-1$ | ||
} | ||
|
||
@Test | ||
public void testResolveValuesWithWrongTypeOfParam() throws TemplateException { | ||
testResolveValues(new Object[] {42}, FILENAME); | ||
} | ||
|
||
/** | ||
* Test resolveValues(). | ||
* | ||
* @param values | ||
* values to resolve | ||
* @param filename | ||
* filename to return from the mock {@link IFile} | ||
* @param expectedResolvedValues | ||
* expected return value | ||
*/ | ||
public void testResolveValues(final Object[] values, final String filename, final String... expectedResolvedValues) throws TemplateException { | ||
// ARRANGE | ||
final TemplateVariable variable = helper.createTemplateVariable(resolver, "name", values); //$NON-NLS-1$ | ||
Mockito.when(mockFile.getName()).thenReturn(filename); | ||
|
||
// ACT | ||
final String[] actualResolvedValues = Iterables.toArray(resolver.resolveValues(variable, mockContext), String.class); | ||
|
||
// ASSERT | ||
Assert.assertArrayEquals(expectedResolvedValues, actualResolvedValues); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...t/src/com/avaloq/tools/ddk/xtext/ui/templates/SimpleEnumTemplateVariableResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 Avaloq Evolution AG 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: | ||
* Avaloq Evolution AG - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package com.avaloq.tools.ddk.xtext.ui.templates; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jface.text.templates.TemplateException; | ||
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 com.google.inject.Guice; | ||
|
||
|
||
public class SimpleEnumTemplateVariableResolverTest { | ||
|
||
private static XtextTemplateContext mockContext; | ||
private static TemplateVariableResolverTestHelper helper; | ||
private static SimpleEnumTemplateVariableResolver resolver; | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
mockContext = mock(XtextTemplateContext.class); | ||
helper = Guice.createInjector(new XtextRuntimeModule()).getInstance(TemplateVariableResolverTestHelper.class); | ||
resolver = new SimpleEnumTemplateVariableResolver(); | ||
} | ||
|
||
@AfterClass | ||
public static void afterClass() { | ||
mockContext = null; | ||
helper = null; | ||
resolver = null; | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public void testResolveValuesWithNullVariable() { | ||
resolver.resolveValues(null, mockContext); | ||
} | ||
|
||
public void testResolveValuesWithNoParams() throws TemplateException { | ||
testResolveValues(); | ||
} | ||
|
||
public void testResolveValuesWithOneParam() throws TemplateException { | ||
testResolveValues("Value"); //$NON-NLS-1$ | ||
} | ||
|
||
public void testResolveValuesWithMultipleParams() throws TemplateException { | ||
testResolveValues("Value 1", "Value 2", "Value 3"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ | ||
} | ||
|
||
private void testResolveValues(final Object... values) throws TemplateException { | ||
// ARRANGE | ||
final TemplateVariable variable = helper.createTemplateVariable(resolver, "name", values); //$NON-NLS-1$ | ||
|
||
// ACT | ||
final List<String> resolvedValues = resolver.resolveValues(variable, mockContext); | ||
|
||
// ASSERT | ||
assertArrayEquals(values, resolvedValues.toArray(new String[resolvedValues.size()])); | ||
} | ||
|
||
} |
Oops, something went wrong.