diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2015-02-17 10:20:41 +0200 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2015-02-17 10:20:41 +0200 |
commit | a6d629529d79def3f1f211168433c3f7553256ad (patch) | |
tree | 7991cd443a50e9559fe8ad922e31c1af046866bf /server/tests/src/com/vaadin | |
parent | c417195029fe79dd6c60413f998731877c534d51 (diff) | |
download | vaadin-framework-a6d629529d79def3f1f211168433c3f7553256ad.tar.gz vaadin-framework-a6d629529d79def3f1f211168433c3f7553256ad.zip |
Refactor critical notifications handling. (#16592)
Change-Id: I235804a80b1d70a564a54953b9255416a7386fe6
Diffstat (limited to 'server/tests/src/com/vaadin')
-rw-r--r-- | server/tests/src/com/vaadin/server/VaadinServiceTest.java | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/server/tests/src/com/vaadin/server/VaadinServiceTest.java b/server/tests/src/com/vaadin/server/VaadinServiceTest.java index c2ca8b0e57..4b655e7855 100644 --- a/server/tests/src/com/vaadin/server/VaadinServiceTest.java +++ b/server/tests/src/com/vaadin/server/VaadinServiceTest.java @@ -15,6 +15,9 @@ */ package com.vaadin.server; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; + import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpSessionBindingEvent; @@ -39,6 +42,11 @@ public class VaadinServiceTest { } } + private String createCriticalNotification(String caption, String message, String details, String url) { + return VaadinService + .createCriticalNotificationJSON(caption, message, details, url); + } + @Test public void testFireSessionDestroy() throws ServletException { ServletConfig servletConfig = new MockServletConfig(); @@ -68,16 +76,66 @@ public class VaadinServiceTest { } @Test - public void testCriticalNotificationNullHandling() { - for (String caption : new String[] { "some caption", null }) { - for (String message : new String[] { "some message", null }) { - for (String details : new String[] { "some details", null }) { - for (String url : new String[] { "some url", null }) { - VaadinService.createCriticalNotificationJSON(caption, - message, details, url); - } - } - } - } + public void captionIsSetToACriticalNotification() { + String notification = + createCriticalNotification("foobar", "message", "details", "url"); + + assertThat(notification, containsString("\"caption\":\"foobar\"")); + } + + @Test + public void nullCaptionIsSetToACriticalNotification() { + String notification = + createCriticalNotification(null, "message", "details", "url"); + + assertThat(notification, containsString("\"caption\":null")); + } + + @Test + public void messageWithDetailsIsSetToACriticalNotification() { + String notification = + createCriticalNotification("caption", "foo", "bar", "url"); + + assertThat(notification, containsString("\"message\":\"foo<br/><br/>bar\"")); + } + + @Test + public void nullMessageIsReplacedByDetailsInACriticalNotification() { + String notification = + createCriticalNotification("caption", null, "foobar", "url"); + + assertThat(notification, containsString("\"message\":\"foobar\"")); + } + + @Test + public void nullMessageIsSetToACriticalNotification() { + String notification = + createCriticalNotification("caption", null, null, "url"); + + assertThat(notification, containsString("\"message\":null")); + } + + @Test + public void messageSetToACriticalNotification() { + String notification = + createCriticalNotification("caption", "foobar", null, "url"); + + assertThat(notification, containsString("\"message\":\"foobar\"")); + } + + @Test + public void urlIsSetToACriticalNotification() { + String notification = + createCriticalNotification("caption", "message", "details", "foobar"); + + assertThat(notification, containsString("\"url\":\"foobar\"")); + } + + @Test + public void nullUrlIsSetToACriticalNotification() { + String notification = + createCriticalNotification("caption", "message", "details", null); + + assertThat(notification, containsString("\"url\":null")); } } |