Revision: 7526
Author: [email protected]
Date: Wed Feb 3 10:33:14 2010
Log: 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 ...
http://code.google.com/p/google-web-toolkit/source/detail?r=7526
Deleted:
/trunk/user/test/com/google/gwt/junit/client/ForcePureJavaTest.java
/trunk/user/test/com/google/gwt/junit/client/NullModuleNameTest.java
Modified:
/trunk/user/src/com/google/gwt/junit/client/GWTTestCase.java
/trunk/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/GWTTestCase.java
/trunk/user/test/com/google/gwt/junit/NonGwtTestSuite.java
/trunk/user/test/com/google/gwt/junit/client/ModuleOneTest.java
/trunk/user/test/com/google/gwt/junit/client/ModuleOneTest2.java
/trunk/user/test/com/google/gwt/junit/client/ModuleTwoTest.java
=======================================
--- /trunk/user/test/com/google/gwt/junit/client/ForcePureJavaTest.java Tue
Feb 2 13:27:34 2010
+++ /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());
- }
-}
=======================================
--- /trunk/user/test/com/google/gwt/junit/client/NullModuleNameTest.java
Tue Feb 2 13:27:34 2010
+++ /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());
- }
-}
=======================================
--- /trunk/user/src/com/google/gwt/junit/client/GWTTestCase.java Tue Feb 2
13:27:34 2010
+++ /trunk/user/src/com/google/gwt/junit/client/GWTTestCase.java Wed Feb 3
10:33:14 2010
@@ -163,15 +163,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.
*/
@@ -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();
}
/**
@@ -310,22 +285,6 @@
testResult = result;
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) {
@@ -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
}
}
=======================================
---
/trunk/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/GWTTestCase.java
Tue Feb 2 13:27:34 2010
+++
/trunk/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/GWTTestCase.java
Wed Feb 3 10:33:14 2010
@@ -199,10 +199,6 @@
}
public abstract String getModuleName();
-
- public boolean isPureJava() {
- return false;
- }
@Override
public void runBare() throws Throwable {
@@ -210,11 +206,6 @@
runTest();
// 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() {
=======================================
--- /trunk/user/test/com/google/gwt/junit/NonGwtTestSuite.java Tue Feb 2
13:27:34 2010
+++ /trunk/user/test/com/google/gwt/junit/NonGwtTestSuite.java Wed Feb 3
10:33:14 2010
@@ -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;
}
=======================================
--- /trunk/user/test/com/google/gwt/junit/client/ModuleOneTest.java Tue
Feb 2 13:27:34 2010
+++ /trunk/user/test/com/google/gwt/junit/client/ModuleOneTest.java Wed
Feb 3 10:33:14 2010
@@ -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);
}
}
=======================================
--- /trunk/user/test/com/google/gwt/junit/client/ModuleOneTest2.java Tue
Feb 2 13:27:34 2010
+++ /trunk/user/test/com/google/gwt/junit/client/ModuleOneTest2.java Wed
Feb 3 10:33:14 2010
@@ -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);
}
}
=======================================
--- /trunk/user/test/com/google/gwt/junit/client/ModuleTwoTest.java Tue
Feb 2 13:27:34 2010
+++ /trunk/user/test/com/google/gwt/junit/client/ModuleTwoTest.java Wed
Feb 3 10:33:14 2010
@@ -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);
}
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors