Revision: 9041
Author: [email protected]
Date: Wed Oct 13 12:25:22 2010
Log: Deprecate DeferredCommand and IncrementalCommand.
Add MockScheduler.
Patch by: bobv
Review by: rjrjr

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

http://code.google.com/p/google-web-toolkit/source/detail?r=9041

Added:
 /trunk/user/src/com/google/gwt/core/client/testing
 /trunk/user/src/com/google/gwt/core/client/testing/StubScheduler.java
Modified:
 /trunk/user/src/com/google/gwt/core/client/Scheduler.java
 /trunk/user/src/com/google/gwt/user/client/Command.java
 /trunk/user/src/com/google/gwt/user/client/DeferredCommand.java
 /trunk/user/src/com/google/gwt/user/client/IncrementalCommand.java

=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/core/client/testing/StubScheduler.java Wed Oct 13 12:25:22 2010
@@ -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);
+  }
+}
=======================================
--- /trunk/user/src/com/google/gwt/core/client/Scheduler.java Tue Dec 15 13:40:53 2009 +++ /trunk/user/src/com/google/gwt/core/client/Scheduler.java Wed Oct 13 12:25:22 2010
@@ -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 {

=======================================
--- /trunk/user/src/com/google/gwt/user/client/Command.java Tue Aug 10 10:18:55 2010 +++ /trunk/user/src/com/google/gwt/user/client/Command.java Wed Oct 13 12:25:22 2010
@@ -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.
    */
=======================================
--- /trunk/user/src/com/google/gwt/user/client/DeferredCommand.java Tue Aug 10 10:18:55 2010 +++ /trunk/user/src/com/google/gwt/user/client/DeferredCommand.java Wed Oct 13 12:25:22 2010
@@ -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);
=======================================
--- /trunk/user/src/com/google/gwt/user/client/IncrementalCommand.java Tue Aug 10 10:18:55 2010 +++ /trunk/user/src/com/google/gwt/user/client/IncrementalCommand.java Wed Oct 13 12:25:22 2010
@@ -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.

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

Reply via email to