HTMLPanel now allows an arbitrary element to be set as its root, via
new constructor HTMLPanel(String tag, String html). Reviewed by jgw

  http://gwt-code-reviews.appspot.com/39802

Introduces FakeMessagesMaker, to allow JUnit (non-GWTTestCase) testing
of objects that rely on generated Messages objects. Reviewed by scottb

  http://gwt-code-reviews.appspot.com/48809



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5725 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/junit/FakeMessagesMaker.java b/user/src/com/google/gwt/junit/FakeMessagesMaker.java
new file mode 100644
index 0000000..dc37afc
--- /dev/null
+++ b/user/src/com/google/gwt/junit/FakeMessagesMaker.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2009 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;
+
+import com.google.gwt.i18n.client.Messages;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+
+/**
+ * Helper to make a fake implementation of any {@link Messages} interface via
+ * reflection, for use in JUnit tests. (This will not work in GWTTestCase.) All
+ * calls to the returned object return the method name followed by the passed
+ * parameters as a list surrounded by [].
+ * <p>
+ * Note that the default message text is very consciously not made available
+ * through the fake, to help tests ensure that specific translations of
+ * localized text are not relied upon.
+ * <p>
+ * Sample use:
+ *
+ * <pre>interface MyMessages extends Messages {
+ *   &#64;DefaultMessage("Isn''t this the fakiest?")
+ *   &#64;Description("A sample message to be tested.")
+ *   String myMessage();
+ * }
+ *
+ * public void testSimple() {
+ *  MyMessages messages = FakeMessagesMaker.create(MyMessages.class);
+ *  assertEquals("myMessage", messages.myMessage());
+ * }
+ * </pre>
+ */
+public class FakeMessagesMaker implements InvocationHandler {
+  public static <T extends Messages> T create(Class<T> messagesClass) {
+    return messagesClass.cast(Proxy.newProxyInstance(
+        FakeMessagesMaker.class.getClassLoader(), new Class[] {messagesClass},
+        new FakeMessagesMaker()));
+  }
+
+  public Object invoke(Object proxy, Method method, Object[] args)
+      throws Throwable {
+    String name = method.getName();
+
+    return (args == null || args.length == 0) ? name : name
+        + Arrays.asList(args);
+  }
+}
diff --git a/user/src/com/google/gwt/user/client/ui/HTMLPanel.java b/user/src/com/google/gwt/user/client/ui/HTMLPanel.java
index 1bbdeb6..d9bf52a 100644
--- a/user/src/com/google/gwt/user/client/ui/HTMLPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/HTMLPanel.java
@@ -40,17 +40,30 @@
   }
 
   /**
-   * Creates an HTML panel with the specified HTML contents. Any element within
-   * this HTML that has a specified id can contain a child widget.
+   * Creates an HTML panel with the specified HTML contents inside a DIV
+   * element. Any element within this HTML that has a specified id can contain a
+   * child widget.
    * 
    * @param html the panel's HTML
    */
   public HTMLPanel(String html) {
-    setElement(DOM.createDiv());
-    DOM.setInnerHTML(getElement(), html);
+    this("div", html);
   }
 
   /**
+   * Creates an HTML panel whose root element has the given tag, and with the
+   * specified HTML contents. Any element within this HTML that has a specified
+   * id can contain a child widget.
+   * 
+   * @param tag the tag of the root element
+   * @param html the panel's HTML
+   */
+  public HTMLPanel(String tag, String html) {
+    setElement(DOM.createElement(tag));
+    DOM.setInnerHTML(getElement(), html);
+  }
+  
+  /**
    * Adds a child widget to the panel, contained within the HTML element
    * specified by a given id.
    * 
diff --git a/user/test/com/google/gwt/junit/FakeMessagesMakerTest.java b/user/test/com/google/gwt/junit/FakeMessagesMakerTest.java
new file mode 100644
index 0000000..ddf541e
--- /dev/null
+++ b/user/test/com/google/gwt/junit/FakeMessagesMakerTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2009 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;
+
+import com.google.gwt.i18n.client.Messages;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests of FakeMessagesMaker.
+ */
+public class FakeMessagesMakerTest extends TestCase {
+  interface MyMessages extends Messages {
+    @DefaultMessage("Isn''t this the fakiest?")
+    @Description("A sample message to be tested.")
+    String myMessage();
+    
+    @DefaultMessage("Isn''t this the fakiest? Pick one: {1} or {2}?")
+    @Description("A sample message with parameters.")
+    String myArgumentedMessage(@Example("yes") String yes, 
+        @Example("no") String no);
+  }
+  
+  public void testSimple() {
+    MyMessages messages = FakeMessagesMaker.create(MyMessages.class);
+    assertEquals("myMessage", messages.myMessage());
+  }
+  
+  public void testArgs() {
+    MyMessages messages = FakeMessagesMaker.create(MyMessages.class);
+    assertEquals("myArgumentedMessage[oui, non]", 
+        messages.myArgumentedMessage("oui", "non"));
+  }
+}
diff --git a/user/test/com/google/gwt/junit/JUnitSuite.java b/user/test/com/google/gwt/junit/JUnitSuite.java
new file mode 100644
index 0000000..a8807eb
--- /dev/null
+++ b/user/test/com/google/gwt/junit/JUnitSuite.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2009 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;
+
+import com.google.gwt.junit.client.GWTTestCaseTest;
+import com.google.gwt.junit.tools.GWTTestSuite;
+
+import junit.framework.Test;
+
+/**
+ * Tests of the junit package.
+ */
+public class JUnitSuite {
+  public static Test suite() {
+    GWTTestSuite suite = new GWTTestSuite("Test for suite for com.google.gwt.junit");
+
+    suite.addTestSuite(FakeMessagesMakerTest.class);
+
+    // client
+    // Suppressed due to flakiness on Linux
+    // suite.addTestSuite(BenchmarkTest.class);
+    suite.addTestSuite(GWTTestCaseTest.class);
+
+    // These two are intended only to be run manually. See class comments
+    // suite.addTestSuite(ParallelRemoteTest.class);
+    // suite.addTestSuite(TestManualAsync.class);
+
+    // remote
+    // Run manually only, launches servers that die on port contention
+    // suite.addTestSuite(BrowserManagerServerTest.class);
+
+    return suite;
+  }
+}
diff --git a/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java b/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java
index 9e7f8ac..6e62376 100644
--- a/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java
+++ b/user/test/com/google/gwt/user/client/ui/HTMLPanelTest.java
@@ -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
@@ -120,6 +120,28 @@
   }
 
   /**
+   * Tests arbitrary root tag
+   */
+  public void testCustomRootTag() {
+    HTMLPanel hp = new HTMLPanel("table", "<tr><td>Hello <span id='labelHere'></span></td></tr>");
+    InlineLabel label = new InlineLabel("World");
+    hp.addAndReplaceElement(label, "labelHere");
+
+    Element parent = label.getElement().getParentElement();
+    assertEquals("td", parent.getTagName().toLowerCase());
+
+    parent = parent.getParentElement();
+    assertEquals("tr", parent.getTagName().toLowerCase());
+
+    while (parent != null && parent != hp.getElement()) {
+      parent = parent.getParentElement();
+    }
+
+    assertNotNull(parent);
+    assertEquals("table", parent.getTagName().toLowerCase());
+  }
+
+  /**
    * Ensure that {@link HTMLPanel#getElementById(String)} behaves properly in
    * both attached and unattached states.
    */