Revision: 6943
Author: [email protected]
Date: Mon Nov 16 18:58:08 2009
Log: Sort & format some junit files.

Review by: jlabanca (desk)
http://code.google.com/p/google-web-toolkit/source/detail?r=6943

Modified:
  /trunk/user/src/com/google/gwt/junit/CompileStrategy.java
  /trunk/user/src/com/google/gwt/junit/JUnitMessageQueue.java
  /trunk/user/src/com/google/gwt/junit/JUnitShell.java
  /trunk/user/src/com/google/gwt/junit/RunStyle.java
  /trunk/user/src/com/google/gwt/junit/RunStyleExternalBrowser.java
  /trunk/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java
  /trunk/user/src/com/google/gwt/junit/RunStyleManual.java
  /trunk/user/src/com/google/gwt/junit/RunStyleRemoteWeb.java
  /trunk/user/src/com/google/gwt/junit/RunStyleSelenium.java
  /trunk/user/test/com/google/gwt/junit/CompileStrategyTest.java

=======================================
--- /trunk/user/src/com/google/gwt/junit/CompileStrategy.java   Thu Oct 22  
08:20:50 2009
+++ /trunk/user/src/com/google/gwt/junit/CompileStrategy.java   Mon Nov 16  
18:58:08 2009
@@ -196,6 +196,12 @@
   */
  class ParallelCompileStrategy extends PreCompileStrategy {

+  /**
+   * The {...@link BatchingStrategy} used to compile, which is set on the  
first
+   * compilation and is the same across all compilations.
+   */
+  private BatchingStrategy batchingStrategy;
+
    /**
     * The list of all synthetic module names to be compiled.
     */
@@ -207,12 +213,6 @@
     */
    private RunStyle runStyle;

-  /**
-   * The {...@link BatchingStrategy} used to compile, which is set on the  
first
-   * compilation and is the same across all compilations.
-   */
-  private BatchingStrategy batchingStrategy;
-
    /**
     * The {...@link TreeLogger} used to compile, which is set on the first
     * compilation and is the same across all compilations.
=======================================
--- /trunk/user/src/com/google/gwt/junit/JUnitMessageQueue.java Fri Nov  6  
15:38:19 2009
+++ /trunk/user/src/com/google/gwt/junit/JUnitMessageQueue.java Mon Nov 16  
18:58:08 2009
@@ -48,9 +48,9 @@
     * Holds the state of an individual client.
     */
    public static class ClientStatus {
+    public int blockIndex = 0;
      public final String clientId;
      public boolean isNew = true;
-    public int blockIndex = 0;

      public ClientStatus(String clientId) {
        this.clientId = clientId;
@@ -70,22 +70,28 @@
     * Records results for each client; must lock before accessing.
     */
    private final Map<String, ClientStatus> clientStatuses = new  
HashMap<String, ClientStatus>();
-
-  /**
-   * A set of the GWT user agents (eg. ie6, gecko) that have connected.
-   */
-  private final Set<String> userAgents = new HashSet<String>();

    /**
     * The lock used to synchronize access to clientStatuses.
     */
    private final Object clientStatusesLock = new Object();

+  /**
+   * Set to true when the last test block has been added. This is used to  
tell
+   * clients that all tests are complete.
+   */
+  private boolean isLastTestBlockAvailable;
+
    /**
     * The number of TestCase clients executing in parallel.
     */
    private int numClients = 1;

+  /**
+   * The list of test blocks to run.
+   */
+  private final List<TestInfo[]> testBlocks = new ArrayList<TestInfo[]>();
+
    /**
     * Maps the TestInfo to the results from each clientId. If JUnitResult is
     * null, it means that the client requested the test but did not report  
the
@@ -94,22 +100,16 @@
    private final Map<TestInfo, Map<String, JUnitResult>> testResults = new  
HashMap<TestInfo, Map<String, JUnitResult>>();

    /**
-   * The list of test blocks to run.
+   * A set of the GWT user agents (eg. ie6, gecko) that have connected.
     */
-  private final List<TestInfo[]> testBlocks = new ArrayList<TestInfo[]>();
-
-  /**
-   * Set to true when the last test block has been added. This is used to  
tell
-   * clients that all tests are complete.
-   */
-  private boolean isLastTestBlockAvailable;
+  private final Set<String> userAgents = new HashSet<String>();

    /**
     * Only instantiable within this package.
     */
    JUnitMessageQueue() {
    }
-
+
    /**
     * Called by the servlet to query for for the next block to test.
     *
@@ -117,8 +117,8 @@
     * @param userAgent the user agent property of the client
     * @param blockIndex the index of the test block to get
     * @param timeout how long to wait for an answer
-   * @return the next test to run, or <code>null</code> if  
<code>timeout</code>
-   *         is exceeded or the next test does not match
+   * @return the next test to run, or <code>null</code> if
+   *         <code>timeout</code> is exceeded or the next test does not  
match
     *         <code>testClassName</code>
     */
    public TestBlock getTestBlock(String clientId, String userAgent,
@@ -457,7 +457,7 @@
    }

    /**
-   * Ensure that a {...@link ClientStatus} for the clientId exists.
+   * Ensure that a {...@link ClientStatus} for the clientId exists.
     *
     * @param clientId the id of the client
     * @return the {...@link ClientStatus} for the client
@@ -487,7 +487,8 @@
      return results;
    }

-  private boolean isMember(Throwable exception, Set<Class<? extends  
Throwable>> throwableSet) {
+  private boolean isMember(Throwable exception,
+      Set<Class<? extends Throwable>> throwableSet) {
      for (Class<? extends Throwable> throwable : throwableSet) {
        if (throwable.isInstance(exception)) {
          return true;
=======================================
--- /trunk/user/src/com/google/gwt/junit/JUnitShell.java        Wed Nov 11  
16:03:42 2009
+++ /trunk/user/src/com/google/gwt/junit/JUnitShell.java        Mon Nov 16  
18:58:08 2009
@@ -356,7 +356,7 @@
            return true;
          }
        });
-
+
        registerHandler(new ArgHandlerInt() {
          @Override
          public String getPurpose() {
@@ -372,12 +372,12 @@
          public String[] getTagArgs() {
            return new String[] {"1"};
          }
-
+
          @Override
          public boolean isRequired() {
            return false;
          }
-
+
          @Override
          public boolean isUndocumented() {
            return false;
@@ -614,29 +614,20 @@
      unitTestShell.checkArgs();
      return unitTestShell;
    }
-
-  /**
-   * Determines how to batch up tests for execution.
-   */
-  private BatchingStrategy batchingStrategy = new NoBatchingStrategy();

    /**
     * The amount of time to wait for all clients to complete a single test
-   * method, in milliseconds, measured from when the <i>last</i> client  
connects
-   * (and thus starts the test). Set by the -testMethodTimeout argument.
+   * method, in milliseconds, measured from when the <i>last</i> client
+   * connects (and thus starts the test). Set by the -testMethodTimeout
+   * argument.
     */
    private long baseTestMethodTimeoutMillis;

    /**
-   * Test method timeout as modified by the batching strategy.
+   * Determines how to batch up tests for execution.
     */
-  private long testBatchingMethodTimeoutMillis;
-
-  /**
-   * Max number of times a test method must be tried.
-   */
-  private int tries;
-
+  private BatchingStrategy batchingStrategy = new NoBatchingStrategy();
+
    /**
     * Determines how modules are compiled.
     */
@@ -644,14 +635,14 @@
        JUnitShell.this);

    /**
-   * Name of the module containing the current/last module to run.
+   * A type oracle for the current module, used to validate class  
existence.
     */
-  private ModuleDef currentModule;
+  private CompilationState currentCompilationState;

    /**
-   * A type oracle for the current module, used to validate class  
existence.
+   * Name of the module containing the current/last module to run.
     */
-  private CompilationState currentCompilationState;
+  private ModuleDef currentModule;

    /**
     * The name of the current test case being run.
@@ -712,8 +703,8 @@
    private RunStyle runStyle = null;

    /**
-   * The argument passed to -runStyle.  This is parsed later so we can  
pass in
-   * a logger.
+   * The argument passed to -runStyle. This is parsed later so we can pass  
in a
+   * logger.
     */
    private String runStyleName = "HtmlUnit";

@@ -721,6 +712,11 @@

    private boolean standardsMode = false;

+  /**
+   * Test method timeout as modified by the batching strategy.
+   */
+  private long testBatchingMethodTimeoutMillis;
+
    /**
     * The time the test actually began.
     */
@@ -740,6 +736,11 @@
     */
    private long testMethodTimeout;

+  /**
+   * Max number of times a test method must be tried.
+   */
+  private int tries;
+
    /**
     * Enforce the singleton pattern. The call to {...@link GWTShell}'s ctor  
forces
     * server mode and disables processing extra arguments as URLs to be  
shown.
@@ -778,14 +779,16 @@
        // RunStyle already logged reasons for its failure
        return false;
      }
-
+
      if (tries >= 1) {
        runStyle.setTries(tries);
      }
-
+
      if (!runStyle.setupMode(getTopLogger(), developmentMode)) {
-      getTopLogger().log(TreeLogger.ERROR, "Run style does not support "
-          + (developmentMode ? "development" : "production") + " mode");
+      getTopLogger().log(
+          TreeLogger.ERROR,
+          "Run style does not support "
+              + (developmentMode ? "development" : "production") + "  
mode");
        return false;
      }
      return true;
@@ -828,16 +831,19 @@
          }
          userAgentList += remoteUserAgents[i];
        }
-      getTopLogger().log(TreeLogger.INFO,
+      getTopLogger().log(
+          TreeLogger.INFO,
            "All clients connected (Limiting future permutations to: "
-          + userAgentList + ")");
+              + userAgentList + ")");
      }

      long currentTimeMillis = System.currentTimeMillis();
      if (activeClients >= numClients) {
        if (activeClients > numClients) {
-        getTopLogger().log(TreeLogger.WARN, "Too many clients: expected "
-            + numClients + ", found " + activeClients);
+        getTopLogger().log(
+            TreeLogger.WARN,
+            "Too many clients: expected " + numClients + ", found "
+                + activeClients);
        }
        firstLaunch = false;

@@ -927,7 +933,7 @@
    /**
     * Accessor method to HostedModeBase.setHeadless -- without this, we get
     * IllegalAccessError from the -notHeadless arg handler. Compiler bug?
-   *
+   *
     * @param headlessMode
     */
    void setHeadlessAccessor(boolean headlessMode) {
@@ -937,7 +943,8 @@
    /**
     * Set the expected number of clients.
     *
-   * <p>Should only be called by RunStyle subtypes.
+   * <p>
+   * Should only be called by RunStyle subtypes.
     *
     * @param numClients
     */
@@ -951,8 +958,10 @@
    }

    private void checkArgs() {
-    if (runStyle.getTries() > 1 && !(batchingStrategy instanceof  
NoBatchingStrategy)) {
-      throw new JUnitFatalLaunchException("Batching does not work with  
tries > 1");
+    if (runStyle.getTries() > 1
+        && !(batchingStrategy instanceof NoBatchingStrategy)) {
+      throw new JUnitFatalLaunchException(
+          "Batching does not work with tries > 1");
      }
    }

@@ -1073,8 +1082,8 @@
    /**
     * Runs a particular test case.
     */
-  private void runTestImpl(GWTTestCase testCase, TestResult testResult,  
int numTries)
-      throws UnableToCompleteException {
+  private void runTestImpl(GWTTestCase testCase, TestResult testResult,
+      int numTries) throws UnableToCompleteException {

      testBatchingMethodTimeoutMillis =  
batchingStrategy.getTimeoutMultiplier()
          * baseTestMethodTimeoutMillis;
=======================================
--- /trunk/user/src/com/google/gwt/junit/RunStyle.java  Wed Nov 11 15:50:48  
2009
+++ /trunk/user/src/com/google/gwt/junit/RunStyle.java  Mon Nov 16 18:58:08  
2009
@@ -26,16 +26,16 @@
   */
  abstract class RunStyle {

-  protected int tries = 1;
-
    /**
     * The containing shell.
     */
    protected final JUnitShell shell;

+  protected int tries = 1;
+
    /**
-   * Constructor for RunStyle.  Any subclass must provide a constructor  
with
-   * the same signature since this will be how the RunStyle is created via
+   * Constructor for RunStyle. Any subclass must provide a constructor  
with the
+   * same signature since this will be how the RunStyle is created via
     * reflection.
     *
     * @param shell the containing shell
@@ -57,7 +57,7 @@
     * Get the host name of the local system to use in URLs. This method  
returns
     * the host address instead of the host name in case the test target  
cannot
     * resolve the host name.
-   *
+   *
     * @return the host name of the local system
     */
    public String getLocalHostName() {
@@ -80,8 +80,8 @@
     * Initialize the runstyle with any supplied arguments.
     *
     * @param args arguments passed in -runStyle option, null if none  
supplied
-   * @return true if this runstyle is initialized successfully, false if it
-   *     was unsuccessful
+   * @return true if this runstyle is initialized successfully, false if  
it was
+   *         unsuccessful
     */
    public boolean initialize(String args) {
      return true;
@@ -102,22 +102,22 @@
    }

    /**
-   * Setup this RunStyle for the selected mode.
+   * Setup this RunStyle for the selected mode.
     *
-   * @param logger TreeLogger to use for any messages
-   * @param developmentMode true if we are running in development mode
-   *     rather that web/production mode
-   * @return false if we should abort processing due to an unsupported mode
-   *     or an error setting up for that mode
+   * @param logger TreeLogger to use for any messages
+   * @param developmentMode true if we are running in development mode  
rather
+   *          that web/production mode
+   * @return false if we should abort processing due to an unsupported  
mode or
+   *         an error setting up for that mode
     */
    public boolean setupMode(TreeLogger logger, boolean developmentMode) {
      return true;
    }

    /**
-   * Whether the embedded server should ever generate resources.  Hosted  
mode
-   * needs this, but not noserver hosted.  TODO(spoon) does web mode get
-   * simpler if this is turned on?
+   * Whether the embedded server should ever generate resources. Hosted  
mode
+   * needs this, but not noserver hosted. TODO(spoon) does web mode get  
simpler
+   * if this is turned on?
     */
    public boolean shouldAutoGenerateResources() {
      return true;
=======================================
--- /trunk/user/src/com/google/gwt/junit/RunStyleExternalBrowser.java   Thu  
Nov  5 11:44:07 2009
+++ /trunk/user/src/com/google/gwt/junit/RunStyleExternalBrowser.java   Mon  
Nov 16 18:58:08 2009
@@ -68,7 +68,7 @@
    }

    private ExternalBrowser[] externalBrowsers;
-
+
    /**
     * @param shell the containing shell
     */
@@ -99,9 +99,11 @@
    @Override
    public boolean initialize(String args) {
      if (args == null || args.length() == 0) {
-      getLogger().log(TreeLogger.ERROR, "ExternalBrowser runstyle requires  
an "
-          + "argument listing one or more executables of external browsers  
to "
-          + "launch");
+      getLogger().log(
+          TreeLogger.ERROR,
+          "ExternalBrowser runstyle requires an "
+              + "argument listing one or more executables of external  
browsers to "
+              + "launch");
        return false;
      }
      String browsers[] = args.split(",");
=======================================
--- /trunk/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java  Fri Nov  6  
10:03:51 2009
+++ /trunk/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java  Mon Nov 16  
18:58:08 2009
@@ -54,10 +54,10 @@
        IncorrectnessListener, OnbeforeunloadHandler {

      private final BrowserVersion browser;
+    private final boolean developmentMode;
+    private final TreeLogger treeLogger;
      private final String url;
      private Object waitForUnload = new Object();
-    private final TreeLogger treeLogger;
-    private final boolean developmentMode;

      public HtmlUnitThread(BrowserVersion browser, String url,
          TreeLogger treeLogger, boolean developmentMode) {
@@ -148,7 +148,7 @@
    }

    private static final Map<String, BrowserVersion> BROWSER_MAP =  
createBrowserMap();
-
+
    /*
     * as long as this number is greater than 1, GWTTestCaseTest::testRetry  
will
     * pass
@@ -181,8 +181,8 @@
    }

    private Set<BrowserVersion> browsers = new HashSet<BrowserVersion>();
-  private final List<Thread> threads = new ArrayList<Thread>();
    private boolean developmentMode;
+  private final List<Thread> threads = new ArrayList<Thread>();

    /**
     * Create a RunStyle instance with the passed-in browser targets.
@@ -206,16 +206,17 @@
      for (String browserName : args.split(",")) {
        BrowserVersion browser = BROWSER_MAP.get(browserName);
        if (browser == null) {
-        getLogger().log(TreeLogger.ERROR, "RunStyleHtmlUnit: Unknown  
browser "
-            + "name " + browserName + ", expected browser name: one of "
-            + BROWSER_MAP.keySet());
+        getLogger().log(
+            TreeLogger.ERROR,
+            "RunStyleHtmlUnit: Unknown browser " + "name " + browserName
+                + ", expected browser name: one of " +  
BROWSER_MAP.keySet());
          return false;
        }
        browserSet.add(browser);
      }
      browsers = Collections.unmodifiableSet(browserSet);
-
-    setTries(DEFAULT_TRIES); // set to the default value for this RunStyle
+
+    setTries(DEFAULT_TRIES); // set to the default value for this RunStyle
      return true;
    }

=======================================
--- /trunk/user/src/com/google/gwt/junit/RunStyleManual.java    Fri Oct 30  
14:27:25 2009
+++ /trunk/user/src/com/google/gwt/junit/RunStyleManual.java    Mon Nov 16  
18:58:08 2009
@@ -37,8 +37,8 @@
        try {
          numClients = Integer.parseInt(args);
        } catch (NumberFormatException e) {
-        getLogger().log(TreeLogger.ERROR, "Error parsing argument \""
-            + args + "\"", e);
+        getLogger().log(TreeLogger.ERROR,
+            "Error parsing argument \"" + args + "\"", e);
          return false;
        }
      }
=======================================
--- /trunk/user/src/com/google/gwt/junit/RunStyleRemoteWeb.java Thu Nov  5  
11:44:07 2009
+++ /trunk/user/src/com/google/gwt/junit/RunStyleRemoteWeb.java Mon Nov 16  
18:58:08 2009
@@ -133,13 +133,13 @@

    private static final int RESPONSE_TIMEOUT_MS = 10000;

-  private RemoteBrowser[] remoteBrowsers;
-
    /**
     * The list of hosts that were interrupted.
     */
    private Set<String> interruptedHosts;

+  private RemoteBrowser[] remoteBrowsers;
+
    /**
     * A separate lock to control access to {...@link #interruptedHosts}. This  
keeps
     * the main thread calls into {...@link #getInterruptedHosts()} from having 
 
to
=======================================
--- /trunk/user/src/com/google/gwt/junit/RunStyleSelenium.java  Mon Nov 16  
12:53:32 2009
+++ /trunk/user/src/com/google/gwt/junit/RunStyleSelenium.java  Mon Nov 16  
18:58:08 2009
@@ -35,7 +35,9 @@
     */
    protected static interface SeleniumWrapper {
      void createSelenium(String domain);
+
      Selenium getSelenium();
+
      String getSpecifier();
    }

@@ -44,8 +46,7 @@
     */
    static class RCSelenium implements SeleniumWrapper {

-    private static final Pattern PATTERN =
-        Pattern.compile("([\\w\\.-]+):([\\d]+)/(.+)");
+    private static final Pattern PATTERN =  
Pattern.compile("([\\w\\.-]+):([\\d]+)/(.+)");

      /*
       * Visible for testing.
@@ -85,14 +86,14 @@
        this.port = Integer.parseInt(matcher.group(2));
      }
    }
-
-  private SeleniumWrapper remotes[];

    /**
     * The list of hosts that were interrupted.
     */
    private Set<String> interruptedHosts;

+  private SeleniumWrapper remotes[];
+
    /**
     * A separate lock to control access to {...@link #interruptedHosts}. This  
keeps
     * the main thread calls into {...@link #getInterruptedHosts()} from having 
 
to be
@@ -186,7 +187,7 @@

    /**
     * Factory method for {...@link SeleniumWrapper}.
-   *
+   *
     * @param seleniumSpecifier Specifies the Selenium instance to create
     * @return an instance of {...@link SeleniumWrapper}
     */
=======================================
--- /trunk/user/test/com/google/gwt/junit/CompileStrategyTest.java      Thu Nov 
  
5 11:44:07 2009
+++ /trunk/user/test/com/google/gwt/junit/CompileStrategyTest.java      Mon Nov 
 
16 18:58:08 2009
@@ -32,81 +32,19 @@
   * {...@link GWTTestCase} to ensure that JUnitShell is already initialized.
   */
  public class CompileStrategyTest extends TestCase {
-
-  /**
-   * A mock {...@link RunStyle} used for testing.
-   */
-  private static class MockRunStyle extends RunStyle {
-
-    public MockRunStyle() {
-      super(null);
-    }
-
-    @Override
-    public void launchModule(String moduleName) {
-    }
-  }
-
-  /**
-   * A mock {...@link JUnitMessageQueue} used for testing.
-   */
-  private static class MockJUnitMessageQueue extends JUnitMessageQueue {
-
-    /**
-     * The test blocks added to the queue.
-     */
-    private List<TestInfo[]> testBlocks;
-
-    /**
-     * Indicates that this is the last test block.
-     */
-    private boolean isLastBlock;
-
-    public MockJUnitMessageQueue() {
-      super();
-    }
-
-    @Override
-    void addTestBlocks(List<TestInfo[]> newTestBlocks, boolean  
isLastBlock) {
-      assertNull(testBlocks);
-      this.testBlocks = newTestBlocks;
-      this.isLastBlock = isLastBlock;
-    }
-
-    void assertIsLastBlock(boolean expected) {
-      assertEquals(expected, isLastBlock);
-    }
-
-    void assertTestBlocks(List<TestInfo[]> expected) {
-      if (expected == null || testBlocks == null) {
-        assertEquals(expected, testBlocks);
-        return;
-      }
-
-      assertEquals(expected.size(), testBlocks.size());
-      for (int i = 0; i < testBlocks.size(); i++) {
-        TestInfo[] actualBlock = testBlocks.get(i);
-        TestInfo[] expectedBlock = expected.get(i);
-        assertEquals(expectedBlock.length, actualBlock.length);
-        for (int j = 0; j < expectedBlock.length; j++) {
-          assertEquals(expectedBlock[j], actualBlock[j]);
-        }
-      }
-    }
-  }

    /**
     * A mock {...@link CompileStrategy} used for testing.
     */
    private static class MockCompileStrategy extends CompileStrategy {

+    private MockJUnitMessageQueue messageQueue = new  
MockJUnitMessageQueue();
+
      /**
       * The number of modules to mock.
       */
      private int mockModuleCount;

-    private MockJUnitMessageQueue messageQueue = new  
MockJUnitMessageQueue();
-
      /**
       * Construct a new {...@link MockCompileStrategy}.
       *
@@ -167,24 +105,66 @@
      }
    }

-  public void testMaybeAddTestBlockForCurrentTestWithoutBatching() {
-    BatchingStrategy batchingStrategy = new NoBatchingStrategy();
-    assertTrue(batchingStrategy.isSingleTestOnly());
-
-    // Maybe add the current test.
-    GWTTestCase testCase = new MockGWTTestCase();
-    MockCompileStrategy strategy = new MockCompileStrategy(-1);
-    strategy.maybeAddTestBlockForCurrentTest(testCase, batchingStrategy);
-
-    // Generate the expected blocks.
-    TestInfo testInfo = new TestInfo(testCase.getSyntheticModuleName(),
-        testCase.getClass().getName(), testCase.getName());
-    List<TestInfo[]> testBlocks = new ArrayList<TestInfo[]>();
-    testBlocks.add(new TestInfo[] {testInfo});
-
-    // Verify the test is added to the queue.
-    strategy.getMessageQueue().assertIsLastBlock(false);
-    strategy.getMessageQueue().assertTestBlocks(testBlocks);
+  /**
+   * A mock {...@link JUnitMessageQueue} used for testing.
+   */
+  private static class MockJUnitMessageQueue extends JUnitMessageQueue {
+
+    /**
+   * Indicates that this is the last test block.
+   */
+    private boolean isLastBlock;
+
+    /**
+                         * The test blocks added to the queue.
+                         */
+    private List<TestInfo[]> testBlocks;
+
+    public MockJUnitMessageQueue() {
+      super();
+    }
+
+    @Override
+    void addTestBlocks(List<TestInfo[]> newTestBlocks, boolean  
isLastBlock) {
+      assertNull(testBlocks);
+      this.testBlocks = newTestBlocks;
+      this.isLastBlock = isLastBlock;
+    }
+
+    void assertIsLastBlock(boolean expected) {
+      assertEquals(expected, isLastBlock);
+    }
+
+    void assertTestBlocks(List<TestInfo[]> expected) {
+      if (expected == null || testBlocks == null) {
+        assertEquals(expected, testBlocks);
+        return;
+      }
+
+      assertEquals(expected.size(), testBlocks.size());
+      for (int i = 0; i < testBlocks.size(); i++) {
+        TestInfo[] actualBlock = testBlocks.get(i);
+        TestInfo[] expectedBlock = expected.get(i);
+        assertEquals(expectedBlock.length, actualBlock.length);
+        for (int j = 0; j < expectedBlock.length; j++) {
+          assertEquals(expectedBlock[j], actualBlock[j]);
+        }
+      }
+    }
+  }
+
+  /**
+ * A mock {...@link RunStyle} used for testing.
+ */
+  private static class MockRunStyle extends RunStyle {
+
+    public MockRunStyle() {
+      super(null);
+    }
+
+    @Override
+    public void launchModule(String moduleName) {
+    }
    }

    public void testMaybeAddTestBlockForCurrentTestWithBatching() {
@@ -200,24 +180,24 @@
      strategy.getMessageQueue().assertTestBlocks(null);
    }

-  public void testMaybeCompileModuleImplWithoutBatching() {
+  public void testMaybeAddTestBlockForCurrentTestWithoutBatching() {
      BatchingStrategy batchingStrategy = new NoBatchingStrategy();
      assertTrue(batchingStrategy.isSingleTestOnly());

      // Maybe add the current test.
-    RunStyle runStyle = new MockRunStyle();
      GWTTestCase testCase = new MockGWTTestCase();
      MockCompileStrategy strategy = new MockCompileStrategy(-1);
-    try {
-      strategy.maybeCompileModuleImpl(testCase.getModuleName(),
-          testCase.getSyntheticModuleName(), testCase.getStrategy(),  
runStyle,
-          batchingStrategy, TreeLogger.NULL);
-    } catch (UnableToCompleteException e) {
-      fail("Unexpected UnableToCompleteException: " + e.getMessage());
-    }
-
-    // Verify the test block is not added to the queue.
-    strategy.getMessageQueue().assertTestBlocks(null);
+    strategy.maybeAddTestBlockForCurrentTest(testCase, batchingStrategy);
+
+    // Generate the expected blocks.
+    TestInfo testInfo = new TestInfo(testCase.getSyntheticModuleName(),
+        testCase.getClass().getName(), testCase.getName());
+    List<TestInfo[]> testBlocks = new ArrayList<TestInfo[]>();
+    testBlocks.add(new TestInfo[] {testInfo});
+
+    // Verify the test is added to the queue.
+    strategy.getMessageQueue().assertIsLastBlock(false);
+    strategy.getMessageQueue().assertTestBlocks(testBlocks);
    }

    public void testMaybeCompileModuleImplWithBatchingLastModule() {
@@ -263,4 +243,24 @@
      strategy.getMessageQueue().assertTestBlocks(
          batchingStrategy.getTestBlocks(testCase.getSyntheticModuleName()));
    }
-}
+
+  public void testMaybeCompileModuleImplWithoutBatching() {
+    BatchingStrategy batchingStrategy = new NoBatchingStrategy();
+    assertTrue(batchingStrategy.isSingleTestOnly());
+
+    // Maybe add the current test.
+    RunStyle runStyle = new MockRunStyle();
+    GWTTestCase testCase = new MockGWTTestCase();
+    MockCompileStrategy strategy = new MockCompileStrategy(-1);
+    try {
+      strategy.maybeCompileModuleImpl(testCase.getModuleName(),
+          testCase.getSyntheticModuleName(), testCase.getStrategy(),  
runStyle,
+          batchingStrategy, TreeLogger.NULL);
+    } catch (UnableToCompleteException e) {
+      fail("Unexpected UnableToCompleteException: " + e.getMessage());
+    }
+
+    // Verify the test block is not added to the queue.
+    strategy.getMessageQueue().assertTestBlocks(null);
+  }
+}

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to