[gwt-contrib] GWT Messages can support SafeHtml output. Add this support to the FakeMessagesMaker as well. (issue1890803)

2013-02-15 Thread jasonmheim

Reviewers: skybrian,

Description:
GWT Messages can support SafeHtml output. Add this support to the
FakeMessagesMaker as well.


Please review this at http://gwt-code-reviews.appspot.com/1890803/

Affected files:
  M user/src/com/google/gwt/junit/FakeMessagesMaker.java
  M user/test/com/google/gwt/junit/FakeMessagesMakerTest.java


Index: user/src/com/google/gwt/junit/FakeMessagesMaker.java
===
--- user/src/com/google/gwt/junit/FakeMessagesMaker.java(revision 11517)
+++ user/src/com/google/gwt/junit/FakeMessagesMaker.java(working copy)
@@ -16,6 +16,8 @@
 package com.google.gwt.junit;

 import com.google.gwt.i18n.client.Messages;
+import com.google.gwt.safehtml.shared.SafeHtml;
+import com.google.gwt.safehtml.shared.SafeHtmlUtils;

 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
@@ -57,7 +59,11 @@
   throws Throwable {
 String name = method.getName();

-return (args == null || args.length == 0) ? name : name
+String result = (args == null || args.length == 0) ? name : name
 + Arrays.asList(args);
+if (SafeHtml.class.isAssignableFrom(method.getReturnType())) {
+  return SafeHtmlUtils.fromString(result);
+}
+return result;
   }
 }
Index: user/test/com/google/gwt/junit/FakeMessagesMakerTest.java
===
--- user/test/com/google/gwt/junit/FakeMessagesMakerTest.java	(revision  
11517)

+++ user/test/com/google/gwt/junit/FakeMessagesMakerTest.java   (working copy)
@@ -16,6 +16,7 @@
 package com.google.gwt.junit;

 import com.google.gwt.i18n.client.Messages;
+import com.google.gwt.safehtml.shared.SafeHtml;

 import junit.framework.TestCase;

@@ -27,21 +28,30 @@
 @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);
+
+@DefaultMessage(This should be safe HTML)
+@Description(A sample SafeHtml message.)
+SafeHtml mySafeHtmlMessage();
   }
-
+
   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));
   }
+
+  public void testSafeHtml() {
+MyMessages messages = FakeMessagesMaker.create(MyMessages.class);
+assertEquals(mySafeHtmlMessage,  
messages.mySafeHtmlMessage().asString());

+  }
 }


--
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
--- 
You received this message because you are subscribed to the Google Groups Google Web Toolkit Contributors group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[gwt-contrib] Emulate System.getProperty(key, default) by always returning the (issue1654803)

2012-03-05 Thread jasonmheim

Reviewers: cromwellian,

Description:
Emulate System.getProperty(key, default) by always returning the
default. This method is commonly used by parsers for establishing the
newline character, so including this makes it possible to port such code
to GWT.


Please review this at http://gwt-code-reviews.appspot.com/1654803/

Affected files:
  M user/super/com/google/gwt/emul/java/lang/System.java
  M user/test/com/google/gwt/emultest/java/lang/SystemTest.java


Index: user/super/com/google/gwt/emul/java/lang/System.java
===
--- user/super/com/google/gwt/emul/java/lang/System.java(revision 10862)
+++ user/super/com/google/gwt/emul/java/lang/System.java(working copy)
@@ -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
@@ -95,10 +95,17 @@

   /**
* Has no effect; just here for source compatibility.
-   *
+   *
* @skip
*/
   public static void gc() {
+  }
+
+  /**
+   * Always returns default, used for source compatibility
+   */
+  public static String getProperty(String key, String def) {
+return def;
   }

   public static int identityHashCode(Object o) {
@@ -137,7 +144,7 @@
* Copy an array using native Javascript. The destination array must be  
a real
* Java array (ie, already has the GWT type info on it). No error  
checking is

* performed -- the caller is expected to have verified everything first.
-   *
+   *
* @param src source array for copy
* @param srcOfs offset into source array
* @param dest destination array for copy
Index: user/test/com/google/gwt/emultest/java/lang/SystemTest.java
===
--- user/test/com/google/gwt/emultest/java/lang/SystemTest.java	(revision  
10862)
+++ user/test/com/google/gwt/emultest/java/lang/SystemTest.java	(working  
copy)

@@ -275,4 +275,8 @@
   assertEquals(src[i + 1], dest[i]);
 }
   }
+
+  public void testGetProperty() {
+assertEquals(default, System.getProperty(key, default));
+  }
 }


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


[gwt-contrib] Add a FakeCssMaker for CSS resources similar to FakeMessagesMaker. (issue1604804)

2011-11-30 Thread jasonmheim

