|
| 1 | +/** |
| 2 | + * Copyright (C) 2010-2016 eBusiness Information, Excilys Group |
| 3 | + * Copyright (C) 2016-2019 the AndroidAnnotations project |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 | + * use this file except in compliance with the License. You may obtain a copy of |
| 7 | + * the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed To in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | + * License for the specific language governing permissions and limitations under |
| 15 | + * the License. |
| 16 | + */ |
| 17 | +package org.androidannotations.test.rootfragment; |
| 18 | + |
| 19 | +import static org.fest.assertions.api.Assertions.assertThat; |
| 20 | + |
| 21 | +import org.junit.Test; |
| 22 | +import org.junit.runner.RunWith; |
| 23 | +import org.robolectric.Robolectric; |
| 24 | +import org.robolectric.RobolectricTestRunner; |
| 25 | + |
| 26 | +@RunWith(RobolectricTestRunner.class) |
| 27 | +public class RootFragmentTest { |
| 28 | + |
| 29 | + @Test |
| 30 | + public void injectFragmentWhichInjectedBean() { |
| 31 | + CustomFragment fragment = new CustomFragment_(); |
| 32 | + |
| 33 | + fragment.onCreate(null); |
| 34 | + |
| 35 | + assertThat(fragment.someBean.fragment).isEqualTo(fragment); |
| 36 | + assertThat(fragment.someBean.fragmentByMethod).isEqualTo(fragment); |
| 37 | + assertThat(fragment.someBean.fragmentByParam1).isEqualTo(fragment); |
| 38 | + assertThat(fragment.someBean.fragmentByParam2).isEqualTo(fragment); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void injectSomeFragmentWhichInjectedBean() { |
| 43 | + CustomFragment fragment = new CustomFragment_(); |
| 44 | + |
| 45 | + fragment.onCreate(null); |
| 46 | + |
| 47 | + assertThat(fragment.someBeanWithCustomFragment.fragment).isEqualTo(fragment); |
| 48 | + assertThat(fragment.someBeanWithCustomFragment.fragmentByMethod).isEqualTo(fragment); |
| 49 | + assertThat(fragment.someBeanWithCustomFragment.fragmentByParam1).isEqualTo(fragment); |
| 50 | + assertThat(fragment.someBeanWithCustomFragment.fragmentByParam2).isEqualTo(fragment); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void nothingInjectedIfDifferentFragmentThanInjectingFragmentIsUsedOnBean() { |
| 55 | + CustomFragment fragment = new CustomFragment_(); |
| 56 | + |
| 57 | + fragment.onCreate(null); |
| 58 | + |
| 59 | + assertThat(fragment.someBeanWithDifferentFragment.fragment).isNull(); |
| 60 | + assertThat(fragment.someBeanWithDifferentFragment.fragmentByMethod).isNull(); |
| 61 | + assertThat(fragment.someBeanWithDifferentFragment.fragmentByParam1).isNull(); |
| 62 | + assertThat(fragment.someBeanWithDifferentFragment.fragmentByParam2).isNull(); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void nothingInjectedIfActivityInjectedBean() { |
| 67 | + ActivityWithBeansWithRootFragment_ activity = Robolectric.setupActivity(ActivityWithBeansWithRootFragment_.class); |
| 68 | + |
| 69 | + assertThat(activity.someBean.fragment).isNull(); |
| 70 | + assertThat(activity.someBean.fragmentByMethod).isNull(); |
| 71 | + assertThat(activity.someBean.fragmentByParam1).isNull(); |
| 72 | + assertThat(activity.someBean.fragmentByParam2).isNull(); |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments