Java Code Examples for org.fest.assertions.data.MapEntry

The following are top voted examples for showing how to use org.fest.assertions.data.MapEntry. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RNLearn_Project1   File: UIManagerModuleConstantsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCustomBubblingEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomBubblingEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_BUBBLING_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
    mReactContext,
    viewManagers,
    mUIImplementationProvider,
    false);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
      .containsKey("topChange");
}
 
Example 2
Project: RNLearn_Project1   File: UIManagerModuleConstantsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCustomDirectEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomDirectEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_DIRECT_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
    mReactContext,
    viewManagers,
    mUIImplementationProvider,
    false);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
      .containsKey("topLoadingStart");
}
 
Example 3
Project: RNLearn_Project1   File: UIManagerModuleConstantsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCustomBubblingEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomBubblingEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_BUBBLING_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
    mReactContext,
    viewManagers,
    mUIImplementationProvider,
    false);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
      .containsKey("topChange");
}
 
Example 4
Project: RNLearn_Project1   File: UIManagerModuleConstantsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCustomDirectEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomDirectEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_DIRECT_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
    mReactContext,
    viewManagers,
    mUIImplementationProvider,
    false);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
      .containsKey("topLoadingStart");
}
 
Example 5
Project: mimecraft   File: PartTest.java   Source Code and License 6 votes vote down vote up
@Test public void completePart() throws Exception {
  Part p = new Part.Builder() //
      .contentDisposition("form-data; filename=\"foo.txt\"") //
      .contentType("application/json") //
      .contentLength(13) //
      .contentLanguage("English") //
      .contentEncoding("UTF-8") //
      .body("{'foo':'bar'}") //
      .build();

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  p.writeBodyTo(baos);
  String actual = new String(baos.toByteArray(), UTF_8);
  assertThat(actual).isEqualTo("{'foo':'bar'}");
  assertThat(p.getHeaders())
      .hasSize(5)
      .contains( //
          MapEntry.entry("Content-Disposition", "form-data; filename=\"foo.txt\""), //
          MapEntry.entry("Content-Type", "application/json"), //
          MapEntry.entry("Content-Length", "13"), //
          MapEntry.entry("Content-Language", "English"), //
          MapEntry.entry("Content-Transfer-Encoding", "UTF-8") //
      );
}
 
Example 6
Project: mimecraft   File: MultipartWriterTest.java   Source Code and License 6 votes vote down vote up
@Test public void singlePart() throws Exception {
  String expected = "" //
      + "--123\r\n" //
      + "\r\n" //
      + "Hello, World!\r\n" //
      + "--123--";

  Multipart m = new Multipart.Builder("123")
      .addPart(new TestPart("Hello, World!"))
      .build();

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  m.writeBodyTo(out);
  String actual = new String(out.toByteArray(), UTF_8);
  assertThat(actual).isEqualTo(expected);
  assertThat(m.getHeaders())
      .hasSize(1)
      .contains(MapEntry.entry("Content-Type", "multipart/mixed; boundary=123"));
}
 
Example 7
Project: empiria.player   File: CssStylesModuleScopedProviderTest.java   Source Code and License 5 votes vote down vote up
@Test
public void getIOS() throws Exception {
    doReturn(true).when(agentUtil).isMobileUserAgent(eq(MobileUserAgent.SAFARI));

    ModuleStyle moduleStyle = instance.get();
    assertThat(moduleStyle).isInstanceOf(IOSModuleStyle.class);
    assertThat(moduleStyle).contains(MapEntry.entry("1", "11"));
    verify(agentUtil).isMobileUserAgent(eq(MobileUserAgent.SAFARI));
    verify(styleSocket).getStyles(eq(element));

}
 
Example 8
Project: empiria.player   File: CssStylesModuleScopedProviderTest.java   Source Code and License 5 votes vote down vote up
@Test
public void get() throws Exception {
    ModuleStyle moduleStyle = instance.get();
    assertThat(moduleStyle).isInstanceOf(ModuleStyleImpl.class);
    assertThat(moduleStyle).contains(MapEntry.entry("1", "11"));
    verify(agentUtil).isMobileUserAgent(eq(MobileUserAgent.SAFARI));
    verify(styleSocket).getStyles(eq(element));
}
 
