Deprecate DeferredCommand and IncrementalCommand.
Add MockScheduler.
Patch by: bobv
Review by: rjrjr

Review at http://gwt-code-reviews.appspot.com/982802


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9041 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/core/client/Scheduler.java b/user/src/com/google/gwt/core/client/Scheduler.java
index ef6a090..7fceb6f 100644
--- a/user/src/com/google/gwt/core/client/Scheduler.java
+++ b/user/src/com/google/gwt/core/client/Scheduler.java
@@ -21,6 +21,8 @@
  * This class provides low-level task scheduling primitives. Any exceptions
  * thrown by the command objects executed by the scheduler will be passed to the
  * {@link GWT.UncaughtExceptionHandler} if one is installed.
+ * 
+ * @see com.google.gwt.core.client.testing.StubScheduler
  */
 public abstract class Scheduler {
 
diff --git a/user/src/com/google/gwt/core/client/testing/StubScheduler.java b/user/src/com/google/gwt/core/client/testing/StubScheduler.java
new file mode 100644
index 0000000..c59fc1a
--- /dev/null
+++ b/user/src/com/google/gwt/core/client/testing/StubScheduler.java
@@ -0,0 +1,84 @@
+/*
+ * 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.core.client.testing;
+
+import com.google.gwt.core.client.Scheduler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A no-op implementation of Scheduler that simply records its arguments.
+ */
+public class StubScheduler extends Scheduler {
+  private final List<RepeatingCommand> repeatingCommands = new ArrayList<RepeatingCommand>();
+
+  private final List<ScheduledCommand> scheduledCommands = new ArrayList<ScheduledCommand>();
+
+  /**
+   * Returns the RepeatingCommands that have been passed into the MockScheduler.
+   */
+  public List<RepeatingCommand> getRepeatingCommands() {
+    return repeatingCommands;
+  }
+
+  /**
+   * Returns the ScheduledCommands that have been passed into the MockScheduler.
+   */
+  public List<ScheduledCommand> getScheduledCommands() {
+    return scheduledCommands;
+  }
+
+  @Override
+  public void scheduleDeferred(ScheduledCommand cmd) {
+    scheduledCommands.add(cmd);
+  }
+
+  @Override
+  public void scheduleEntry(RepeatingCommand cmd) {
+    repeatingCommands.add(cmd);
+  }
+
+  @Override
+  public void scheduleEntry(ScheduledCommand cmd) {
+    scheduledCommands.add(cmd);
+  }
+
+  @Override
+  public void scheduleFinally(RepeatingCommand cmd) {
+    repeatingCommands.add(cmd);
+  }
+
+  @Override
+  public void scheduleFinally(ScheduledCommand cmd) {
+    scheduledCommands.add(cmd);
+  }
+
+  @Override
+  public void scheduleFixedDelay(RepeatingCommand cmd, int delayMs) {
+    repeatingCommands.add(cmd);
+  }
+
+  @Override
+  public void scheduleFixedPeriod(RepeatingCommand cmd, int delayMs) {
+    repeatingCommands.add(cmd);
+  }
+
+  @Override
+  public void scheduleIncremental(RepeatingCommand cmd) {
+    repeatingCommands.add(cmd);
+  }
+}
diff --git a/user/src/com/google/gwt/user/client/Command.java b/user/src/com/google/gwt/user/client/Command.java
index 90b9bde..e664e31 100644
--- a/user/src/com/google/gwt/user/client/Command.java
+++ b/user/src/com/google/gwt/user/client/Command.java
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.user.client;
 
+import com.google.gwt.core.client.Scheduler;
+
 /**
  * Encapsulates an action for later execution, often from a different context.
  * 
@@ -22,14 +24,16 @@
  * The Command interface provides a layer of separation between the code
  * specifying some behavior and the code invoking that behavior. This separation
  * aids in creating reusable code. For example, a
- * {@link com.google.gwt.user.client.ui.MenuItem} can have a Command
- * associated with it that it executes when the menu item is chosen by the user.
+ * {@link com.google.gwt.user.client.ui.MenuItem} can have a Command associated
+ * with it that it executes when the menu item is chosen by the user.
  * Importantly, the code that constructed the Command to be executed when the
  * menu item is invoked knows nothing about the internals of the MenuItem class
- * and vice-versa.</p>
+ * and vice-versa.
+ * </p>
  * 
- * <p> The Command interface is often implemented with an anonymous inner class.
- * For example,
+ * <p>
+ * The Command interface is often implemented with an anonymous inner class. For
+ * example,
  * 
  * <pre>
  * Command sayHello = new Command() {
@@ -41,9 +45,9 @@
  * </pre>
  * 
  * </p>
+ * This type extends ScheduledCommand to help migrate from DeferredCommand API.
  */
-public interface Command {
-
+public interface Command extends Scheduler.ScheduledCommand {
   /**
    * Causes the Command to perform its encapsulated behavior.
    */
diff --git a/user/src/com/google/gwt/user/client/DeferredCommand.java b/user/src/com/google/gwt/user/client/DeferredCommand.java
index 9fe21d4..3601913 100644
--- a/user/src/com/google/gwt/user/client/DeferredCommand.java
+++ b/user/src/com/google/gwt/user/client/DeferredCommand.java
@@ -20,7 +20,13 @@
  * handlers have completed, using the {@link #addCommand(Command)} or
  * {@link #addCommand(IncrementalCommand)} methods. This is useful when you need
  * to execute code outside of the context of the current stack.
+ * 
+ * @deprecated Replaced by
+ *             {@link com.google.gwt.core.client.Scheduler#scheduleDeferred
+ *             Scheduler.scheduleDeferred()} because the static nature of this
+ *             API prevents effective mocking for JRE-only tests.
  */
+@Deprecated
 public class DeferredCommand {
   private static final CommandExecutor commandExecutor = new CommandExecutor();
 
@@ -80,6 +86,9 @@
    * {@link DeferredCommand}s or pauses that are added after this pause will
    * wait for an additional cycle through the system event loop before
    * executing.
+   * 
+   * @deprecated with no replacement because the presence of this method causes
+   *             arbitrary scheduling decisions
    */
   public static void addPause() {
     commandExecutor.submit((Command) null);
diff --git a/user/src/com/google/gwt/user/client/IncrementalCommand.java b/user/src/com/google/gwt/user/client/IncrementalCommand.java
index d2f9739..dd53bd3 100644
--- a/user/src/com/google/gwt/user/client/IncrementalCommand.java
+++ b/user/src/com/google/gwt/user/client/IncrementalCommand.java
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.user.client;
 
+import com.google.gwt.core.client.Scheduler.RepeatingCommand;
+
 /**
  * An <code>IncrementalCommand</code> is a command that is broken into one or
  * more substeps, each substep brings the whole command nearer to completion.
@@ -22,8 +24,13 @@
  * <code>false</code>.
  * 
  * {@example com.google.gwt.examples.IncrementalCommandExample}
+ * 
+ * @deprecated Replaced by {@link RepeatingCommand} and
+ *             {@link com.google.gwt.core.client.Scheduler#scheduleIncremental
+ *             Scheduler.scheduleIncremental()}
  */
-public interface IncrementalCommand {
+@Deprecated
+public interface IncrementalCommand extends RepeatingCommand {
   /**
    * Causes the <code>IncrementalCommand</code> to execute its encapsulated
    * behavior.