diff options
author | Vitaly Takmazov | 2016-11-22 17:49:03 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-22 17:49:03 +0300 |
commit | aa3c1a06ed46f49b617e2956b6cf9a1b0d367fb0 (patch) | |
tree | 722163db0e9b060a5c4f7902fd422c0c2b13032e /juick-notifications/src/test/java/com/juick/components | |
parent | 8b267a3b630f5843623801f42eb90d0ad6a9d849 (diff) |
add APNS feedback component
Diffstat (limited to 'juick-notifications/src/test/java/com/juick/components')
-rw-r--r-- | juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java | 69 |
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"); + } + })); + } +} |