aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-notifications/src/test/java')
-rw-r--r--juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java69
1 files changed, 69 insertions, 0 deletions
diff --git a/juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java b/juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java
new file mode 100644
index 00000000..c4a4ed24
--- /dev/null
+++ b/juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java
@@ -0,0 +1,69 @@
+package com.juick.components.test;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.Appender;
+import com.juick.components.CleanUp;
+import com.notnoop.apns.ApnsService;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by vitalyster on 22.11.2016.
+ */
+public class NotificationTests {
+ @InjectMocks
+ CleanUp cleanUp;
+
+ @Mock
+ ApnsService service;
+ @Mock
+ RestTemplate rest;
+
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void CleanUpTest() {
+ Map<String, Date> inactiveDevices = new HashMap<>();
+ inactiveDevices.put("yoyoyo", new Date());
+ when(service.getInactiveDevices()).thenReturn(inactiveDevices);
+ ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ final Appender mockAppender = mock(Appender.class);
+ when(mockAppender.getName()).thenReturn("MOCK");
+ root.addAppender(mockAppender);
+ cleanUp.cleanupTokens();
+ verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
+ @Override
+ public boolean matches(final Object argument) {
+ return ((LoggingEvent)argument).getFormattedMessage().contains("1 tokens to delete");
+ }
+ }));
+ when(service.getInactiveDevices()).thenReturn(new HashMap<>());
+ cleanUp.cleanupTokens();
+ verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
+ @Override
+ public boolean matches(final Object argument) {
+ return ((LoggingEvent)argument).getFormattedMessage().contains("No APNS tokens to delete");
+ }
+ }));
+ }
+}