Skip to content

Commit

Permalink
Update pinpoint notification test
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerjroach committed Jun 8, 2022
1 parent 302147f commit d0a74d6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
@@ -1,3 +1,18 @@
/**
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amazonaws.mobileconnectors.pinpoint.targeting.notification;

import android.content.BroadcastReceiver;
Expand Down
Expand Up @@ -2,43 +2,47 @@

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.android.controller.ActivityController;

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk=23)
public class PinpointNotificationReceiverTests {
public class PinpointNotificationActivityTests {

private NotificationClient notificationClient;

private PinpointNotificationReceiver receiver;

private Intent intent;

private Context context;
private ActivityController<PinpointNotificationActivity> activityController;

@Before
public void setup() {
PinpointNotificationActivity.setNotificationClient((NotificationClient) null);
notificationClient = Mockito.mock(NotificationClient.class);
intent = Mockito.mock(Intent.class);
receiver = new PinpointNotificationReceiver();
PinpointNotificationReceiver.setNotificationClient(notificationClient);
context = Mockito.mock(Context.class);
activityController = Robolectric.buildActivity(PinpointNotificationActivity.class);
PinpointNotificationActivity.setNotificationClient(notificationClient);
}

@After
public void tearDown() {
activityController.destroy();
PinpointNotificationActivity.setNotificationClient((NotificationClient) null);
}

@Test
public void testReferenceToNotificationClient() {
System.gc();
receiver.onReceive(context, intent);
verifyZeroInteractions(notificationClient);

activityController.create();

verify(notificationClient, times(1)).handleNotificationOpen(Mockito.anyMap(),
Mockito.any(Bundle.class));
}
Expand Down

0 comments on commit d0a74d6

Please sign in to comment.