Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java

Issue 29348972: Issue 4239 - Change indentation to reflect our coding style (Closed)
Patch Set: Created Aug. 2, 2016, 10:43 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java
index 3dc07e349fae59af53923ed7f500fdb74098818e..a8402bc5ac6ae07e1fc5bd7f9ae0feed54501fa5 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java
@@ -31,136 +31,138 @@ import org.junit.Test;
import java.util.List;
-public class NotificationTest extends BaseJsTest {
+public class NotificationTest extends BaseJsTest
+{
- protected FilterEngine filterEngine;
+ protected FilterEngine filterEngine;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
- jsEngine.setWebRequest(new LazyWebRequest());
- filterEngine = new FilterEngine(jsEngine);
- }
+ jsEngine.setWebRequest(new LazyWebRequest());
+ filterEngine = new FilterEngine(jsEngine);
+ }
- protected void addNotification(String notification)
- {
- jsEngine.evaluate(
- "(function()\n" +
- "{\n" +
- "require('notification').Notification.addNotification(" + notification + ");\n" +
- "})();");
- }
+ protected void addNotification(String notification)
+ {
+ jsEngine.evaluate(
+ "(function()\n" +
+ "{\n" +
+ "require('notification').Notification.addNotification(" + notification + ");\n" +
+ "})();");
+ }
- private static final String TAG = "notification";
+ private static final String TAG = "notification";
- private class LocalShowNotificationCallback extends ShowNotificationCallback
- {
- private Notification retValue;
-
- public Notification getRetValue()
- {
- return retValue;
- }
-
- @Override
- public void showNotificationCallback(Notification notification)
- {
- Log.d(TAG, this + " received [" + notification + "]");
- retValue = notification;
- }
- }
+ private class LocalShowNotificationCallback extends ShowNotificationCallback
+ {
+ private Notification retValue;
- protected Notification peekNotification(String url) throws InterruptedException
+ public Notification getRetValue()
{
- Log.d(TAG, "Start peek");
-
- LocalShowNotificationCallback callback = new LocalShowNotificationCallback();
- Log.d(TAG, "set callback " + callback);
- filterEngine.setShowNotificationCallback(callback);
- filterEngine.showNextNotification(url);
- filterEngine.removeShowNotificationCallback();
- Log.d(TAG, "removed callback");
- return callback.getRetValue();
+ return retValue;
}
- private class MockWebRequest extends WebRequest
- {
- private String responseText;
-
- public MockWebRequest(String responseText)
- {
- this.responseText = responseText;
- }
-
- @Override
- public ServerResponse httpGET(String url, List<HeaderEntry> headers)
- {
- if (url.indexOf("/notification.json") < 0)
- return new ServerResponse();
-
- ServerResponse response = new ServerResponse();
- response.setStatus(ServerResponse.NsStatus.OK);
- response.setResponseStatus(200);
- response.setResponse(responseText);
- return response;
- }
- }
-
- @Test
- public void testNoNotifications() throws InterruptedException
- {
- assertNull(peekNotification(""));
- }
-
- @Test
- public void testAddNotification() throws InterruptedException
+ @Override
+ public void showNotificationCallback(Notification notification)
{
- addNotification(
- "{\n" +
- " type: 'critical',\n" +
- " title: 'testTitle',\n" +
- " message: 'testMessage',\n" +
- "}");
- Notification notification = peekNotification("");
- assertNotNull(notification);
- assertEquals(Notification.Type.CRITICAL, notification.getType());
- assertEquals("testTitle", notification.getTitle());
- assertEquals("testMessage", notification.getMessageString());
+ Log.d(TAG, this + " received [" + notification + "]");
+ retValue = notification;
}
-
- @Test
- public void testFilterByUrl() throws InterruptedException
+ }
+
+ protected Notification peekNotification(String url) throws InterruptedException
+ {
+ Log.d(TAG, "Start peek");
+
+ LocalShowNotificationCallback callback = new LocalShowNotificationCallback();
+ Log.d(TAG, "set callback " + callback);
+ filterEngine.setShowNotificationCallback(callback);
+ filterEngine.showNextNotification(url);
+ filterEngine.removeShowNotificationCallback();
+ Log.d(TAG, "removed callback");
+ return callback.getRetValue();
+ }
+
+ private class MockWebRequest extends WebRequest
+ {
+ private String responseText;
+
+ public MockWebRequest(String responseText)
{
- addNotification("{ id:'no-filter', type:'critical' }");
- addNotification("{ id:'www.com', type:'information', urlFilters:['||www.com$document'] }");
- addNotification("{ id:'www.de', type:'question', urlFilters:['||www.de$document'] }");
-
- Notification notification = peekNotification("");
- assertNotNull(notification);
- assertEquals(Notification.Type.CRITICAL, notification.getType());
-
- notification = peekNotification("http://www.de");
- assertNotNull(notification);
- assertEquals(Notification.Type.QUESTION, notification.getType());
-
- notification = peekNotification("http://www.com");
- assertNotNull(notification);
- assertEquals(Notification.Type.INFORMATION, notification.getType());
+ this.responseText = responseText;
}
- @Test
- public void testMarkAsShown() throws InterruptedException
+ @Override
+ public ServerResponse httpGET(String url, List<HeaderEntry> headers)
{
- addNotification("{ type: 'question' }");
- assertNotNull(peekNotification(""));
-
- Notification notification = peekNotification("");
- assertNotNull(notification);
-
- Thread.sleep(1000);
- notification.markAsShown();
-
- assertNull(peekNotification(""));
+ if (url.indexOf("/notification.json") < 0)
+ return new ServerResponse();
+
+ ServerResponse response = new ServerResponse();
+ response.setStatus(ServerResponse.NsStatus.OK);
+ response.setResponseStatus(200);
+ response.setResponse(responseText);
+ return response;
}
+ }
+
+ @Test
+ public void testNoNotifications() throws InterruptedException
+ {
+ assertNull(peekNotification(""));
+ }
+
+ @Test
+ public void testAddNotification() throws InterruptedException
+ {
+ addNotification(
+ "{\n" +
+ " type: 'critical',\n" +
+ " title: 'testTitle',\n" +
+ " message: 'testMessage',\n" +
+ "}");
+ Notification notification = peekNotification("");
+ assertNotNull(notification);
+ assertEquals(Notification.Type.CRITICAL, notification.getType());
+ assertEquals("testTitle", notification.getTitle());
+ assertEquals("testMessage", notification.getMessageString());
+ }
+
+ @Test
+ public void testFilterByUrl() throws InterruptedException
+ {
+ addNotification("{ id:'no-filter', type:'critical' }");
+ addNotification("{ id:'www.com', type:'information', urlFilters:['||www.com$document'] }");
+ addNotification("{ id:'www.de', type:'question', urlFilters:['||www.de$document'] }");
+
+ Notification notification = peekNotification("");
+ assertNotNull(notification);
+ assertEquals(Notification.Type.CRITICAL, notification.getType());
+
+ notification = peekNotification("http://www.de");
+ assertNotNull(notification);
+ assertEquals(Notification.Type.QUESTION, notification.getType());
+
+ notification = peekNotification("http://www.com");
+ assertNotNull(notification);
+ assertEquals(Notification.Type.INFORMATION, notification.getType());
+ }
+
+ @Test
+ public void testMarkAsShown() throws InterruptedException
+ {
+ addNotification("{ type: 'question' }");
+ assertNotNull(peekNotification(""));
+
+ Notification notification = peekNotification("");
+ assertNotNull(notification);
+
+ Thread.sleep(1000);
+ notification.markAsShown();
+
+ assertNull(peekNotification(""));
+ }
}

Powered by Google App Engine
This is Rietveld