summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-04-27 10:32:35 (EDT)
committer pelder2006-04-27 10:32:35 (EDT)
commiteb44df5611ecf4484f9813ea4bc8cc97d35389b3 (patch)
tree7185e6828f5f1c3fc7b607af60c7e7a8c3334500
parent3fd74192591bd6428af42636b5822469d00b69ce (diff)
downloadorg.eclipse.jet-eb44df5611ecf4484f9813ea4bc8cc97d35389b3.zip
org.eclipse.jet-eb44df5611ecf4484f9813ea4bc8cc97d35389b3.tar.gz
org.eclipse.jet-eb44df5611ecf4484f9813ea4bc8cc97d35389b3.tar.bz2
[138923] Improved format tag JUnits.
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/AllTests.java3
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/FormatNowTagTests.java10
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/LowerCaseTagTests.java209
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/UpperCaseTagTests.java209
4 files changed, 426 insertions, 5 deletions
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/AllTests.java
index 96f4996..055c1af 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/AllTests.java
@@ -10,6 +10,9 @@ public class AllTests {
"Test for org.eclipse.jet.tests.taglib.format");
//$JUnit-BEGIN$
suite.addTestSuite(UuidTagTests.class);
+ suite.addTestSuite(LowerCaseTagTests.class);
+ suite.addTestSuite(FormatNowTagTests.class);
+ suite.addTestSuite(UpperCaseTagTests.class);
suite.addTestSuite(FormatContextExtenderTests.class);
//$JUnit-END$
return suite;
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/FormatNowTagTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/FormatNowTagTests.java
index 71676a4..fb58193 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/FormatNowTagTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/FormatNowTagTests.java
@@ -28,7 +28,7 @@ public class FormatNowTagTests extends TestCase {
tag.setParent(null);
tagInfo = new TagInfo("f:formatNow", 1, 1,
new String[] {
- "format"
+ "pattern"
},
new String[] {
"yyyy.MM.dd.HH.mm"
@@ -51,10 +51,10 @@ public class FormatNowTagTests extends TestCase {
final String[] parts = formatted.split("\\.");
assertNotNull(parts);
assertEquals(5, parts.length);
- assertEquals(String.valueOf(now.get(Calendar.YEAR)), parts[0]);
- assertEquals(String.valueOf(now.get(Calendar.MONTH)), parts[1]);
- assertEquals(String.valueOf(now.get(Calendar.DAY_OF_MONTH)), parts[2]);
- assertEquals(String.valueOf(now.get(Calendar.HOUR_OF_DAY)), parts[3]);
+ assertEquals(now.get(Calendar.YEAR), Integer.parseInt(parts[0]));
+ assertEquals(now.get(Calendar.MONTH) + 1, Integer.parseInt(parts[1]));
+ assertEquals(now.get(Calendar.DAY_OF_MONTH), Integer.parseInt(parts[2]));
+ assertEquals(now.get(Calendar.HOUR_OF_DAY), Integer.parseInt(parts[3]));
}
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/LowerCaseTagTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/LowerCaseTagTests.java
new file mode 100644
index 0000000..24226fc
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/LowerCaseTagTests.java
@@ -0,0 +1,209 @@
+package org.eclipse.jet.tests.taglib.format;
+
+import java.text.MessageFormat;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jet.BodyContentWriter;
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.taglib.format.LowerCaseTag;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagInfo;
+
+public class LowerCaseTagTests extends TestCase {
+
+ private BodyContentWriter out;
+ private LowerCaseTag lowerCaseTag;
+ private JET2Context context;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ out = new BodyContentWriter();
+ lowerCaseTag = new LowerCaseTag();
+ lowerCaseTag.setParent(null);
+ lowerCaseTag.setOut(out);
+ context = new JET2Context(null);
+ lowerCaseTag.setContext(context);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_noAttrs() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {}, new String[] {});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("test", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"offset"}, new String[] {"1"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("Test", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_tooBigOffset() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"offset"}, new String[] {"5"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("TEST", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_negativeOffset() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"offset"}, new String[] {"-1"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+
+ try {
+ lowerCaseTag.doFunction(tagInfo, context, "TEST");
+ fail("Excepted JET2TagException");
+ } catch (JET2TagException e) {
+ String expected = MessageFormat.format(JET2Messages.AnyTag_AttributeMustBeInteger, new Object[] {"offset"});
+ assertEquals(expected, e.getMessage());
+ }
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_negativeLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"length"}, new String[] {"-1"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+
+ try {
+ lowerCaseTag.doFunction(tagInfo, context, "TEST");
+ fail("Excepted JET2TagException");
+ } catch (JET2TagException e) {
+ String expected = MessageFormat.format(JET2Messages.AnyTag_AttributeMustBeInteger, new Object[] {"length"});
+ assertEquals(expected, e.getMessage());
+ }
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_zeroOffset() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"offset"}, new String[] {"0"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("test", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"length"}, new String[] {"2"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("teST", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_tooBigLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"length"}, new String[] {"5"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("test", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_zeroLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"length"}, new String[] {"0"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("TEST", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset_validLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"offset", "length"}, new String[] {"1", "2"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("TesT", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset_validLength_rearBoundary() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"offset", "length"}, new String[] {"3", "1"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("TESt", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset_validLength_frontBoundary() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"offset", "length"}, new String[] {"0", "1"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("tEST", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset_tooBigLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"offset", "length"}, new String[] {"1", "4"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("Test", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_tooBigOffset_tooBigLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:lc", 1, 1, new String[] {"offset", "length"}, new String[] {"4", "4"});
+ lowerCaseTag.setTagInfo(tagInfo);
+
+ final String result = lowerCaseTag.doFunction(tagInfo, context, "TEST");
+
+ assertEquals("TEST", result);
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/UpperCaseTagTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/UpperCaseTagTests.java
new file mode 100644
index 0000000..f34c34c
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/format/UpperCaseTagTests.java
@@ -0,0 +1,209 @@
+package org.eclipse.jet.tests.taglib.format;
+
+import java.text.MessageFormat;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jet.BodyContentWriter;
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.taglib.format.UpperCaseTag;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagInfo;
+
+public class UpperCaseTagTests extends TestCase {
+
+ private BodyContentWriter out;
+ private UpperCaseTag upperCaseTag;
+ private JET2Context context;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ out = new BodyContentWriter();
+ upperCaseTag = new UpperCaseTag();
+ upperCaseTag.setParent(null);
+ upperCaseTag.setOut(out);
+ context = new JET2Context(null);
+ upperCaseTag.setContext(context);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_noAttrs() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {}, new String[] {});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("DATA", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"offset"}, new String[] {"1"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("dATA", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_tooBigOffset() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"offset"}, new String[] {"5"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("data", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_negativeOffset() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"offset"}, new String[] {"-1"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+
+ try {
+ upperCaseTag.doFunction(tagInfo, context, "data");
+ fail("Excepted JET2TagException");
+ } catch (JET2TagException e) {
+ String expected = MessageFormat.format(JET2Messages.AnyTag_AttributeMustBeInteger, new Object[] {"offset"});
+ assertEquals(expected, e.getMessage());
+ }
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_negativeLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"length"}, new String[] {"-1"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+
+ try {
+ upperCaseTag.doFunction(tagInfo, context, "data");
+ fail("Excepted JET2TagException");
+ } catch (JET2TagException e) {
+ String expected = MessageFormat.format(JET2Messages.AnyTag_AttributeMustBeInteger, new Object[] {"length"});
+ assertEquals(expected, e.getMessage());
+ }
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_zeroOffset() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"offset"}, new String[] {"0"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("DATA", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"length"}, new String[] {"2"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("DAta", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_tooBigLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"length"}, new String[] {"5"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("DATA", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_zeroLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"length"}, new String[] {"0"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("data", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset_validLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"offset", "length"}, new String[] {"1", "2"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("dATa", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset_validLength_rearBoundary() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"offset", "length"}, new String[] {"3", "1"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("datA", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset_validLength_frontBoundary() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"offset", "length"}, new String[] {"0", "1"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("Data", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_validOffset_tooBigLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"offset", "length"}, new String[] {"1", "4"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("dATA", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.format.LowerCaseTag.doFunction(TagInfo, JET2Context, String)'
+ */
+ public void testDoFunction_tooBigOffset_tooBigLength() throws JET2TagException {
+ final TagInfo tagInfo = new TagInfo("f:uc", 1, 1, new String[] {"offset", "length"}, new String[] {"4", "4"});
+ upperCaseTag.setTagInfo(tagInfo);
+
+ final String result = upperCaseTag.doFunction(tagInfo, context, "data");
+
+ assertEquals("data", result);
+ }
+
+}