diff options
author | Lars Vogel | 2016-01-30 15:24:32 +0000 |
---|---|---|
committer | Lars Vogel | 2016-01-30 23:32:29 +0000 |
commit | fdfe9878fed51da5cf72454dea079a13b139d607 (patch) | |
tree | 0bc1f26f3c4048351ec046119bcba06962f565f6 /org.eclipse.text.tests | |
parent | 94c39a4e3ae778044d0fc97947ec53dc720e98f2 (diff) | |
download | eclipse.platform.text-fdfe9878fed51da5cf72454dea079a13b139d607.tar.gz eclipse.platform.text-fdfe9878fed51da5cf72454dea079a13b139d607.tar.xz eclipse.platform.text-fdfe9878fed51da5cf72454dea079a13b139d607.zip |
Bug 486889 - Migrated TemplatesTestSuite to JUnit 4I20160202-1000I20160202-0800
Change-Id: I9b2f4194d765e59a39c59a85db724c03b95c8cfe
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
Diffstat (limited to 'org.eclipse.text.tests')
4 files changed, 76 insertions, 52 deletions
diff --git a/org.eclipse.text.tests/src/org/eclipse/text/tests/EclipseTextTestSuite.java b/org.eclipse.text.tests/src/org/eclipse/text/tests/EclipseTextTestSuite.java index ced70cd9966..4bd88113087 100644 --- a/org.eclipse.text.tests/src/org/eclipse/text/tests/EclipseTextTestSuite.java +++ b/org.eclipse.text.tests/src/org/eclipse/text/tests/EclipseTextTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2016 IBM Corporation 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 @@ -7,15 +7,17 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Lars Vogel <Lars.Vogel@vogella.com> - Bug 486889 *******************************************************************************/ package org.eclipse.text.tests; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.eclipse.text.tests.link.LinkTestSuite; import org.eclipse.text.tests.templates.TemplatesTestSuite; +import junit.framework.JUnit4TestAdapter; +import junit.framework.Test; +import junit.framework.TestSuite; + /** * Test Suite for org.eclipse.text. @@ -45,7 +47,7 @@ public class EclipseTextTestSuite { suite.addTest(TextUtilitiesTest.suite()); suite.addTest(AnnotationModelStressTest.suite()); suite.addTest(AnnotationModelExtension2Test.suite()); - suite.addTest(TemplatesTestSuite.suite()); + suite.addTest(new JUnit4TestAdapter(TemplatesTestSuite.class)); //$JUnit-END$ return suite; diff --git a/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/GlobalTemplateVariablesDateTest.java b/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/GlobalTemplateVariablesDateTest.java index 08222f20817..3f714c48cb7 100644 --- a/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/GlobalTemplateVariablesDateTest.java +++ b/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/GlobalTemplateVariablesDateTest.java @@ -7,13 +7,20 @@ * * Contributors: * BSI Business Systems Integration AG - initial API and implementation + * Lars Vogel <Lars.Vogel@vogella.com> - Bug 486889 *******************************************************************************/ package org.eclipse.text.tests.templates; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import com.ibm.icu.text.DateFormat; import com.ibm.icu.text.SimpleDateFormat; import com.ibm.icu.util.ULocale; +import org.junit.Before; +import org.junit.Test; + import org.eclipse.jface.text.Document; import org.eclipse.jface.text.templates.DocumentTemplateContext; import org.eclipse.jface.text.templates.GlobalTemplateVariables; @@ -22,14 +29,7 @@ import org.eclipse.jface.text.templates.TemplateContextType; import org.eclipse.jface.text.templates.TemplateTranslator; import org.eclipse.jface.text.templates.TemplateVariable; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class GlobalTemplateVariablesDateTest extends TestCase { - public static Test suite() { - return new TestSuite(GlobalTemplateVariablesDateTest.class); - } +public class GlobalTemplateVariablesDateTest { private TemplateTranslator fTranslator; @@ -37,9 +37,8 @@ public class GlobalTemplateVariablesDateTest extends TestCase { private TemplateContextType fType; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { fTranslator= new TemplateTranslator(); fType= new TemplateContextType(); @@ -47,7 +46,8 @@ public class GlobalTemplateVariablesDateTest extends TestCase { fContext= new DocumentTemplateContext(fType, new Document(), 0, 0); } - + + @Test public void testWithoutParameter() throws Exception { TemplateBuffer buffer= fTranslator.translate("Today is ${date}!"); fType.resolve(buffer, fContext); @@ -58,7 +58,8 @@ public class GlobalTemplateVariablesDateTest extends TestCase { expected.append("!"); assertBufferStringAndVariables(expected.toString(), buffer); } - + + @Test public void testOneParameter() throws Exception { TemplateBuffer buffer= fTranslator.translate("This format ${d:date('dd MMM YYYY')} and not ${p:date('YYYY-MM-dd')}"); fType.resolve(buffer, fContext); @@ -71,6 +72,7 @@ public class GlobalTemplateVariablesDateTest extends TestCase { assertBufferStringAndVariables(expected.toString(), buffer); } + @Test public void testSimpleLocale() throws Exception { TemplateBuffer buffer= fTranslator.translate("From ${d:date('dd MMM YYYY', 'fr')} to ${d}"); fType.resolve(buffer, fContext); @@ -83,6 +85,7 @@ public class GlobalTemplateVariablesDateTest extends TestCase { assertBufferStringAndVariables(expected.toString(), buffer); } + @Test public void testComplexLocale() throws Exception { TemplateBuffer buffer= fTranslator.translate("France ${d:date('EEEE dd MMMM YYYY', 'fr_FR')} and Germany ${p:date('EEEE dd. MMMM YYYY', 'de_DE')}"); fType.resolve(buffer, fContext); @@ -95,6 +98,7 @@ public class GlobalTemplateVariablesDateTest extends TestCase { assertBufferStringAndVariables(expected.toString(), buffer); } + @Test public void testInvalidDateFormat() throws Exception { TemplateBuffer buffer= fTranslator.translate("Today is ${d:date('invalid')}!"); fType.resolve(buffer, fContext); @@ -106,6 +110,7 @@ public class GlobalTemplateVariablesDateTest extends TestCase { assertBufferStringAndVariables(expected.toString(), buffer); } + @Test public void testInvalidLocale() throws Exception { TemplateBuffer buffer= fTranslator.translate("Today is ${d:date('YYYY-MM-dd', 'this_invalid_locale')}!"); fType.resolve(buffer, fContext); diff --git a/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/TemplateTranslatorTest.java b/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/TemplateTranslatorTest.java index 494e3f1c26a..5384a9403b9 100644 --- a/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/TemplateTranslatorTest.java +++ b/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/TemplateTranslatorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2015 IBM Corporation and others. + * Copyright (c) 2006, 2016 IBM Corporation 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 @@ -7,47 +7,50 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Lars Vogel <Lars.Vogel@vogella.com> - Bug 486889 *******************************************************************************/ package org.eclipse.text.tests.templates; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.junit.Before; +import org.junit.Test; + import org.eclipse.jface.text.templates.TemplateBuffer; import org.eclipse.jface.text.templates.TemplateException; import org.eclipse.jface.text.templates.TemplateTranslator; import org.eclipse.jface.text.templates.TemplateVariable; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - /** * @since 3.3 */ -public class TemplateTranslatorTest extends TestCase { - public static Test suite() { - return new TestSuite(TemplateTranslatorTest.class); - } +public class TemplateTranslatorTest { private TemplateTranslator fTranslator; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { fTranslator= new TemplateTranslator(); } + @Test public void testNullTemplate() throws Exception { try { fTranslator.translate((String) null); fail(); } catch (NullPointerException x) { + // expected } } + @Test public void testEmptyTemplate() throws Exception { TemplateBuffer buffer= fTranslator.translate(""); assertNull(fTranslator.getErrorMessage()); @@ -64,6 +67,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals("foo bar", buffer.getString()); } + @Test public void testSimpleTemplate() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${var} bar"); assertNull(fTranslator.getErrorMessage()); @@ -81,6 +85,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals("var", vars[0].getType()); } + @Test public void testMultiTemplate() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${var} bar ${var} end"); assertNull(fTranslator.getErrorMessage()); @@ -99,13 +104,14 @@ public class TemplateTranslatorTest extends TestCase { assertEquals("var", vars[0].getType()); } + @Test public void testNonAsciiVarTemplate() throws Exception { TemplateBuffer buffer= fTranslator.translate("System.out.println(${bl\u00F6d:var} + \" with element type \" + ${h\u00E4:elemType(bl\u00F6d)});"); assertNull(fTranslator.getErrorMessage()); assertEquals("System.out.println(bl\u00F6d + \" with element type \" + h\u00E4);", buffer.getString()); TemplateVariable[] vars= buffer.getVariables(); assertEquals(2, vars.length); - + assertEquals("bl\u00F6d", vars[0].getName()); assertEquals(1, vars[0].getOffsets().length); assertEquals(19, vars[0].getOffsets()[0]); @@ -115,7 +121,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals(1, vars[0].getValues().length); assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]); assertEquals("var", vars[0].getType()); - + assertEquals("h\u00E4", vars[1].getName()); assertEquals(1, vars[1].getOffsets().length); assertEquals(50, vars[1].getOffsets()[0]); @@ -126,7 +132,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals(vars[1].getDefaultValue(), vars[1].getValues()[0]); assertEquals("elemType", vars[1].getType()); } - + @Test public void testNumberAsIdentifier() throws Exception { TemplateBuffer buffer= fTranslator.translate("${0:link(1,'2 ',3)}\\n${0}"); assertNull(fTranslator.getErrorMessage()); @@ -142,11 +148,12 @@ public class TemplateTranslatorTest extends TestCase { assertEquals("0", vars[0].getDefaultValue()); assertEquals(1, vars[0].getValues().length); assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]); - + assertEquals("link", vars[0].getType()); assertEquals(Arrays.asList(new Object[] { "1", "2 ", "3" }), vars[0].getVariableType().getParams()); } - + + @Test public void testIllegalSyntax1() throws Exception { ensureFailure("foo ${var"); } @@ -156,17 +163,21 @@ public class TemplateTranslatorTest extends TestCase { fTranslator.translate(template); fail(); } catch (TemplateException e) { + // expected } } + @Test public void testIllegalSyntax2() throws Exception { ensureFailure("foo $"); } + @Test public void testIllegalSyntax3() throws Exception { ensureFailure("foo ${] } bar"); } + @Test public void testDollar() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo $$ bar"); assertNull(fTranslator.getErrorMessage()); @@ -175,6 +186,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals("foo $ bar", buffer.getString()); } + @Test public void testEmptyVariable() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${} bar"); assertNull(fTranslator.getErrorMessage()); @@ -193,7 +205,7 @@ public class TemplateTranslatorTest extends TestCase { } /* 3.3 typed template variables */ - + @Test public void testTypedTemplate() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${var:type} bar"); assertNull(fTranslator.getErrorMessage()); @@ -210,7 +222,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals("type", vars[0].getType()); assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]); } - + @Test public void testParameterizedTypeTemplate() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${var:type(param)} bar"); assertNull(fTranslator.getErrorMessage()); @@ -229,6 +241,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals(Collections.singletonList("param"), vars[0].getVariableType().getParams()); } + @Test public void testMultiParameterizedTypeTemplate1() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${var:type(param)} bar ${var:type(param)} end"); assertNull(fTranslator.getErrorMessage()); @@ -248,6 +261,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals(Collections.singletonList("param"), vars[0].getVariableType().getParams()); } + @Test public void testMultiParameterizedTypeTemplate2() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${var:type(param)} bar ${var} end"); assertNull(fTranslator.getErrorMessage()); @@ -267,11 +281,13 @@ public class TemplateTranslatorTest extends TestCase { assertEquals(Collections.singletonList("param"), vars[0].getVariableType().getParams()); } + @Test public void testIllegallyParameterizedTypeTemplate() throws Exception { ensureFailure("foo ${var:type(param)} bar ${var:type(other)} end"); ensureFailure("foo ${var:type(param)} bar ${var:type} end"); } + @Test public void testParameterizedTypeTemplateWithWhitespace() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${ var : type ( param1 , param2 , param3 ) } bar"); assertNull(fTranslator.getErrorMessage()); @@ -294,6 +310,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals(params, vars[0].getVariableType().getParams()); } + @Test public void testQualifiedTypeTemplate() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${ var : qual.type ( qual.param1, qual.param2 ) } bar"); assertNull(fTranslator.getErrorMessage()); @@ -315,6 +332,7 @@ public class TemplateTranslatorTest extends TestCase { assertEquals(params, vars[0].getVariableType().getParams()); } + @Test public void testTextParameterTemplate() throws Exception { TemplateBuffer buffer= fTranslator.translate("foo ${ var : qual.type ( 'a parameter 1', qual.param2, 'a parameter ''3' ) } bar"); assertNull(fTranslator.getErrorMessage()); @@ -337,18 +355,22 @@ public class TemplateTranslatorTest extends TestCase { assertEquals(params, vars[0].getVariableType().getParams()); } + @Test public void testIllegalSyntax4() throws Exception { ensureFailure("foo ${var:} bar"); } + @Test public void testIllegalSyntax5() throws Exception { ensureFailure("foo ${var:type(} bar"); } + @Test public void testIllegalSyntax6() throws Exception { ensureFailure("foo ${var:type(] )} bar"); } + @Test public void testIllegalSyntax7() throws Exception { ensureFailure("foo ${var:type((} bar"); } diff --git a/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/TemplatesTestSuite.java b/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/TemplatesTestSuite.java index df495d5a4a1..5160075d68b 100755 --- a/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/TemplatesTestSuite.java +++ b/org.eclipse.text.tests/src/org/eclipse/text/tests/templates/TemplatesTestSuite.java @@ -8,28 +8,23 @@ * Contributors: * IBM Corporation - initial API and implementation * Jeremie Bresson <jbr@bsiag.com> - Allow to specify format for date variable - https://bugs.eclipse.org/75981 + * Lars Vogel <Lars.Vogel@vogella.com> - Bug 486889 *******************************************************************************/ package org.eclipse.text.tests.templates; -import junit.framework.Test; -import junit.framework.TestSuite; - +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; /** - * Test Suite for org.eclipse.text. + * Test Suite for the org.eclipse.text plug-in * - * @since 3.3 */ +@RunWith(Suite.class) +@SuiteClasses({ + TemplateTranslatorTest.class, + GlobalTemplateVariablesDateTest.class}) public class TemplatesTestSuite { - - public static Test suite() { - TestSuite suite = new TestSuite("Test Suite for org.eclipse.jface.text.templates"); //$NON-NLS-1$ - //$JUnit-BEGIN$ - suite.addTest(TemplateTranslatorTest.suite()); - suite.addTest(GlobalTemplateVariablesDateTest.suite()); - //$JUnit-END$ - - return suite; - } + // intentionally empty } |