Revision: 8378
Author: [email protected]
Date: Tue Jul 13 09:51:15 2010
Log: Speed up UiBinderTest by having all tests share one instance of the
test app. Also clean up some deprecation warnings.

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

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8378

Modified:
 /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
 /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTestApp.java
 /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java

=======================================
--- /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java Fri Jul 2 08:22:57 2010 +++ /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java Tue Jul 13 09:51:15 2010
@@ -17,7 +17,6 @@

 import com.google.gwt.core.client.GWT;
 import com.google.gwt.dom.client.DivElement;
-import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.ParagraphElement;
 import com.google.gwt.dom.client.SpanElement;
@@ -28,13 +27,11 @@
 import com.google.gwt.uibinder.test.client.EnumeratedLabel.Suffix;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.ui.DisclosurePanel;
-import com.google.gwt.user.client.ui.DockPanel;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HTMLPanel;
 import com.google.gwt.user.client.ui.Image;
 import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.RadioButton;
-import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.StackPanel;
 import com.google.gwt.user.client.ui.Widget;

@@ -44,7 +41,8 @@
 public class UiBinderTest extends GWTTestCase {
   private WidgetBasedUi widgetUi;
   private DomBasedUi domUi;
-  private DockPanel root;
+  @SuppressWarnings("deprecation")
+  private com.google.gwt.user.client.ui.DockPanel root;

   @Override
   public String getModuleName() {
@@ -54,22 +52,12 @@
   @Override
   public void gwtSetUp() throws Exception {
     super.gwtSetUp();
-    RootPanel.get().clear();
-    domUi = new DomBasedUi("Cherished User");
-    Document.get().getBody().appendChild(domUi.root);
-
-    widgetUi = new WidgetBasedUi();
+    UiBinderTestApp app = UiBinderTestApp.getInstance();
+    widgetUi = app.getWidgetUi();
+    domUi = app.getDomUi();
     root = widgetUi.root;
-    RootPanel.get().add(widgetUi);
   }

-  @Override
-  public void gwtTearDown() throws Exception {
-    domUi.root.getParentElement().removeChild(domUi.root);
-    RootPanel.get().clear();
-    super.gwtTearDown();
-  }
-
   public void testTableWithColumns() {
     assertEquals("col", domUi.narrowColumn.getTagName().toLowerCase());
     assertEquals("tr", domUi.tr.getTagName().toLowerCase());
@@ -168,11 +156,12 @@
         widgetUi.bundledDivLegacy.getClassName());
   }

+  @SuppressWarnings("deprecation")
   public void testCenter() {
     // TODO(rjrjr) More of a test of HTMLPanelParser

     Widget center = getCenter();
-    assertEquals(DockPanel.CENTER, root.getWidgetDirection(center));
+ assertEquals(com.google.gwt.user.client.ui.DockPanel.CENTER, root.getWidgetDirection(center));
     assertEquals(HTMLPanel.class, center.getClass());
     String html = center.getElement().getInnerHTML();
     assertTrue(html.contains("main area"));
@@ -355,9 +344,8 @@

   public void testNoOverrideInheritedSharedCssClasses() {
     Bundle bundle = GWT.create(Bundle.class);
-    WidgetBasedUi ui = GWT.create(WidgetBasedUi.class);
     String publicStyle = bundle.style().menuBar();
-    String privateStyle = ui.myStyle.menuBar();
+    String privateStyle = widgetUi.myStyle.menuBar();
     assertEquals(publicStyle, privateStyle);
   }

@@ -370,9 +358,10 @@
     assertTrue(innerHTML.endsWith("</span>&nbsp;\u261C"));
   }

+  @SuppressWarnings("deprecation")
   public void testNorth() {
     Widget north = root.getWidget(0);
-    assertEquals(DockPanel.NORTH, root.getWidgetDirection(north));
+ assertEquals(com.google.gwt.user.client.ui.DockPanel.NORTH, root.getWidgetDirection(north));
     assertEquals(HTML.class, north.getClass());
     assertTrue(((HTML) north).getHTML().contains("Title area"));
   }
@@ -437,9 +426,10 @@
assertEquals("100%", root.getElement().getStyle().getProperty("width"));
   }

+  @SuppressWarnings("deprecation")
   public void testWest() {
     Widget west = root.getWidget(1);
-    assertEquals(DockPanel.WEST, root.getWidgetDirection(west));
+ assertEquals(com.google.gwt.user.client.ui.DockPanel.WEST, root.getWidgetDirection(west));
     assertEquals(HTML.class, west.getClass());
     String html = ((HTML) west).getHTML();
     assertTrue(html.contains("side bar"));
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTestApp.java Thu Oct 29 21:43:40 2009 +++ /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTestApp.java Tue Jul 13 09:51:15 2010
@@ -1,12 +1,12 @@
 /*
  * Copyright 2008 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
@@ -23,11 +23,47 @@
  * Demonstration of templated UI. Used by UiBinderTest
  */
 public class UiBinderTestApp implements EntryPoint {
-
-  public void onModuleLoad() {
-    DomBasedUi boundUi = new DomBasedUi("Mr. User Man");
-    Document.get().getBody().appendChild(boundUi.root);
-
-    RootPanel.get().add(new WidgetBasedUi());
+  private static UiBinderTestApp instance;
+
+  /**
+   * Ensure the singleton instance has installed its UI, and return it.
+   */
+  public static UiBinderTestApp getInstance() {
+    if (instance == null) {
+      setAndInitInstance(new UiBinderTestApp());
+    }
+
+    return instance;
+  }
+
+  private static void setAndInitInstance(UiBinderTestApp newInstance) {
+    instance = newInstance;
+    instance.domUi = new DomBasedUi("Mr. User Man");
+    Document.get().getBody().appendChild(instance.domUi.root);
+
+    instance.widgetUi = new WidgetBasedUi();
+    RootPanel.get().add(instance.widgetUi);
+  }
+
+  private DomBasedUi domUi;
+
+  private WidgetBasedUi widgetUi;
+
+  private UiBinderTestApp() {
+  }
+
+  public DomBasedUi getDomUi() {
+    return domUi;
+  }
+
+  public WidgetBasedUi getWidgetUi() {
+    return widgetUi;
+  }
+
+  /**
+   * Entry point method, called only when this is run as an application.
+   */
+  public void onModuleLoad() {
+    setAndInitInstance(this);
   }
 }
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java Fri Apr 2 07:37:08 2010 +++ /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java Tue Jul 13 09:51:15 2010
@@ -33,7 +33,6 @@
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.DisclosurePanel;
-import com.google.gwt.user.client.ui.DockPanel;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HTMLPanel;
 import com.google.gwt.user.client.ui.HasHTML;
@@ -100,7 +99,8 @@
   @UiField Widget myDisclosurePanelItem;
   @UiField Tree myTree;
   @UiField Element nonStandardElement;
-  @UiField DockPanel root;
+  @SuppressWarnings("deprecation")
+  @UiField com.google.gwt.user.client.ui.DockPanel root;
   @UiField Widget sideBarWidget;
   @UiField DivElement sideBar;
   @UiField SpanElement spanInMsg;

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

Reply via email to