|
| 1 | +/** |
| 2 | + * Copyright (C) 2010-2016 eBusiness Information, Excilys Group |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed To in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | +package org.androidannotations.test.receiver; |
| 17 | + |
| 18 | +import static org.junit.Assert.assertTrue; |
| 19 | + |
| 20 | +import org.junit.Before; |
| 21 | +import org.junit.Test; |
| 22 | +import org.junit.runner.RunWith; |
| 23 | +import org.robolectric.Robolectric; |
| 24 | +import org.robolectric.RobolectricTestRunner; |
| 25 | + |
| 26 | +import android.content.Intent; |
| 27 | +import android.support.v4.content.LocalBroadcastManager; |
| 28 | + |
| 29 | +@RunWith(RobolectricTestRunner.class) |
| 30 | +public class EViewAndEViewGroupWithReceiverTest { |
| 31 | + |
| 32 | + private EViewAndEViewGroupWithReceiverActivity_ activity; |
| 33 | + |
| 34 | + @Before |
| 35 | + public void setUp() { |
| 36 | + activity = Robolectric.setupActivity(EViewAndEViewGroupWithReceiverActivity_.class); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void eViewAndEViewGroupReceivedAction0Test() { |
| 41 | + Intent intent = new Intent(ReceiverActions.ACTION_0); |
| 42 | + activity.sendBroadcast(intent); |
| 43 | + |
| 44 | + assertTrue(activity.viewWithReceiver.action0Received); |
| 45 | + assertTrue(activity.viewGroupWithReceiver.action0Received); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void eViewAndEViewGroupReceivedAction1WithExtraTest() { |
| 50 | + String extraContent = "extraContent"; |
| 51 | + Intent intent = new Intent(ReceiverActions.ACTION_1); |
| 52 | + intent.putExtra("extra", extraContent); |
| 53 | + activity.sendBroadcast(intent); |
| 54 | + |
| 55 | + assertTrue(activity.viewWithReceiver.action1Received); |
| 56 | + assertTrue(activity.viewWithReceiver.action1Extra.equals(extraContent)); |
| 57 | + assertTrue(activity.viewGroupWithReceiver.action1Received); |
| 58 | + assertTrue(activity.viewGroupWithReceiver.action1Extra.equals(extraContent)); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void eViewAndEViewGroupReceivedAction2WithExtraTest() { |
| 63 | + Intent intent = new Intent(ReceiverActions.ACTION_2); |
| 64 | + Intent extraIntent = new Intent("someAction"); |
| 65 | + intent.putExtra("extra", extraIntent); |
| 66 | + |
| 67 | + LocalBroadcastManager.getInstance(Robolectric.application).sendBroadcast(intent); |
| 68 | + |
| 69 | + assertTrue(activity.viewWithReceiver.action2Received); |
| 70 | + assertTrue(activity.viewWithReceiver.action2Extra.equals(extraIntent)); |
| 71 | + assertTrue(activity.viewGroupWithReceiver.action2Received); |
| 72 | + assertTrue(activity.viewGroupWithReceiver.action2Extra.equals(extraIntent)); |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments