|
30 | 30 | import io.grpc.NameResolver.ServiceConfigParser; |
31 | 31 | import io.grpc.NameResolverProvider; |
32 | 32 | import io.grpc.SynchronizationContext; |
| 33 | +import io.grpc.Uri; |
33 | 34 | import io.grpc.binder.ApiConstants; |
34 | 35 | import java.net.URI; |
35 | 36 | import org.junit.Before; |
@@ -70,18 +71,32 @@ public void testProviderScheme_returnsIntentScheme() throws Exception { |
70 | 71 |
|
71 | 72 | @Test |
72 | 73 | public void testNoResolverForUnknownScheme_returnsNull() throws Exception { |
73 | | - assertThat(provider.newNameResolver(new URI("random://uri"), args)).isNull(); |
| 74 | + assertThat(provider.newNameResolver(Uri.create("random://uri"), args)).isNull(); |
74 | 75 | } |
75 | 76 |
|
76 | 77 | @Test |
77 | 78 | public void testResolutionWithBadUri_throwsIllegalArg() throws Exception { |
78 | 79 | assertThrows( |
79 | 80 | IllegalArgumentException.class, |
80 | | - () -> provider.newNameResolver(new URI("intent:xxx#Intent;e.x=1;end;"), args)); |
| 81 | + () -> provider.newNameResolver(Uri.create("intent:xxx#Intent;e.x=1;end;"), args)); |
81 | 82 | } |
82 | 83 |
|
83 | 84 | @Test |
84 | 85 | public void testResolverForIntentScheme_returnsResolver() throws Exception { |
| 86 | + Uri uri = Uri.create("intent:#Intent;action=action;end"); |
| 87 | + NameResolver resolver = provider.newNameResolver(uri, args); |
| 88 | + assertThat(resolver).isNotNull(); |
| 89 | + assertThat(resolver.getServiceAuthority()).isEqualTo("localhost"); |
| 90 | + syncContext.execute(() -> resolver.start(mockListener)); |
| 91 | + shadowOf(getMainLooper()).idle(); |
| 92 | + verify(mockListener).onResult2(resultCaptor.capture()); |
| 93 | + assertThat(resultCaptor.getValue().getAddressesOrError()).isNotNull(); |
| 94 | + syncContext.execute(resolver::shutdown); |
| 95 | + shadowOf(getMainLooper()).idle(); |
| 96 | + } |
| 97 | + |
| 98 | + @Test |
| 99 | + public void testResolverForIntentScheme_returnsResolver_javaNetUri() throws Exception { |
85 | 100 | URI uri = new URI("intent://authority/path#Intent;action=action;scheme=scheme;end"); |
86 | 101 | NameResolver resolver = provider.newNameResolver(uri, args); |
87 | 102 | assertThat(resolver).isNotNull(); |
|
0 commit comments