private void validateSelectResult(CommandResult cmdResult, Boolean expectSuccess, Integer expectedRows, String[] cols) { if (ResultData.TYPE_MODEL.equals(cmdResult.getType())) { ResultModel rd = (ResultModel) cmdResult.getResultData(); Map<String, String> data = rd.getDataSection(DataCommandResult.DATA_INFO_SECTION).getContent(); assertThat(data.get("Result")).isEqualTo(expectSuccess.toString()); if (expectSuccess && expectedRows != -1) { assertThat(data.get("Rows")).isEqualTo(expectedRows.toString()); if (expectedRows > 0 && cols != null) { Map<String, List<String>> table = rd.getTableSection(DataCommandResult.QUERY_SECTION).getContent(); assertThat(table.keySet()).contains(cols); } } } else { fail("Expected CompositeResult Returned Result Type " + cmdResult.getType()); } }
@Test public void testThatALauncherCanAddACommand() { Launcher myLauncher = new Launcher() { @Override protected void load() { super.load(); register(FooCommand.class); } }; myLauncher.dispatch(new String[]{"foo"}); assertThat(myLauncher.getCommandNames()).contains("foo"); assertWaitUntil(spy::get); }
@Test public void testDelete() { RecyclerView.ViewHolder holder = shadowAdapter.getViewHolder(0); holder.itemView.performLongClick(); ActionMode actionMode = mock(ActionMode.class); activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear)); AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog(); dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick(); assertEquals(2, adapter.getItemCount()); activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear)); dialog = ShadowAlertDialog.getLatestAlertDialog(); dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); verify(favoriteManager).remove(any(Context.class), selection.capture()); assertThat(selection.getValue()).contains("1"); verify(actionMode).finish(); when(favoriteManager.getSize()).thenReturn(1); observerCaptor.getValue().onChanged(); assertEquals(1, adapter.getItemCount()); }
true); assertThat(component.getDispatchedEventHandlers()).contains(visibleEventHandler); assertThat(component.getDispatchedEventHandlers()).contains(focusedEventHandler); assertThat(component.getDispatchedEventHandlers()).contains(fullImpressionHandler); assertThat(component.getDispatchedEventHandlers()).contains(invisibleEventHandler); assertThat(component.getDispatchedEventHandlers()).contains(unfocusedEventHandler); assertThat(component.getDispatchedEventHandlers()).contains(visibleEventHandler); assertThat(component.getDispatchedEventHandlers()).contains(focusedEventHandler); assertThat(component.getDispatchedEventHandlers()).contains(fullImpressionHandler);
@Test public void addHeader_getRequestHeaderFiles_meet() throws IOException { assertThat(connection.getRequestProperty("no-exist-key")).isNull(); DownloadOkHttp3Connection.Factory creator = new DownloadOkHttp3Connection.Factory(); DownloadOkHttp3Connection connection = (DownloadOkHttp3Connection) creator.create(URL); connection.addHeader("mock", "mock"); connection.addHeader("mock1", "mock2"); connection.addHeader("mock1", "mock3"); assertThat(connection.getRequestProperty("mock")).isEqualTo("mock"); Map<String, List<String>> headers = connection.getRequestProperties(); assertThat(headers.keySet()).hasSize(2).contains("mock", "mock1"); List<String> allValues = new ArrayList<>(); Collection<List<String>> valueList = headers.values(); for (List<String> values : valueList) { allValues.addAll(values); } assertThat(allValues).hasSize(3).contains("mock", "mock2", "mock3"); }
10); assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(invisibleEventHandler); assertThat(content.getDispatchedEventHandlers()).contains(invisibleEventHandler); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(visibleEventHandler); assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(invisibleEventHandler); assertThat(content.getDispatchedEventHandlers()).contains(invisibleEventHandler); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(visibleEventHandler);
@Test public void testFocusedOccupiesHalfViewport() { final TestComponent content = create(mContext).build(); final EventHandler<FocusedVisibleEvent> focusedEventHandler = new EventHandler<>(content, 2); final LithoView lithoView = mountComponent( mContext, mLithoView, Column.create(mContext) .child( Wrapper.create(mContext) .delegate(content) .focusedHandler(focusedEventHandler) .widthPx(10) .heightPx(10)) .build(), true, 10, 10); content.getDispatchedEventHandlers().clear(); lithoView.performIncrementalMount(new Rect(LEFT, 0, RIGHT, 4), true); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(focusedEventHandler); lithoView.performIncrementalMount(new Rect(LEFT, 0, RIGHT, 5), true); assertThat(content.getDispatchedEventHandlers()).contains(focusedEventHandler); }
@Test public void testFocusedOccupiesLessThanHalfViewport() { final TestComponent content = create(mContext).build(); final EventHandler<FocusedVisibleEvent> focusedEventHandler = new EventHandler<>(content, 2); final LithoView lithoView = mountComponent( mContext, mLithoView, Column.create(mContext) .child( Wrapper.create(mContext) .delegate(content) .focusedHandler(focusedEventHandler) .widthPx(10) .heightPx(3)) .build(), true, 10, 10); content.getDispatchedEventHandlers().clear(); lithoView.performIncrementalMount(new Rect(LEFT, 0, RIGHT, 2), true); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(focusedEventHandler); lithoView.performIncrementalMount(new Rect(LEFT, 0, RIGHT, 3), true); assertThat(content.getDispatchedEventHandlers()).contains(focusedEventHandler); }
assertThat(content.getDispatchedEventHandlers()).contains(visibilityChangedHandler);
assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler);
10); assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler); assertThat(content.getDispatchedEventHandlers()).doesNotContain(invisibleEventHandler); assertThat(content.getDispatchedEventHandlers()).contains(invisibleEventHandler); assertThat(content.getDispatchedEventHandlers()).doesNotContain(visibleEventHandler); assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler); assertThat(content.getDispatchedEventHandlers()).doesNotContain(invisibleEventHandler);
assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler);
.contains(visibleEventHandler1); assertThat(component1.getDispatchedEventHandlers()) .contains(focusedEventHandler1); .contains(invisibleEventHandler1); assertThat(component1.getDispatchedEventHandlers()) .contains(unfocusedEventHandler1); assertThat(component2.getDispatchedEventHandlers()) .contains(visibleEventHandler2);
@Test public void testTransientStateDoesNotTriggerVisibilityEvents() { final TestComponent content = create(mContext).build(); final EventHandler<VisibleEvent> visibleEventHandler = new EventHandler<>(content, 2); final LithoView lithoView = mountComponent( mContext, Column.create(mContext) .child( Wrapper.create(mContext) .delegate(content) .visibleHandler(visibleEventHandler) .widthPx(10) .heightPx(10)) .build(), true); lithoView.performIncrementalMount(new Rect(0, -10, 10, -5), true); content.getDispatchedEventHandlers().clear(); lithoView.setHasTransientState(true); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(visibleEventHandler); lithoView.setMountStateDirty(); lithoView.performIncrementalMount(new Rect(0, -10, 10, -5), true); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(visibleEventHandler); lithoView.setHasTransientState(false); assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler); }
@Test public void testVisibleEventWithWidthRatio() { final TestComponent content = create(mContext).build(); final EventHandler<VisibleEvent> visibleEventHandler = new EventHandler<>(content, 2); final LithoView lithoView = mountComponent( mContext, mLithoView, Column.create(mContext) .child( Wrapper.create(mContext) .delegate(content) .visibleWidthRatio(0.4f) .visibleHandler(visibleEventHandler) .widthPx(10) .heightPx(5) .marginPx(YogaEdge.TOP, 5)) .build(), true, 10, 5); assertThat(content.getDispatchedEventHandlers()).doesNotContain(visibleEventHandler); lithoView.performIncrementalMount(new Rect(LEFT, 0, 3, 10), true); assertThat(content.getDispatchedEventHandlers()).doesNotContain(visibleEventHandler); lithoView.performIncrementalMount(new Rect(LEFT, 0, 5, 10), true); assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler); }
@Test public void testVisibleEvent() { final TestComponent content = create(mContext).build(); final EventHandler<VisibleEvent> visibleEventHandler = new EventHandler<>(content, 2); final LithoView lithoView = mountComponent( mContext, mLithoView, Column.create(mContext) .child( Wrapper.create(mContext) .delegate(content) .visibleHandler(visibleEventHandler) .widthPx(10) .heightPx(5) .marginPx(YogaEdge.TOP, 5)) .build(), true, 10, 5); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(visibleEventHandler); lithoView.performIncrementalMount(new Rect(LEFT, 0, RIGHT, 10), true); assertThat(content.getDispatchedEventHandlers()).contains(visibleEventHandler); }
@Test public void testInvisibleEvent() { final TestComponent content = create(mContext).build(); final EventHandler<InvisibleEvent> invisibleEventHandler = new EventHandler<>(content, 2); final LithoView lithoView = mountComponent( mContext, mLithoView, Column.create(mContext) .child( Wrapper.create(mContext) .delegate(content) .invisibleHandler(invisibleEventHandler) .widthPx(10) .heightPx(5) .marginPx(YogaEdge.TOP, 5)) .build(), true, 10, 10); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(invisibleEventHandler); lithoView.performIncrementalMount(new Rect(LEFT, 0, RIGHT, 5), true); assertThat(content.getDispatchedEventHandlers()).contains(invisibleEventHandler); }
@Test public void testDetachWithReleasedTreeTriggersInvisibilityItems() { final TestComponent content = create(mContext).build(); final EventHandler<InvisibleEvent> invisibleEventHandler = new EventHandler<>(content, 2); final LithoView lithoView = mountComponent( mContext, Column.create(mContext) .child( Wrapper.create(mContext) .delegate(content) .invisibleHandler(invisibleEventHandler) .widthPx(10) .heightPx(10)) .build(), true); lithoView.performIncrementalMount(new Rect(LEFT, 0, RIGHT, 10), true); lithoView.release(); assertThat(content.getDispatchedEventHandlers()) .doesNotContain(invisibleEventHandler); unbindComponent(lithoView); assertThat(content.getDispatchedEventHandlers()).contains(invisibleEventHandler); }
@Test public void testFullImpressionEvent() { final TestComponent content = create(mContext).build(); final EventHandler<FullImpressionVisibleEvent> fullImpressionVisibleEvent = new EventHandler<>(content, 2); mountComponent( mContext, mLithoView, Column.create(mContext) .child( Wrapper.create(mContext) .delegate(content) .fullImpressionHandler(fullImpressionVisibleEvent) .widthPx(10) .heightPx(5) .marginPx(YogaEdge.TOP, 5)) .build(), true, 10, 10); assertThat(content.getDispatchedEventHandlers()) .contains(fullImpressionVisibleEvent); }