Home | History | Annotate | Download | only in fragment
      1 /*
      2  * Copyright 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of 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,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package androidx.navigation.fragment;
     18 
     19 import static org.hamcrest.CoreMatchers.is;
     20 import static org.hamcrest.MatcherAssert.assertThat;
     21 
     22 import android.app.Instrumentation;
     23 import android.content.Intent;
     24 import android.support.test.InstrumentationRegistry;
     25 import android.support.test.filters.SmallTest;
     26 import android.support.test.rule.ActivityTestRule;
     27 
     28 import androidx.navigation.NavController;
     29 import androidx.navigation.fragment.test.ImmediateNavigationActivity;
     30 import androidx.navigation.fragment.test.R;
     31 
     32 import org.junit.Rule;
     33 import org.junit.Test;
     34 
     35 @SmallTest
     36 public class ImmediateNavigationTest {
     37 
     38     @Rule
     39     public ActivityTestRule<ImmediateNavigationActivity> mActivityRule =
     40             new ActivityTestRule<>(ImmediateNavigationActivity.class, false, false);
     41 
     42     @Test
     43     public void testNavigateInOnResume() throws Throwable {
     44         Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
     45         Intent intent = new Intent(instrumentation.getContext(),
     46                 ImmediateNavigationActivity.class);
     47 
     48         final ImmediateNavigationActivity activity = mActivityRule.launchActivity(intent);
     49         instrumentation.waitForIdleSync();
     50         NavController navController = activity.getNavController();
     51         assertThat(navController.getCurrentDestination().getId(), is(R.id.deep_link_test));
     52     }
     53 }
     54