Revision: 6063
Author: [email protected]
Date: Tue Sep  1 15:18:26 2009
Log: Internal contribution that extends FakeMessagesMaker to work with  
Constants as well.

review by: rjrjr

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

Modified:
  /trunk/user/src/com/google/gwt/junit/FakeMessagesMaker.java
  /trunk/user/test/com/google/gwt/junit/FakeMessagesMakerTest.java

=======================================
--- /trunk/user/src/com/google/gwt/junit/FakeMessagesMaker.java Mon Jul 13  
14:05:32 2009
+++ /trunk/user/src/com/google/gwt/junit/FakeMessagesMaker.java Tue Sep  1  
15:18:26 2009
@@ -1,12 +1,12 @@
  /*
   * 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
@@ -15,6 +15,7 @@
   */
  package com.google.gwt.junit;

+import com.google.gwt.i18n.client.Constants;
  import com.google.gwt.i18n.client.Messages;

  import java.lang.reflect.InvocationHandler;
@@ -23,10 +24,10 @@
  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 [].
+ * Helper to make a fake implementation of any {...@link Messages} or
+ * {...@link Constants} 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
@@ -52,6 +53,12 @@
          FakeMessagesMaker.class.getClassLoader(), new Class[]  
{messagesClass},
          new FakeMessagesMaker()));
    }
+
+  public static <T extends Constants> T create(Class<T> constantsClass) {
+    return constantsClass.cast(Proxy.newProxyInstance(
+        FakeMessagesMaker.class.getClassLoader(), new Class[]  
{constantsClass},
+        new FakeMessagesMaker()));
+  }

    public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
=======================================
--- /trunk/user/test/com/google/gwt/junit/FakeMessagesMakerTest.java    Mon  
Jul 13 14:05:32 2009
+++ /trunk/user/test/com/google/gwt/junit/FakeMessagesMakerTest.java    Tue  
Sep  1 15:18:26 2009
@@ -1,12 +1,12 @@
  /*
   * 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
@@ -15,6 +15,7 @@
   */
  package com.google.gwt.junit;

+import com.google.gwt.i18n.client.Constants;
  import com.google.gwt.i18n.client.Messages;

  import junit.framework.TestCase;
@@ -27,21 +28,41 @@
      @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,
+    String myArgumentedMessage(@Example("yes") String yes,
          @Example("no") String no);
    }
-
-  public void testSimple() {
+
+  interface MyConstants extends Constants {
+    @DefaultStringValue("This is a very simple message")
+    String myFixedMessage();
+
+    @DefaultStringValue("This message is so complicated, it requires a  
description")
+    @Description("42")
+    String messageWithDescription();
+  }
+
+  public void testSimpleWithMessages() {
      MyMessages messages = FakeMessagesMaker.create(MyMessages.class);
      assertEquals("myMessage", messages.myMessage());
    }
-
-  public void testArgs() {
+
+  public void testArgsWithMessages() {
      MyMessages messages = FakeMessagesMaker.create(MyMessages.class);
-    assertEquals("myArgumentedMessage[oui, non]",
+    assertEquals("myArgumentedMessage[oui, non]",
          messages.myArgumentedMessage("oui", "non"));
    }
-}
+
+  public void testSimpleWithConstants() {
+    MyConstants constants = FakeMessagesMaker.create(MyConstants.class);
+    assertEquals("myFixedMessage", constants.myFixedMessage());
+  }
+
+  public void testConstantWithDescription() {
+    MyConstants constants = FakeMessagesMaker.create(MyConstants.class);
+    assertEquals("messageWithDescription",  
constants.messageWithDescription());
+  }
+
+}

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

Reply via email to