Reviewers: skybrian,

Description:
Add a FakeCssMaker for CSS resources similar to FakeMessagesMaker.


Please review this at http://gwt-code-reviews.appspot.com/1604804/

Affected files:
  A user/src/com/google/gwt/junit/FakeCssMaker.java
  A user/test/com/google/gwt/junit/FakeCssMakerTest.java


Index: user/src/com/google/gwt/junit/FakeCssMaker.java
===
--- user/src/com/google/gwt/junit/FakeCssMaker.java (revision 0)
+++ user/src/com/google/gwt/junit/FakeCssMaker.java (revision 0)
@@ -0,0 +1,52 @@
+/*
+ * 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.resources.client.CssResource;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * Helper to make a fake implementation of any {@link CssResource}  
interface via
+ * reflection, for use in JUnit tests. (This will not work in  
GWTTestCase.) All

+ * calls to the returned object return the method name.
+ * p
+ * Sample use:
+ *
+ * preinterface MyCss extends CssResource {
+ *   String myStyleName();
+ * }
+ *
+ * public void testSimple() {
+ *  MyCss myCss = FakeCssMaker.create(MyCss.class);
+ *  assertEquals(myStyleName, messages.myMessage());
+ * }
+ * /pre
+ */
+public class FakeCssMaker implements InvocationHandler {
+  public static T extends CssResource T create(ClassT cssClass) {
+return cssClass.cast(Proxy.newProxyInstance(
+FakeCssMaker.class.getClassLoader(), new Class[] {cssClass},
+new FakeCssMaker()));
+  }
+
+  public Object invoke(Object proxy, Method method, Object[] args)
+  throws Throwable {
+return method.getName();
+  }
+}
Index: user/test/com/google/gwt/junit/FakeCssMakerTest.java
===
--- user/test/com/google/gwt/junit/FakeCssMakerTest.java(revision 0)
+++ user/test/com/google/gwt/junit/FakeCssMakerTest.java(revision 0)
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2011 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.resources.client.CssResource;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests of FakeCssMaker.
+ */
+public class FakeCssMakerTest extends TestCase {
+  interface MyCss extends CssResource {
+String myFirstStyleName();
+String mySecondStyleName();
+  }
+
+  public void testCreate() {
+MyCss css = FakeCssMaker.create(MyCss.class);
+assertEquals(myFirstStyleName, css.myFirstStyleName());
+assertEquals(mySecondStyleName, css.mySecondStyleName());
+  }
+}


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


[gwt-contrib] Re: Add a FakeCssMaker for CSS resources similar to FakeMessagesMaker. (issue1604804)

2011-11-30 Thread jasonmheim

On 2011/11/30 20:26:19, jat wrote:

http://gwt-code-reviews.appspot.com/1604804/diff/1/user/src/com/google/gwt/junit/FakeCssMaker.java

File user/src/com/google/gwt/junit/FakeCssMaker.java (right):



http://gwt-code-reviews.appspot.com/1604804/diff/1/user/src/com/google/gwt/junit/FakeCssMaker.java#newcode44

user/src/com/google/gwt/junit/FakeCssMaker.java:44:
FakeCssMaker.class.getClassLoader(), new Class[] {cssClass},
Is this the right classloader to use?  FakeCssMaker is part of GWT,

while

cssClass will typically be a user class.



I suggest using the thread context classloader instead.


Interesting comment. Under what circumstances would they be in different
classloaders? The JUnit testing environment for which this class is
intended shouldn't have multiple classloaders. Then again, if that
somehow occurred then I would think that the right classloader would be
that of 'cssClass', so maybe it's worth revisiting.

For what it's worth, this is the same technique that FakeMessagesMaker
uses without issue. I submitted the change prior to seeing your comment,
but I'm happy to make the change to both this and FakeMessagesMaker if
you think it has value.


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

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


[gwt-contrib] Re: Add a FakeCssMaker for CSS resources similar to FakeMessagesMaker. (issue1604804)

2011-11-30 Thread jasonmheim

On 2011/11/30 21:05:17, jat wrote:

Right now, it won't make much difference as GWT gets user classes from

the same

classpath that GWT classes are loaded from.  However, that leads to

conflict for

shared code where you want to use a different version of something

than the

version GWT itself needs to run.  So, in the future we may provide a

way to give

separate classpaths.



I think of the following guidelines for choosing which classloader to

use:

  - if a class being loaded is bundled with some other class (ie, known

to be

from the same jar), use that class's classloader to load it.
  - if you want to load a system class and definitely don't want it to

be

overridden, use the system classloader
  - otherwise, use the thread context classloader.



Since you have already submitted it and this will generally be used

only in

tests, this is just FYI and you don't need to update it.


Thanks for the extra info, I agree with your assessment.

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

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