1 package org.robolectric.shadows; 2 3 import static com.google.common.truth.Truth.assertThat; 4 5 import android.net.Uri; 6 import androidx.test.ext.junit.runners.AndroidJUnit4; 7 import org.junit.Test; 8 import org.junit.runner.RunWith; 9 10 @RunWith(AndroidJUnit4.class) 11 public class ShadowUriTest { 12 @Test shouldParseUris()13 public void shouldParseUris() throws Exception { 14 Uri testUri = Uri.parse("http://someplace.com:8080/a/path?param=value&another_param=another_value#top"); 15 16 assertThat(testUri.getQuery()).isEqualTo("param=value&another_param=another_value"); 17 assertThat(testUri.getPort()).isEqualTo(8080); 18 assertThat(testUri.getAuthority()).isEqualTo("someplace.com:8080"); 19 assertThat(testUri.getHost()).isEqualTo("someplace.com"); 20 assertThat(testUri.getFragment()).isEqualTo("top"); 21 assertThat(testUri.getPath()).isEqualTo("/a/path"); 22 assertThat(testUri.getScheme()).isEqualTo("http"); 23 } 24 getQueryParameter_shouldWork()25 @Test public void getQueryParameter_shouldWork() throws Exception { 26 Uri testUri = Uri.parse("http://someplace.com:8080/a/path?param=value&another_param=another_value#top"); 27 assertThat(testUri.getQueryParameter("param")).isEqualTo("value"); 28 } 29 } 30