FRANotificationGatewayTests.m revision 6c1420dd55f69d09f39dd213ee6c97ba901b8d92
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan/*
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * The contents of this file are subject to the terms of the Common Development and
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * Distribution License (the License). You may not use this file except in compliance with the
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * License.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan *
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * specific language governing permission and limitations under the License.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan *
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * When distributing Covered Software, include this CDDL Header Notice in each file and include
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * Header, with the fields enclosed by brackets [] replaced by your own identifying
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * information: "Portions copyright [year] [name of copyright owner]".
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan *
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan * Copyright 2016 ForgeRock AS.
dc53767f6614db736c8a95a165beae870ac1e3d9Jake Feasel */
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan
4eb529f0471672590d77cf89ef23987ba2c95ff4Laszlo Hordos#import <OCMock/OCMock.h>
4eb529f0471672590d77cf89ef23987ba2c95ff4Laszlo Hordos#import <UIKit/UIKit.h>
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#import <XCTest/XCTest.h>
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#import "FRANotificationGateway.h"
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#import "FRANotificationHandler.h"
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan@interface FRANotificationGatewayTests : XCTestCase
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan
7c64421614d420f1951773af3ce6a6111cef84b2Jake Feasel@end
7c64421614d420f1951773af3ce6a6111cef84b2Jake Feasel
7c64421614d420f1951773af3ce6a6111cef84b2Jake Feasel@implementation FRANotificationGatewayTests
7c64421614d420f1951773af3ce6a6111cef84b2Jake Feasel
b564baaca75789be41eba24bb96e31f3ce5b10eeJake FeaselFRANotificationGateway *notificationGateway;
5d0f143a8ead3cd79919f648b4a899e348902143Jake FeaselFRANotificationHandler *mockNotificationHandler;
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake FeaselUIApplication *mockApplication;
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel- (void)setUp {
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel [super setUp];
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel mockApplication = OCMClassMock([UIApplication class]);
596fa6db662266170abd38371893c621541d1881Jake Feasel mockNotificationHandler = OCMClassMock([FRANotificationHandler class]);
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan notificationGateway = [FRANotificationGateway gatewayWithHandler:mockNotificationHandler];
54f30b716553d88ea9ebb010037f4c74eb1d69acPaul Bryan}
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos- (void)tearDown {
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos [super tearDown];
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos}
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos- (void)testPropagatesPushNotificationsToRegisteredHandler {
0389b442e8bd8d112b977faae238cc8bb66201e2Bruno Lavit // Given
0389b442e8bd8d112b977faae238cc8bb66201e2Bruno Lavit NSDictionary *notification = @{};
f1aa66113fa700d874f2c4c38e87c6ce44dae232Bruno Lavit
f1aa66113fa700d874f2c4c38e87c6ce44dae232Bruno Lavit // When
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel [notificationGateway application:mockApplication didReceiveRemoteNotification:notification];
596fa6db662266170abd38371893c621541d1881Jake Feasel
596fa6db662266170abd38371893c621541d1881Jake Feasel // Then
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel OCMVerify([mockNotificationHandler handleRemoteNotification:notification]);
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel}
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel- (void)testBackgroundPropagatesPushNotificationsToRegisteredHandler {
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel // Given
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel NSDictionary *notification = @{};
3f09f5b4acc8cefb61799cd3bb7b34dea90d1958Jake Feasel // When
dc53767f6614db736c8a95a165beae870ac1e3d9Jake Feasel [notificationGateway application:mockApplication
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos didReceiveRemoteNotification:notification
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos fetchCompletionHandler:^(UIBackgroundFetchResult result){}];
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos // Then
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos OCMVerify([mockNotificationHandler handleRemoteNotification:notification]);
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos}
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos@end
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos