Adds explicit pure Java test support to GWTTestCase, via a setter.
Calling setForcePureJava(true) on a GWTTestCase forces running the test in pure Java mode (non-GWT). This feature has the same effect than returning null in getModuleName(), with the major difference that it can be called by test suite builders (which cannot reliably subclass tests in a generic way).
Fixes bug: gwtSetUp and gwtTearDown should be called in pure Java mode.
Also hardens existi
... description truncated by rollback ...
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7526 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/junit/client/GWTTestCase.java b/user/src/com/google/gwt/junit/client/GWTTestCase.java
index b87324c..3b4b973 100644
--- a/user/src/com/google/gwt/junit/client/GWTTestCase.java
+++ b/user/src/com/google/gwt/junit/client/GWTTestCase.java
@@ -164,15 +164,6 @@
protected TestResult testResult = null;
/**
- * Whether this test case should be always run in pure Java mode (non-GWT).
- * Setting this to <code>true</code> has the same effect as returning
- * <code>null</code> in {@link #getModuleName}.
- *
- * @see #isPureJava
- */
- private boolean forcePureJava;
-
- /**
* The {@link Strategy} used by this test.
*/
private Strategy strategy;
@@ -255,10 +246,7 @@
* be included.
*
* @return the fully qualified name of a module, or <code>null</code> to run
- * as a pure Java (non-GWT) test case (same effect as passing
- * <code>true</code> to {@link #setForcePureJava})
- *
- * @see #isPureJava
+ * as a non-GWT test case
*/
public abstract String getModuleName();
@@ -278,27 +266,14 @@
* Get the synthetic module name, which includes the synthetic extension
* defined by the {@link Strategy}.
*
- * @return the synthetic module name, or <code>null</code> if this test case
- * is run in pure Java mode (non-GWT)
- *
- * @see #isPureJava
+ * @return the synthetic module name or null if this is not really a GWT test
*/
public final String getSyntheticModuleName() {
- if (isPureJava()) {
+ String moduleName = getModuleName();
+ if (moduleName == null) {
return null;
- } else {
- return getModuleName() + "." + getStrategy().getSyntheticModuleExtension();
}
- }
-
- /**
- * Returns whether this test case should be run in pure Java mode (non-GWT).
- * Returns <code>true</code> if and only if {@link #getModuleName} returns
- * <code>null</code>, or {@link #setForcePureJava} was last invoked with
- * <code>true</code>.
- */
- public boolean isPureJava() {
- return forcePureJava || (getModuleName() == null);
+ return moduleName + "." + getStrategy().getSyntheticModuleExtension();
}
/**
@@ -311,22 +286,6 @@
super.run(result);
}
- /**
- * Specifies whether this test case should be always run in pure Java mode
- * (non-GWT). Passing <code>true</code> has the same effect as returning
- * <code>null</code> in {@link #getModuleName}. The setting is
- * <code>false</code> by default.
- *
- * @param forcePureJava <code>true</code> to always run this test case in pure
- * Java mode (non-GWT); <code>false</code> to run this test case in GWT
- * mode if {@link #getModuleName} does not return <code>null</code>
- *
- * @see #isPureJava
- */
- public void setForcePureJava(boolean forcePureJava) {
- this.forcePureJava = forcePureJava;
- }
-
@Override
public void setName(String name) {
super.setName(name);
@@ -419,9 +378,7 @@
* A replacement for JUnit's {@link #setUp()} method. This method runs once
* per test method in your subclass, just before your each test method runs
* and can be used to perform initialization. Override this method instead of
- * {@link #setUp()}. This method is run even in pure Java mode (non-GWT).
- *
- * @see #setForcePureJava
+ * {@link #setUp()}.
*/
protected void gwtSetUp() throws Exception {
}
@@ -430,9 +387,7 @@
* A replacement for JUnit's {@link #tearDown()} method. This method runs once
* per test method in your subclass, just after your each test method runs and
* can be used to perform cleanup. Override this method instead of
- * {@link #tearDown()}. This method is run even in pure Java mode (non-GWT).
- *
- * @see #setForcePureJava
+ * {@link #tearDown()}.
*/
protected void gwtTearDown() throws Exception {
}
@@ -450,10 +405,12 @@
+ "\" has none. Perhaps you used TestSuite.addTest() instead of addTestClass()?");
}
- if (isPureJava()) {
- super.runTest();
- } else {
+ String moduleName = getModuleName();
+ if (moduleName != null) {
JUnitShell.runTest(this, testResult);
+ } else {
+ // Run as a non-GWT test
+ super.runTest();
}
}
@@ -464,9 +421,7 @@
*/
@Override
protected final void setUp() throws Exception {
- if (isPureJava()) {
- gwtSetUp();
- }
+ // implemented in the translatable version of this class
}
/**
@@ -484,8 +439,6 @@
*/
@Override
protected final void tearDown() throws Exception {
- if (isPureJava()) {
- gwtTearDown();
- }
+ // implemented in the translatable version of this class
}
}
diff --git a/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/GWTTestCase.java b/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/GWTTestCase.java
index daba14a..7f166f0 100644
--- a/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/GWTTestCase.java
+++ b/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/GWTTestCase.java
@@ -199,10 +199,6 @@
}
public abstract String getModuleName();
-
- public boolean isPureJava() {
- return false;
- }
@Override
public void runBare() throws Throwable {
@@ -211,11 +207,6 @@
// No tearDown call here; we do it from reportResults.
}
- public void setForcePureJava(boolean forcePureJava) {
- // Ignore completely. The test is being run in GWT mode,
- // hence assumed not to be pure Java.
- }
-
// CHECKSTYLE_OFF
protected JUnitResult __getOrCreateTestResult() {
if (result == null) {
diff --git a/user/test/com/google/gwt/junit/NonGwtTestSuite.java b/user/test/com/google/gwt/junit/NonGwtTestSuite.java
index fcd68ef..f1f4833 100644
--- a/user/test/com/google/gwt/junit/NonGwtTestSuite.java
+++ b/user/test/com/google/gwt/junit/NonGwtTestSuite.java
@@ -15,18 +15,15 @@
*/
package com.google.gwt.junit;
-import com.google.gwt.junit.client.ForcePureJavaTest;
import com.google.gwt.junit.client.ModuleOneTest;
import com.google.gwt.junit.client.ModuleOneTest2;
import com.google.gwt.junit.client.ModuleTwoTest;
-import com.google.gwt.junit.client.NullModuleNameTest;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Tests that a normal test suite will run even if modules are out of order.
- * Also checks that tests are run in pure Java mode (non-GWT).
*/
public class NonGwtTestSuite {
@@ -34,11 +31,9 @@
// This is intentionally not a GWTTestSuite.
TestSuite suite = new TestSuite();
- suite.addTestSuite(ForcePureJavaTest.class);
suite.addTestSuite(ModuleOneTest.class);
suite.addTestSuite(ModuleTwoTest.class);
suite.addTestSuite(ModuleOneTest2.class);
- suite.addTestSuite(NullModuleNameTest.class);
return suite;
}
diff --git a/user/test/com/google/gwt/junit/client/ForcePureJavaTest.java b/user/test/com/google/gwt/junit/client/ForcePureJavaTest.java
deleted file mode 100644
index 088729a..0000000
--- a/user/test/com/google/gwt/junit/client/ForcePureJavaTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.junit.client;
-
-import com.google.gwt.core.client.GWT;
-
-/**
- * Test case running in pure Java mode (non-GWT) due to a call to
- * {@link GWTTestCase#setForcePureJava}.
- */
-public class ForcePureJavaTest extends GWTTestCase {
-
- private int gwtSetUpCalls;
-
- public ForcePureJavaTest() {
- setForcePureJava(true);
- }
-
- @Override
- public String getModuleName() {
- return "invalid.module";
- }
-
- @Override
- protected void gwtSetUp() throws Exception {
- gwtSetUpCalls++;
- super.gwtSetUp();
- }
-
- public void testGwtSetUpCalled() {
- assertEquals(1, gwtSetUpCalls);
- }
-
- public void testIsNotClient() {
- assertFalse(GWT.isClient());
- }
-
- public void testSetForcePureJava_inTestMethod() {
- setForcePureJava(false);
- }
-
- public void testIsNotClient_afterChangeForcePureJavaInTest() {
- assertFalse(GWT.isClient());
- }
-}
diff --git a/user/test/com/google/gwt/junit/client/ModuleOneTest.java b/user/test/com/google/gwt/junit/client/ModuleOneTest.java
index c4cf78b..1d1c5a7 100644
--- a/user/test/com/google/gwt/junit/client/ModuleOneTest.java
+++ b/user/test/com/google/gwt/junit/client/ModuleOneTest.java
@@ -15,8 +15,6 @@
*/
package com.google.gwt.junit.client;
-import com.google.gwt.core.client.GWT;
-
/**
* A test in the first module.
*/
@@ -26,7 +24,7 @@
return "com.google.gwt.junit.JUnitTest";
}
- public void testIsClient() {
- assertTrue(GWT.isClient());
+ public void testTrue() {
+ assertTrue(true);
}
}
diff --git a/user/test/com/google/gwt/junit/client/ModuleOneTest2.java b/user/test/com/google/gwt/junit/client/ModuleOneTest2.java
index c26e53c..f0fc271 100644
--- a/user/test/com/google/gwt/junit/client/ModuleOneTest2.java
+++ b/user/test/com/google/gwt/junit/client/ModuleOneTest2.java
@@ -15,8 +15,6 @@
*/
package com.google.gwt.junit.client;
-import com.google.gwt.core.client.GWT;
-
/**
* Another test in the first module.
*/
@@ -26,7 +24,7 @@
return "com.google.gwt.junit.JUnitTest";
}
- public void testIsClient() {
- assertTrue(GWT.isClient());
+ public void testTrue() {
+ assertTrue(true);
}
}
diff --git a/user/test/com/google/gwt/junit/client/ModuleTwoTest.java b/user/test/com/google/gwt/junit/client/ModuleTwoTest.java
index 3840f7a..0d983dc 100644
--- a/user/test/com/google/gwt/junit/client/ModuleTwoTest.java
+++ b/user/test/com/google/gwt/junit/client/ModuleTwoTest.java
@@ -15,8 +15,6 @@
*/
package com.google.gwt.junit.client;
-import com.google.gwt.core.client.GWT;
-
/**
* A test in the second module.
*/
@@ -26,7 +24,7 @@
return "com.google.gwt.junit.JUnitTest2";
}
- public void testIsClient() {
- assertTrue(GWT.isClient());
+ public void testTrue() {
+ assertTrue(true);
}
}
diff --git a/user/test/com/google/gwt/junit/client/NullModuleNameTest.java b/user/test/com/google/gwt/junit/client/NullModuleNameTest.java
deleted file mode 100644
index 8f39f1b..0000000
--- a/user/test/com/google/gwt/junit/client/NullModuleNameTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.junit.client;
-
-import com.google.gwt.core.client.GWT;
-
-/**
- * Test case running in pure Java mode (non-GWT) due to {@link #getModuleName}
- * returning <code>null</code>.
- */
-public class NullModuleNameTest extends GWTTestCase {
-
- private int gwtSetUpCalls;
-
- @Override
- public String getModuleName() {
- return null;
- }
-
- @Override
- protected void gwtSetUp() throws Exception {
- gwtSetUpCalls++;
- super.gwtSetUp();
- }
-
- public void testGwtSetUpCalled() {
- assertEquals(1, gwtSetUpCalls);
- }
-
- public void testIsNotClient() {
- assertFalse(GWT.isClient());
- }
-}