aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/GCMIntentServiceTest.java
blob: ae2dd501f013cfef74108b17758541e7523a3379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.wordpress.android.ui.notifications;

import android.content.Context;
import android.os.Bundle;
import android.test.RenamingDelegatingContext;
import android.test.ServiceTestCase;

import org.wordpress.android.FactoryUtils;
import org.wordpress.android.GCMMessageService;
import org.wordpress.android.TestUtils;
import org.wordpress.android.models.AccountHelper;

public class GCMIntentServiceTest extends ServiceTestCase<GCMMessageService> {
    protected Context mTargetContext;

    public GCMIntentServiceTest() {
        super(GCMMessageService.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        FactoryUtils.initWithTestFactories();

        mTargetContext = new RenamingDelegatingContext(getContext(), "test_");
        TestUtils.clearApplicationState(mTargetContext);

        setupService();
    }

    @Override
    protected void tearDown() throws Exception {
        FactoryUtils.clearFactories();
        super.tearDown();
    }

    public void testShouldCircularizeNoteIcon() {
        GCMMessageService intentService = new GCMMessageService();

        String type = "c";
        assertTrue(intentService.shouldCircularizeNoteIcon(type));

        assertFalse(intentService.shouldCircularizeNoteIcon(null));

        type = "invalidType";
        assertFalse(intentService.shouldCircularizeNoteIcon(type));
    }

    public void testOnMessageReceived() throws InterruptedException {
        org.wordpress.android.models.Account account = AccountHelper.getDefaultAccount();
        account.setAccessToken("secret token");
        account.setUserId(1);
        final Bundle bundle = new Bundle();
        bundle.putString("user", "1");
        for (int i = 0; i < 1000; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    getService().onMessageReceived("from", bundle);
                }
            }).start();
        }

        Thread.sleep(10000);
    }
}