本文整理汇总了Java中com.facebook.react.bridge.JavaOnlyMap.putString方法的典型用法代码示例。如果您正苦于以下问题:Java JavaOnlyMap.putString方法的具体用法?Java JavaOnlyMap.putString怎么用?Java JavaOnlyMap.putString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.react.bridge.JavaOnlyMap
的用法示例。
在下文中一共展示了JavaOnlyMap.putString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAllOptions
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testAllOptions() {
final JavaOnlyMap options = new JavaOnlyMap();
options.putString("title", "Title");
options.putString("message", "Message");
options.putString("buttonPositive", "OK");
options.putString("buttonNegative", "Cancel");
options.putString("buttonNeutral", "Later");
options.putBoolean("cancelable", false);
mDialogModule.showAlert(options, null, null);
final AlertFragment fragment = getFragment();
assertNotNull("Fragment was not displayed", fragment);
assertEquals(false, fragment.isCancelable());
final AlertDialog dialog = (AlertDialog) fragment.getDialog();
assertEquals("OK", dialog.getButton(DialogInterface.BUTTON_POSITIVE).getText().toString());
assertEquals("Cancel", dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getText().toString());
assertEquals("Later", dialog.getButton(DialogInterface.BUTTON_NEUTRAL).getText().toString());
}
示例2: testCallbackPositive
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testCallbackPositive() {
final JavaOnlyMap options = new JavaOnlyMap();
options.putString("buttonPositive", "OK");
final SimpleCallback actionCallback = new SimpleCallback();
mDialogModule.showAlert(options, null, actionCallback);
final AlertDialog dialog = (AlertDialog) getFragment().getDialog();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
assertEquals(1, actionCallback.getCalls());
assertEquals(DialogModule.ACTION_BUTTON_CLICKED, actionCallback.getArgs()[0]);
assertEquals(DialogInterface.BUTTON_POSITIVE, actionCallback.getArgs()[1]);
}
示例3: testCallbackNegative
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testCallbackNegative() {
final JavaOnlyMap options = new JavaOnlyMap();
options.putString("buttonNegative", "Cancel");
final SimpleCallback actionCallback = new SimpleCallback();
mDialogModule.showAlert(options, null, actionCallback);
final AlertDialog dialog = (AlertDialog) getFragment().getDialog();
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
assertEquals(1, actionCallback.getCalls());
assertEquals(DialogModule.ACTION_BUTTON_CLICKED, actionCallback.getArgs()[0]);
assertEquals(DialogInterface.BUTTON_NEGATIVE, actionCallback.getArgs()[1]);
}
示例4: testCallbackNeutral
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testCallbackNeutral() {
final JavaOnlyMap options = new JavaOnlyMap();
options.putString("buttonNeutral", "Later");
final SimpleCallback actionCallback = new SimpleCallback();
mDialogModule.showAlert(options, null, actionCallback);
final AlertDialog dialog = (AlertDialog) getFragment().getDialog();
dialog.getButton(DialogInterface.BUTTON_NEUTRAL).performClick();
assertEquals(1, actionCallback.getCalls());
assertEquals(DialogModule.ACTION_BUTTON_CLICKED, actionCallback.getArgs()[0]);
assertEquals(DialogInterface.BUTTON_NEUTRAL, actionCallback.getArgs()[1]);
}
示例5: testFailPostWithoutContentType
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testFailPostWithoutContentType() throws Exception {
RCTDeviceEventEmitter emitter = mock(RCTDeviceEventEmitter.class);
ReactApplicationContext context = mock(ReactApplicationContext.class);
when(context.getJSModule(any(ExecutorToken.class), any(Class.class))).thenReturn(emitter);
OkHttpClient httpClient = mock(OkHttpClient.class);
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
when(clientBuilder.build()).thenReturn(httpClient);
when(httpClient.newBuilder()).thenReturn(clientBuilder);
NetworkingModule networkingModule = new NetworkingModule(context, "", httpClient);
JavaOnlyMap body = new JavaOnlyMap();
body.putString("string", "This is request body");
mockEvents();
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://somedomain/bar",
0,
JavaOnlyArray.of(),
body,
/* responseType */ "text",
/* useIncrementalUpdates*/ true,
/* timeout */ 0,
/* withCredentials */ false);
verifyErrorEmit(emitter, 0);
}
示例6: testShareDialog
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testShareDialog() {
final String title = "Title";
final String message = "Message";
final String dialogTitle = "Dialog Title";
JavaOnlyMap content = new JavaOnlyMap();
content.putString("title", title);
content.putString("message", message);
final SimplePromise promise = new SimplePromise();
mShareModule.share(content, dialogTitle, promise);
final Intent chooserIntent =
((ShadowApplication)ShadowExtractor.extract(RuntimeEnvironment.application)).getNextStartedActivity();
assertNotNull("Dialog was not displayed", chooserIntent);
assertEquals(Intent.ACTION_CHOOSER, chooserIntent.getAction());
assertEquals(dialogTitle, chooserIntent.getExtras().get(Intent.EXTRA_TITLE));
final Intent contentIntent = (Intent)chooserIntent.getExtras().get(Intent.EXTRA_INTENT);
assertNotNull("Intent was not built correctly", contentIntent);
assertEquals(Intent.ACTION_SEND, contentIntent.getAction());
assertEquals(title, contentIntent.getExtras().get(Intent.EXTRA_SUBJECT));
assertEquals(message, contentIntent.getExtras().get(Intent.EXTRA_TEXT));
assertEquals(1, promise.getResolved());
}
示例7: testFailPostWithoutContentType
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testFailPostWithoutContentType() throws Exception {
RCTDeviceEventEmitter emitter = mock(RCTDeviceEventEmitter.class);
ReactApplicationContext context = mock(ReactApplicationContext.class);
when(context.getJSModule(any(ExecutorToken.class), any(Class.class))).thenReturn(emitter);
OkHttpClient httpClient = mock(OkHttpClient.class);
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
when(clientBuilder.build()).thenReturn(httpClient);
when(httpClient.newBuilder()).thenReturn(clientBuilder);
NetworkingModule networkingModule = new NetworkingModule(context, "", httpClient);
JavaOnlyMap body = new JavaOnlyMap();
body.putString("string", "This is request body");
mockEvents();
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://somedomain/bar",
0,
JavaOnlyArray.of(),
body,
/* responseType */ "text",
/* useIncrementalUpdates*/ true,
/* timeout */ 0);
verifyErrorEmit(emitter, 0);
}
示例8: testSuccessfulPostRequest
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testSuccessfulPostRequest() throws Exception {
OkHttpClient httpClient = mock(OkHttpClient.class);
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Call callMock = mock(Call.class);
return callMock;
}
});
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
when(clientBuilder.build()).thenReturn(httpClient);
when(httpClient.newBuilder()).thenReturn(clientBuilder);
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
JavaOnlyMap body = new JavaOnlyMap();
body.putString("string", "This is request body");
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://somedomain/bar",
0,
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "text/plain")),
body,
/* responseType */ "text",
/* useIncrementalUpdates*/ true,
/* timeout */ 0,
/* withCredentials */ false);
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
verify(httpClient).newCall(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().url().toString()).isEqualTo("http://somedomain/bar");
assertThat(argumentCaptor.getValue().headers().size()).isEqualTo(2);
assertThat(argumentCaptor.getValue().method()).isEqualTo("POST");
assertThat(argumentCaptor.getValue().body().contentType().type()).isEqualTo("text");
assertThat(argumentCaptor.getValue().body().contentType().subtype()).isEqualTo("plain");
Buffer contentBuffer = new Buffer();
argumentCaptor.getValue().body().writeTo(contentBuffer);
assertThat(contentBuffer.readUtf8()).isEqualTo("This is request body");
}
示例9: testMultipartPostRequestSimple
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testMultipartPostRequestSimple() throws Exception {
PowerMockito.mockStatic(RequestBodyUtil.class);
when(RequestBodyUtil.getFileInputStream(any(ReactContext.class), any(String.class)))
.thenReturn(mock(InputStream.class));
when(RequestBodyUtil.create(any(MediaType.class), any(InputStream.class)))
.thenReturn(mock(RequestBody.class));
when(RequestBodyUtil.createProgressRequest(any(RequestBody.class), any(ProgressListener.class)))
.thenCallRealMethod();
JavaOnlyMap body = new JavaOnlyMap();
JavaOnlyArray formData = new JavaOnlyArray();
JavaOnlyMap bodyPart = new JavaOnlyMap();
bodyPart.putString("string", "value");
bodyPart.putArray(
"headers",
JavaOnlyArray.from(
Arrays.asList(
JavaOnlyArray.of("content-disposition", "name"))));
formData.pushMap(bodyPart);
body.putArray("formData", formData);
OkHttpClient httpClient = mock(OkHttpClient.class);
when(httpClient.newCall(any(Request.class))).thenAnswer(
new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Call callMock = mock(Call.class);
return callMock;
}
});
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
when(clientBuilder.build()).thenReturn(httpClient);
when(httpClient.newBuilder()).thenReturn(clientBuilder);
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
new JavaOnlyArray(),
body,
/* responseType */ "text",
/* useIncrementalUpdates*/ true,
/* timeout */ 0,
/* withCredentials */ false);
// verify url, method, headers
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
verify(httpClient).newCall(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().url().toString()).isEqualTo("http://someurl/uploadFoo");
assertThat(argumentCaptor.getValue().method()).isEqualTo("POST");
assertThat(argumentCaptor.getValue().body().contentType().type()).
isEqualTo(MultipartBody.FORM.type());
assertThat(argumentCaptor.getValue().body().contentType().subtype()).
isEqualTo(MultipartBody.FORM.subtype());
Headers requestHeaders = argumentCaptor.getValue().headers();
assertThat(requestHeaders.size()).isEqualTo(1);
}
示例10: testMultipartPostRequestHeaders
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testMultipartPostRequestHeaders() throws Exception {
PowerMockito.mockStatic(RequestBodyUtil.class);
when(RequestBodyUtil.getFileInputStream(any(ReactContext.class), any(String.class)))
.thenReturn(mock(InputStream.class));
when(RequestBodyUtil.create(any(MediaType.class), any(InputStream.class)))
.thenReturn(mock(RequestBody.class));
when(RequestBodyUtil.createProgressRequest(any(RequestBody.class), any(ProgressListener.class)))
.thenCallRealMethod();
List<JavaOnlyArray> headers = Arrays.asList(
JavaOnlyArray.of("Accept", "text/plain"),
JavaOnlyArray.of("User-Agent", "React test agent/1.0"),
JavaOnlyArray.of("content-type", "multipart/form-data"));
JavaOnlyMap body = new JavaOnlyMap();
JavaOnlyArray formData = new JavaOnlyArray();
JavaOnlyMap bodyPart = new JavaOnlyMap();
bodyPart.putString("string", "value");
bodyPart.putArray(
"headers",
JavaOnlyArray.from(
Arrays.asList(
JavaOnlyArray.of("content-disposition", "name"))));
formData.pushMap(bodyPart);
body.putArray("formData", formData);
OkHttpClient httpClient = mock(OkHttpClient.class);
when(httpClient.newCall(any(Request.class))).thenAnswer(
new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Call callMock = mock(Call.class);
return callMock;
}
});
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
when(clientBuilder.build()).thenReturn(httpClient);
when(httpClient.newBuilder()).thenReturn(clientBuilder);
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
JavaOnlyArray.from(headers),
body,
/* responseType */ "text",
/* useIncrementalUpdates*/ true,
/* timeout */ 0,
/* withCredentials */ false);
// verify url, method, headers
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
verify(httpClient).newCall(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().url().toString()).isEqualTo("http://someurl/uploadFoo");
assertThat(argumentCaptor.getValue().method()).isEqualTo("POST");
assertThat(argumentCaptor.getValue().body().contentType().type()).
isEqualTo(MultipartBody.FORM.type());
assertThat(argumentCaptor.getValue().body().contentType().subtype()).
isEqualTo(MultipartBody.FORM.subtype());
Headers requestHeaders = argumentCaptor.getValue().headers();
assertThat(requestHeaders.size()).isEqualTo(3);
assertThat(requestHeaders.get("Accept")).isEqualTo("text/plain");
assertThat(requestHeaders.get("User-Agent")).isEqualTo("React test agent/1.0");
assertThat(requestHeaders.get("content-type")).isEqualTo("multipart/form-data");
}
示例11: testSuccessfulPostRequest
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testSuccessfulPostRequest() throws Exception {
OkHttpClient httpClient = mock(OkHttpClient.class);
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Call callMock = mock(Call.class);
return callMock;
}
});
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
when(clientBuilder.build()).thenReturn(httpClient);
when(httpClient.newBuilder()).thenReturn(clientBuilder);
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
JavaOnlyMap body = new JavaOnlyMap();
body.putString("string", "This is request body");
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://somedomain/bar",
0,
JavaOnlyArray.of(JavaOnlyArray.of("Content-Type", "text/plain")),
body,
/* responseType */ "text",
/* useIncrementalUpdates*/ true,
/* timeout */ 0);
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
verify(httpClient).newCall(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().url().toString()).isEqualTo("http://somedomain/bar");
assertThat(argumentCaptor.getValue().headers().size()).isEqualTo(2);
assertThat(argumentCaptor.getValue().method()).isEqualTo("POST");
assertThat(argumentCaptor.getValue().body().contentType().type()).isEqualTo("text");
assertThat(argumentCaptor.getValue().body().contentType().subtype()).isEqualTo("plain");
Buffer contentBuffer = new Buffer();
argumentCaptor.getValue().body().writeTo(contentBuffer);
assertThat(contentBuffer.readUtf8()).isEqualTo("This is request body");
}
示例12: testMultipartPostRequestSimple
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testMultipartPostRequestSimple() throws Exception {
PowerMockito.mockStatic(RequestBodyUtil.class);
when(RequestBodyUtil.getFileInputStream(any(ReactContext.class), any(String.class)))
.thenReturn(mock(InputStream.class));
when(RequestBodyUtil.create(any(MediaType.class), any(InputStream.class)))
.thenReturn(mock(RequestBody.class));
when(RequestBodyUtil.createProgressRequest(any(RequestBody.class), any(ProgressListener.class)))
.thenCallRealMethod();
JavaOnlyMap body = new JavaOnlyMap();
JavaOnlyArray formData = new JavaOnlyArray();
JavaOnlyMap bodyPart = new JavaOnlyMap();
bodyPart.putString("string", "value");
bodyPart.putArray(
"headers",
JavaOnlyArray.from(
Arrays.asList(
JavaOnlyArray.of("content-disposition", "name"))));
formData.pushMap(bodyPart);
body.putArray("formData", formData);
OkHttpClient httpClient = mock(OkHttpClient.class);
when(httpClient.newCall(any(Request.class))).thenAnswer(
new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Call callMock = mock(Call.class);
return callMock;
}
});
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
when(clientBuilder.build()).thenReturn(httpClient);
when(httpClient.newBuilder()).thenReturn(clientBuilder);
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
new JavaOnlyArray(),
body,
/* responseType */ "text",
/* useIncrementalUpdates*/ true,
/* timeout */ 0);
// verify url, method, headers
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
verify(httpClient).newCall(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().url().toString()).isEqualTo("http://someurl/uploadFoo");
assertThat(argumentCaptor.getValue().method()).isEqualTo("POST");
assertThat(argumentCaptor.getValue().body().contentType().type()).
isEqualTo(MultipartBody.FORM.type());
assertThat(argumentCaptor.getValue().body().contentType().subtype()).
isEqualTo(MultipartBody.FORM.subtype());
Headers requestHeaders = argumentCaptor.getValue().headers();
assertThat(requestHeaders.size()).isEqualTo(1);
}
示例13: testMultipartPostRequestHeaders
import com.facebook.react.bridge.JavaOnlyMap; //导入方法依赖的package包/类
@Test
public void testMultipartPostRequestHeaders() throws Exception {
PowerMockito.mockStatic(RequestBodyUtil.class);
when(RequestBodyUtil.getFileInputStream(any(ReactContext.class), any(String.class)))
.thenReturn(mock(InputStream.class));
when(RequestBodyUtil.create(any(MediaType.class), any(InputStream.class)))
.thenReturn(mock(RequestBody.class));
when(RequestBodyUtil.createProgressRequest(any(RequestBody.class), any(ProgressListener.class)))
.thenCallRealMethod();
List<JavaOnlyArray> headers = Arrays.asList(
JavaOnlyArray.of("Accept", "text/plain"),
JavaOnlyArray.of("User-Agent", "React test agent/1.0"),
JavaOnlyArray.of("content-type", "multipart/form-data"));
JavaOnlyMap body = new JavaOnlyMap();
JavaOnlyArray formData = new JavaOnlyArray();
JavaOnlyMap bodyPart = new JavaOnlyMap();
bodyPart.putString("string", "value");
bodyPart.putArray(
"headers",
JavaOnlyArray.from(
Arrays.asList(
JavaOnlyArray.of("content-disposition", "name"))));
formData.pushMap(bodyPart);
body.putArray("formData", formData);
OkHttpClient httpClient = mock(OkHttpClient.class);
when(httpClient.newCall(any(Request.class))).thenAnswer(
new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Call callMock = mock(Call.class);
return callMock;
}
});
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
when(clientBuilder.build()).thenReturn(httpClient);
when(httpClient.newBuilder()).thenReturn(clientBuilder);
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
JavaOnlyArray.from(headers),
body,
/* responseType */ "text",
/* useIncrementalUpdates*/ true,
/* timeout */ 0);
// verify url, method, headers
ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
verify(httpClient).newCall(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().url().toString()).isEqualTo("http://someurl/uploadFoo");
assertThat(argumentCaptor.getValue().method()).isEqualTo("POST");
assertThat(argumentCaptor.getValue().body().contentType().type()).
isEqualTo(MultipartBody.FORM.type());
assertThat(argumentCaptor.getValue().body().contentType().subtype()).
isEqualTo(MultipartBody.FORM.subtype());
Headers requestHeaders = argumentCaptor.getValue().headers();
assertThat(requestHeaders.size()).isEqualTo(3);
assertThat(requestHeaders.get("Accept")).isEqualTo("text/plain");
assertThat(requestHeaders.get("User-Agent")).isEqualTo("React test agent/1.0");
assertThat(requestHeaders.get("content-type")).isEqualTo("multipart/form-data");
}