Example 9
Project: ReactNativeSignatureExample   File: UIManagerModuleConstantsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testCustomBubblingEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomBubblingEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_BUBBLING_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
      mUIImplementation);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
      .containsKey("topChange");
}
 
Example 10
Project: ReactNativeSignatureExample   File: UIManagerModuleConstantsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testCustomDirectEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomDirectEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_DIRECT_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
      mUIImplementation);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
      .containsKey("topLoadingStart");
}
 
Example 11
Project: react-native-ibeacon-android   File: UIManagerModuleConstantsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testCustomBubblingEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomBubblingEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_BUBBLING_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
      mUIImplementation);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
      .containsKey("topChange");
}
 
Example 12
Project: react-native-ibeacon-android   File: UIManagerModuleConstantsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testCustomDirectEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomDirectEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_DIRECT_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
      mUIImplementation);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
      .containsKey("topLoadingStart");
}
 
Example 13
Project: react-native-box-loaders   File: UIManagerModuleConstantsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testCustomBubblingEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomBubblingEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_BUBBLING_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
      mUIImplementation);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
      .containsKey("topChange");
}
 
Example 14
Project: react-native-box-loaders   File: UIManagerModuleConstantsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testCustomDirectEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomDirectEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_DIRECT_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
      mUIImplementation);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
      .containsKey("topLoadingStart");
}
 
Example 15
Project: Ironman   File: UIManagerModuleConstantsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testCustomBubblingEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomBubblingEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_BUBBLING_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
    mUIImplementationProvider);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_BUBBLING_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_BUBBLING_EVENT_MAP))
      .containsKey("topChange");
}
 
Example 16
Project: Ironman   File: UIManagerModuleConstantsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testCustomDirectEvents() {
  ViewManager mockViewManager = mock(ViewManager.class);
  List<ViewManager> viewManagers = Arrays.asList(mockViewManager);
  when(mockViewManager.getExportedCustomDirectEventTypeConstants())
      .thenReturn(MapBuilder.of("onTwirl", TWIRL_DIRECT_EVENT_MAP));
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
    mUIImplementationProvider);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES))
      .contains(MapEntry.entry("onTwirl", TWIRL_DIRECT_EVENT_MAP))
      .containsKey("topLoadingStart");
}
 
Example 17
Project: stack-overflow-android   File: SimpleTest.java   Source Code and License 5 votes vote down vote up
@Test
public void shouldCallRestApiWithPassedText() {
    // given
    String queryString = "query string";
    query.setText(queryString);

    // when
    search.performClick();

    // then
    ArgumentCaptor<Map> arg = ArgumentCaptor.forClass(Map.class);
    Mockito.verify(mockRestApi, times(1)).search(arg.capture(), any(Integer.class), any(Callback.class));
    assertThat(arg.getValue()).contains(MapEntry.entry("intitle", queryString));
}
 
Example 18
Project: mimecraft   File: PartTest.java   Source Code and License 5 votes vote down vote up
@Test public void multipartBodySetsType() throws Exception {
  Multipart m = new Multipart.Builder().addPart(new TestPart("hi")).build();

  try {
    new Part.Builder().body(m).contentType("break me!");
    fail();
  } catch (IllegalStateException expected) {
  }

  Part p = new Part.Builder().body(m).build();
  for (Map.Entry<String, String> header : m.getHeaders().entrySet()) {
    assertThat(p.getHeaders()).contains(MapEntry.entry(header.getKey(), header.getValue()));
  }
}
 
