From 54991f219b649e9228e313b23df1588c3e38ffc8 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Tue, 4 Dec 2012 21:32:04 +0100 Subject: [PATCH] Add client-side tests for StringUtils and Utils. * src/test/java/org/glom/web/client/GwtTestStringUtils.java: Added. * src/test/java/org/glom/web/client/GwtTestUtils.java: Added. This is mostly just to catch java->javascript compilation problems. --- ChangeLog | 8 ++++ .../org/glom/web/client/GwtTestStringUtils.java | 52 ++++++++++++++++++++++ .../java/org/glom/web/client/GwtTestUtils.java | 41 +++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 src/test/java/org/glom/web/client/GwtTestStringUtils.java create mode 100644 src/test/java/org/glom/web/client/GwtTestUtils.java diff --git a/ChangeLog b/ChangeLog index 04b730b..4cf4c13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-12-04 Murray Cumming + + Add client-side tests for StringUtils and Utils. + + * src/test/java/org/glom/web/client/GwtTestStringUtils.java: Added. + * src/test/java/org/glom/web/client/GwtTestUtils.java: Added. + This is mostly just to catch java->javascript compilation problems. + 2012-12-02 Murray Cumming Add GwtTestReportPlace. diff --git a/src/test/java/org/glom/web/client/GwtTestStringUtils.java b/src/test/java/org/glom/web/client/GwtTestStringUtils.java new file mode 100644 index 0000000..66f120f --- /dev/null +++ b/src/test/java/org/glom/web/client/GwtTestStringUtils.java @@ -0,0 +1,52 @@ +package org.glom.web.client; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.googlecode.gwt.test.GwtModule; +import com.googlecode.gwt.test.GwtTest; + +@GwtModule("org.glom.web.OnlineGlom") +public class GwtTestStringUtils extends GwtTest { + + public GwtTestStringUtils() { + } + + @Test + public void testIsEmpty() { + assertTrue(StringUtils.isEmpty("")); + assertTrue(StringUtils.isEmpty(null)); + assertTrue(StringUtils.isEmpty(new String())); + assertFalse(StringUtils.isEmpty("something")); + } + + @Test + public void testDefaultString() { + assertEquals("", StringUtils.defaultString("")); + assertEquals("", StringUtils.defaultString(null)); + + assertEquals("something", StringUtils.defaultString("something")); + } + + @Test + public void testEquals() { + assertTrue(StringUtils.equals(null, null)); + assertTrue(StringUtils.equals("", "")); + assertTrue(StringUtils.equals(new String(), new String())); + assertTrue(StringUtils.equals(null, "")); + assertTrue(StringUtils.equals("", null)); + assertTrue(StringUtils.equals(null, new String())); + assertTrue(StringUtils.equals(new String(), null)); + assertTrue(StringUtils.equals(null, new String())); + assertTrue(StringUtils.equals(new String(), null)); + + assertFalse(StringUtils.equals("something", null)); + assertFalse(StringUtils.equals("something", "")); + assertFalse(StringUtils.equals("something", new String())); + assertFalse(StringUtils.equals(null, "something")); + assertFalse(StringUtils.equals("", "something")); + assertFalse(StringUtils.equals(new String(), "something")); + } + +} diff --git a/src/test/java/org/glom/web/client/GwtTestUtils.java b/src/test/java/org/glom/web/client/GwtTestUtils.java new file mode 100644 index 0000000..f4c7f20 --- /dev/null +++ b/src/test/java/org/glom/web/client/GwtTestUtils.java @@ -0,0 +1,41 @@ +package org.glom.web.client; + +import static org.junit.Assert.*; + +import org.glom.web.shared.libglom.NumericFormat; +import org.junit.Test; + +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.Widget; +import com.googlecode.gwt.test.GwtModule; +import com.googlecode.gwt.test.GwtTest; + +@GwtModule("org.glom.web.OnlineGlom") +public class GwtTestUtils extends GwtTest { + + public GwtTestUtils() { + } + + @Test + public void testGetCurrentLocaleID() { + assertNotNull(Utils.getCurrentLocaleID()); + } + + @Test + public void testGetNumberFormat() { + final NumericFormat numericFormat = new NumericFormat(); + final NumberFormat format = Utils.getNumberFormat(numericFormat); + assertNotNull(format); + assertNotNull(format.getPattern()); + assertFalse(StringUtils.isEmpty(format.getPattern())); + } + + @Test + public void testGetWidgetHeight() { + final Widget widget = new Button(); + final int height = Utils.getWidgetHeight(widget); + assertTrue(height > 0); + } + +} -- 2.1.4