aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test
diff options
context:
space:
mode:
authorOlli Tietäväinen <ollit@vaadin.com>2019-02-22 10:50:51 +0200
committerSun Zhe <31067185+ZheSun88@users.noreply.github.com>2019-02-22 10:50:51 +0200
commit9d5bdaf89bd173bec7364d591377ca17bb5bb91d (patch)
treecaa481e8d5f29f24be6f11ffd1cac4dfe7f9d887 /server/src/test
parentc79dca4391bff459f090102447c5502089bf9fc7 (diff)
downloadvaadin-framework-9d5bdaf89bd173bec7364d591377ca17bb5bb91d.tar.gz
vaadin-framework-9d5bdaf89bd173bec7364d591377ca17bb5bb91d.zip
Custom serializers accessors (#10658)
* add accessor methods for CUSTOM_SERIALIZERS in JsonCodec * javadoc * removed removeCustomSerializer method, renamed putCustomSerializer to addCustomSerializer, added sanity checks and JavaDocs * refactored addCustomJsonSerializer to set, added test UI * move enums to be parsed after custom serializers * move adding custom serializer to static block * throw an exception if multiple serializers are registered for class * updated javadocs * changed CustomJSONSerializerTest to a SingleBrowserTest * moved CustomJSONSerializerTest to server/ and it's now not a browser test * removed CustomJSONSerializerTest
Diffstat (limited to 'server/src/test')
-rw-r--r--server/src/test/java/com/vaadin/server/CustomJSONSerializerTest.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/server/src/test/java/com/vaadin/server/CustomJSONSerializerTest.java b/server/src/test/java/com/vaadin/server/CustomJSONSerializerTest.java
new file mode 100644
index 0000000000..0c8b69fe62
--- /dev/null
+++ b/server/src/test/java/com/vaadin/server/CustomJSONSerializerTest.java
@@ -0,0 +1,52 @@
+package com.vaadin.server;
+
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Type;
+
+import org.junit.Test;
+
+import com.vaadin.server.communication.JSONSerializer;
+import com.vaadin.ui.ConnectorTracker;
+
+import elemental.json.JsonValue;
+
+public class CustomJSONSerializerTest {
+
+ public static class Foo {
+
+ }
+
+ public static class FooSerializer implements JSONSerializer<Foo> {
+
+ @Override
+ public Foo deserialize(Type type, JsonValue jsonValue,
+ ConnectorTracker connectorTracker) {
+ return null;
+ }
+
+ @Override
+ public JsonValue serialize(Foo value,
+ ConnectorTracker connectorTracker) {
+ return null;
+ }
+
+ }
+
+ @Test
+ public void testMultipleRegistration() {
+ boolean thrown = false;
+ try {
+ JsonCodec.setCustomSerializer(Foo.class, new FooSerializer());
+ JsonCodec.setCustomSerializer(Foo.class, new FooSerializer());
+ } catch (IllegalStateException ise) {
+ thrown = true;
+ } finally {
+ JsonCodec.setCustomSerializer(Foo.class, null);
+ }
+ assertTrue("Multiple serializer registrations for one class "
+ + "should throw an IllegalStateException", thrown);
+
+ }
+
+}