Example 19
Project: mimecraft   File: MultipartWriterTest.java   Source Code and License 5 votes vote down vote up
@Test public void threeParts() throws Exception {
  String expected = ""
      + "--123\r\n"
      + "\r\n"
      + "Quick\r\n"
      + "--123\r\n"
      + "\r\n"
      + "Brown\r\n"
      + "--123\r\n"
      + "\r\n"
      + "Fox\r\n"
      + "--123--";

  Multipart m = new Multipart.Builder("123")
      .addPart(new TestPart("Quick"))
      .addPart(new TestPart("Brown"))
      .addPart(new TestPart("Fox"))
      .build();

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  m.writeBodyTo(out);
  String actual = new String(out.toByteArray(), UTF_8);
  assertThat(actual).isEqualTo(expected);
  assertThat(m.getHeaders())
      .hasSize(1)
      .contains(MapEntry.entry("Content-Type", "multipart/mixed; boundary=123"));
}
 
Example 20
Project: RNLearn_Project1   File: UIManagerModuleConstantsTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testMergeConstants() {
  ViewManager managerX = mock(ViewManager.class);
  when(managerX.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "registrationName",
          "onTwirl",
          "keyToOverride",
          "valueX",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueX", "anotherKey", "valueX"))));

  ViewManager managerY = mock(ViewManager.class);
  when(managerY.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "extraKey",
          "extraValue",
          "keyToOverride",
          "valueY",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueY", "extraKey", "valueY"))));

  List<ViewManager> viewManagers = Arrays.asList(managerX, managerY);
  UIManagerModule uiManagerModule = new UIManagerModule(
    mReactContext,
    viewManagers,
    mUIImplementationProvider,
    false);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");

  Map twirlMap = (Map) valueAtPath(constants, CUSTOM_DIRECT_EVENT_TYPES, "onTwirl");
  assertThat(twirlMap)
      .contains(MapEntry.entry("registrationName", "onTwirl"))
      .contains(MapEntry.entry("keyToOverride", "valueY"))
      .contains(MapEntry.entry("extraKey", "extraValue"))
      .containsKey("mapToMerge");

  Map mapToMerge = (Map) valueAtPath(twirlMap, "mapToMerge");
  assertThat(mapToMerge)
      .contains(MapEntry.entry("keyToOverride", "innerValueY"))
      .contains(MapEntry.entry("anotherKey", "valueX"))
      .contains(MapEntry.entry("extraKey", "valueY"));
}
 
Example 21
Project: RNLearn_Project1   File: UIManagerModuleConstantsTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testMergeConstants() {
  ViewManager managerX = mock(ViewManager.class);
  when(managerX.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "registrationName",
          "onTwirl",
          "keyToOverride",
          "valueX",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueX", "anotherKey", "valueX"))));

  ViewManager managerY = mock(ViewManager.class);
  when(managerY.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "extraKey",
          "extraValue",
          "keyToOverride",
          "valueY",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueY", "extraKey", "valueY"))));

  List<ViewManager> viewManagers = Arrays.asList(managerX, managerY);
  UIManagerModule uiManagerModule = new UIManagerModule(
    mReactContext,
    viewManagers,
    mUIImplementationProvider,
    false);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");

  Map twirlMap = (Map) valueAtPath(constants, CUSTOM_DIRECT_EVENT_TYPES, "onTwirl");
  assertThat(twirlMap)
      .contains(MapEntry.entry("registrationName", "onTwirl"))
      .contains(MapEntry.entry("keyToOverride", "valueY"))
      .contains(MapEntry.entry("extraKey", "extraValue"))
      .containsKey("mapToMerge");

  Map mapToMerge = (Map) valueAtPath(twirlMap, "mapToMerge");
  assertThat(mapToMerge)
      .contains(MapEntry.entry("keyToOverride", "innerValueY"))
      .contains(MapEntry.entry("anotherKey", "valueX"))
      .contains(MapEntry.entry("extraKey", "valueY"));
}
 
Example 22
Project: ReactNativeSignatureExample   File: UIManagerModuleConstantsTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testMergeConstants() {
  ViewManager managerX = mock(ViewManager.class);
  when(managerX.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "registrationName",
          "onTwirl",
          "keyToOverride",
          "valueX",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueX", "anotherKey", "valueX"))));

  ViewManager managerY = mock(ViewManager.class);
  when(managerY.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "extraKey",
          "extraValue",
          "keyToOverride",
          "valueY",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueY", "extraKey", "valueY"))));

  List<ViewManager> viewManagers = Arrays.asList(managerX, managerY);
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
      mUIImplementation);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");

  Map twirlMap = (Map) valueAtPath(constants, CUSTOM_DIRECT_EVENT_TYPES, "onTwirl");
  assertThat(twirlMap)
      .contains(MapEntry.entry("registrationName", "onTwirl"))
      .contains(MapEntry.entry("keyToOverride", "valueY"))
      .contains(MapEntry.entry("extraKey", "extraValue"))
      .containsKey("mapToMerge");

  Map mapToMerge = (Map) valueAtPath(twirlMap, "mapToMerge");
  assertThat(mapToMerge)
      .contains(MapEntry.entry("keyToOverride", "innerValueY"))
      .contains(MapEntry.entry("anotherKey", "valueX"))
      .contains(MapEntry.entry("extraKey", "valueY"));
}
 
Example 23
Project: react-native-ibeacon-android   File: UIManagerModuleConstantsTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testMergeConstants() {
  ViewManager managerX = mock(ViewManager.class);
  when(managerX.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "registrationName",
          "onTwirl",
          "keyToOverride",
          "valueX",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueX", "anotherKey", "valueX"))));

  ViewManager managerY = mock(ViewManager.class);
  when(managerY.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "extraKey",
          "extraValue",
          "keyToOverride",
          "valueY",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueY", "extraKey", "valueY"))));

  List<ViewManager> viewManagers = Arrays.asList(managerX, managerY);
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
      mUIImplementation);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");

  Map twirlMap = (Map) valueAtPath(constants, CUSTOM_DIRECT_EVENT_TYPES, "onTwirl");
  assertThat(twirlMap)
      .contains(MapEntry.entry("registrationName", "onTwirl"))
      .contains(MapEntry.entry("keyToOverride", "valueY"))
      .contains(MapEntry.entry("extraKey", "extraValue"))
      .containsKey("mapToMerge");

  Map mapToMerge = (Map) valueAtPath(twirlMap, "mapToMerge");
  assertThat(mapToMerge)
      .contains(MapEntry.entry("keyToOverride", "innerValueY"))
      .contains(MapEntry.entry("anotherKey", "valueX"))
      .contains(MapEntry.entry("extraKey", "valueY"));
}
 
Example 24
Project: react-native-box-loaders   File: UIManagerModuleConstantsTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testMergeConstants() {
  ViewManager managerX = mock(ViewManager.class);
  when(managerX.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "registrationName",
          "onTwirl",
          "keyToOverride",
          "valueX",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueX", "anotherKey", "valueX"))));

  ViewManager managerY = mock(ViewManager.class);
  when(managerY.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "extraKey",
          "extraValue",
          "keyToOverride",
          "valueY",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueY", "extraKey", "valueY"))));

  List<ViewManager> viewManagers = Arrays.asList(managerX, managerY);
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
      mUIImplementation);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");

  Map twirlMap = (Map) valueAtPath(constants, CUSTOM_DIRECT_EVENT_TYPES, "onTwirl");
  assertThat(twirlMap)
      .contains(MapEntry.entry("registrationName", "onTwirl"))
      .contains(MapEntry.entry("keyToOverride", "valueY"))
      .contains(MapEntry.entry("extraKey", "extraValue"))
      .containsKey("mapToMerge");

  Map mapToMerge = (Map) valueAtPath(twirlMap, "mapToMerge");
  assertThat(mapToMerge)
      .contains(MapEntry.entry("keyToOverride", "innerValueY"))
      .contains(MapEntry.entry("anotherKey", "valueX"))
      .contains(MapEntry.entry("extraKey", "valueY"));
}
 
Example 25
Project: Ironman   File: UIManagerModuleConstantsTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testMergeConstants() {
  ViewManager managerX = mock(ViewManager.class);
  when(managerX.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "registrationName",
          "onTwirl",
          "keyToOverride",
          "valueX",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueX", "anotherKey", "valueX"))));

  ViewManager managerY = mock(ViewManager.class);
  when(managerY.getExportedCustomDirectEventTypeConstants()).thenReturn(MapBuilder.of(
      "onTwirl",
      MapBuilder.of(
          "extraKey",
          "extraValue",
          "keyToOverride",
          "valueY",
          "mapToMerge",
          MapBuilder.of("keyToOverride", "innerValueY", "extraKey", "valueY"))));

  List<ViewManager> viewManagers = Arrays.asList(managerX, managerY);
  UIManagerModule uiManagerModule = new UIManagerModule(
      mReactContext,
      viewManagers,
    mUIImplementationProvider);
  Map<String, Object> constants = uiManagerModule.getConstants();
  assertThat((Map) constants.get(CUSTOM_DIRECT_EVENT_TYPES)).containsKey("onTwirl");

  Map twirlMap = (Map) valueAtPath(constants, CUSTOM_DIRECT_EVENT_TYPES, "onTwirl");
  assertThat(twirlMap)
      .contains(MapEntry.entry("registrationName", "onTwirl"))
      .contains(MapEntry.entry("keyToOverride", "valueY"))
      .contains(MapEntry.entry("extraKey", "extraValue"))
      .containsKey("mapToMerge");

  Map mapToMerge = (Map) valueAtPath(twirlMap, "mapToMerge");
  assertThat(mapToMerge)
      .contains(MapEntry.entry("keyToOverride", "innerValueY"))
      .contains(MapEntry.entry("anotherKey", "valueX"))
      .contains(MapEntry.entry("extraKey", "valueY"));
}
 
Example 26
Project: mimecraft   File: ComplexExamplesTest.java   Source Code and License 4 votes vote down vote up
@Test public void fieldAndTwoFiles() throws Exception {
  String expected = ""
      + "--AaB03x\r\n"
      + "Content-Disposition: form-data; name=\"submit-name\"\r\n"
      + "Content-Length: 5\r\n"
      + "\r\n"
      + "Larry\r\n"
      + "--AaB03x\r\n"
      + "Content-Disposition: form-data; name=\"files\"\r\n"
      + "Content-Type: multipart/mixed; boundary=BbC04y\r\n"
      + "\r\n"
      + "--BbC04y\r\n"
      + "Content-Disposition: file; filename=\"file1.txt\"\r\n"
      + "Content-Type: text/plain\r\n"
      + "Content-Length: 29\r\n"
      + "\r\n"
      + "... contents of file1.txt ...\r\n"
      + "--BbC04y\r\n"
      + "Content-Disposition: file; filename=\"file2.gif\"\r\n"
      + "Content-Type: image/gif\r\n"
      + "Content-Length: 29\r\n"
      + "Content-Transfer-Encoding: binary\r\n"
      + "\r\n"
      + "... contents of file2.gif ...\r\n"
      + "--BbC04y--\r\n"
      + "--AaB03x--";

  Multipart m = new Multipart.Builder("AaB03x") //
      .type(Multipart.Type.FORM) //
      .addPart(new Part.Builder() //
          .contentDisposition("form-data; name=\"submit-name\"") //
          .body("Larry") //
          .build()) //
      .addPart(new Part.Builder() //
          .contentDisposition("form-data; name=\"files\"") //
          .body(new Multipart.Builder("BbC04y") //
              .addPart(new Part.Builder() //
                  .contentDisposition("file; filename=\"file1.txt\"") //
                  .contentType("text/plain") //
                  .body("... contents of file1.txt ...") //
                  .build()) //
              .addPart(new Part.Builder() //
                  .contentDisposition("file; filename=\"file2.gif\"") //
                  .contentType("image/gif") //
                  .contentEncoding("binary") //
                  .body("... contents of file2.gif ...") //
                  .build()) //
              .build()) //
          .build()) //
      .build();

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  m.writeBodyTo(out);
  String actual = new String(out.toByteArray(), UTF_8);
  assertThat(actual).isEqualTo(expected);
  assertThat(m.getHeaders()) //
      .hasSize(1) //
      .contains(MapEntry.entry("Content-Type", "multipart/form-data; boundary=AaB03x"));
}