From aa3c1a06ed46f49b617e2956b6cf9a1b0d367fb0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 22 Nov 2016 17:49:03 +0300 Subject: add APNS feedback component --- .../juick/components/test/NotificationTests.java | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java (limited to 'juick-notifications/src/test') 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 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"); + } + })); + } +} -- cgit v1.2.3