org.robolectric.shadows.ShadowView Java Examples

The following examples show how to use org.robolectric.shadows.ShadowView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivityWithContextMenuTest.java    From fogger with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUnregisteredLongClickListenerWhenContextMenuUnregisteredOnView() {
    //given
    TextView view = new TextView(RuntimeEnvironment.application.getBaseContext());
    activityWithContextMenu.registerForContextMenu(view);
    ShadowView shadowView = shadowOf(view);

    //expected
    assertThat(shadowView.getOnLongClickListener()).isNotNull();

    //when
    activityWithContextMenu.unregisterForContextMenu(view);

    //then
    assertThat(shadowView.getOnLongClickListener()).isNull();
}
 
Example #2
Source File: LithoViewTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void measureBeforeBeingAttached() {
  mLithoView.measure(makeMeasureSpec(0, UNSPECIFIED), makeMeasureSpec(0, UNSPECIFIED));
  mLithoView.layout(0, 0, mLithoView.getMeasuredWidth(), mLithoView.getMeasuredHeight());

  // View got measured.
  assertThat(mLithoView.getMeasuredWidth()).isGreaterThan(0);
  assertThat(mLithoView.getMeasuredHeight()).isGreaterThan(0);

  // Attaching will automatically mount since we already have a layout fitting our size.
  ShadowView shadow = shadowOf(mLithoView);
  shadow.callOnAttachedToWindow();

  assertThat(getInternalMountItems(mLithoView)).hasSize(2);
}
 
Example #3
Source File: LithoViewTest.java    From litho with Apache License 2.0 5 votes vote down vote up
/** This verifies that the width is 0 with normal layout params. */
@Test
public void measureWithLayoutParams() {
  final Component component =
      new InlineLayoutSpec() {
        @Override
        protected Component onCreateLayout(ComponentContext c) {
          return SimpleMountSpecTester.create(c).widthPercent(100).heightPx(100).build();
        }
      };

  mLithoView = new LithoView(getApplicationContext());
  mLithoView.setComponent(component);

  mLithoView.setLayoutParams(new ViewGroup.LayoutParams(0, 200));
  mLithoView.measure(makeMeasureSpec(0, UNSPECIFIED), makeMeasureSpec(200, EXACTLY));
  mLithoView.layout(0, 0, mLithoView.getMeasuredWidth(), mLithoView.getMeasuredHeight());

  // View got measured.
  assertThat(mLithoView.getMeasuredWidth()).isEqualTo(0);
  assertThat(mLithoView.getMeasuredHeight()).isEqualTo(200);

  // Attaching will not mount anything as we have no width.
  ShadowView shadow = shadowOf(mLithoView);
  shadow.callOnAttachedToWindow();

  assertThat(getInternalMountItems(mLithoView)).isNull();
}
 
Example #4
Source File: LithoViewTest.java    From litho with Apache License 2.0 5 votes vote down vote up
/** This verifies that the width is correct with at most layout params. */
@Test
public void measureWithAtMostLayoutParams() {
  final Component component =
      new InlineLayoutSpec() {
        @Override
        protected Component onCreateLayout(ComponentContext c) {
          return SimpleMountSpecTester.create(c).widthPercent(50).heightPercent(10).build();
        }
      };

  mLithoView = new LithoView(getApplicationContext());
  mLithoView.setComponent(component);

  mLithoView.setLayoutParams(
      new RecyclerViewLayoutManagerOverrideParams(
          SizeSpec.makeSizeSpec(100, SizeSpec.AT_MOST),
          SizeSpec.makeSizeSpec(200, SizeSpec.AT_MOST)));
  mLithoView.measure(makeMeasureSpec(0, UNSPECIFIED), makeMeasureSpec(0, UNSPECIFIED));
  mLithoView.layout(0, 0, mLithoView.getMeasuredWidth(), mLithoView.getMeasuredHeight());

  // View got measured.
  assertThat(mLithoView.getMeasuredWidth()).isEqualTo(50);
  assertThat(mLithoView.getMeasuredHeight()).isEqualTo(20);

  // Attaching will automatically mount since we already have a layout fitting our size.
  ShadowView shadow = shadowOf(mLithoView);
  shadow.callOnAttachedToWindow();

  assertThat(getInternalMountItems(mLithoView)).hasSize(2);
}
 
Example #5
Source File: FeatureCollectionTest.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Test
public void testFeatureSetter() {
  Marker marker = new Marker(getMap());
  collection.removeFeature(marker);
  assertEquals(0, collection.Features().size());
  ShadowView view = Shadow.extract(getMap().getView());
  view.clearWasInvalidated();
  collection.Features(YailList.makeList(Collections.singletonList(marker)));
  assertTrue(view.wasInvalidated());
  assertEquals(1, collection.Features().size());
  assertEquals(marker, collection.Features().get(1));
}
 
Example #6
Source File: FeatureCollectionTest.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private void testFeatureListSetter(MapFeature feature) {
  ShadowView view = Shadow.extract(getMap().getView());
  view.clearWasInvalidated();
  collection.Features(YailList.makeList(Collections.singletonList(feature)));
  assertTrue(view.wasInvalidated());
  assertEquals(1, collection.Features().size());
  assertEquals(feature, collection.Features().get(1));
}
 
Example #7
Source File: MapTest.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Test
public void testFeatureListRemoval() {
  Marker marker1 = new Marker(map);
  Marker marker2 = new Marker(map);
  ((ShadowView) Shadow.extract(map.getView())).clearWasInvalidated();
  map.Features(YailList.makeList(Collections.singletonList(marker1)));
  assertTrue(((ShadowView) Shadow.extract(map.getView())).wasInvalidated());
  assertEquals(1, map.Features().size());
  assertTrue(map.Features().contains(marker1));
  assertFalse(map.Features().contains(marker2));
}
 
Example #8
Source File: TooltipViewTest.java    From tooltip-view with MIT License 5 votes vote down vote up
@Test
public void settersInvalidateView() {
    TooltipView view = createView();
    ShadowView shadow = shadowOf(view);
    shadow.clearWasInvalidated();

    view.setAnchoredViewId(sampleId);
    assertThat(shadow).wasInvalidated();
    shadow.clearWasInvalidated();

    view.setArrowHeight(123);
    assertThat(shadow).wasInvalidated();
    shadow.clearWasInvalidated();

    view.setArrowHeightResource(R.dimen.tooltip_default_arrow_height);
    assertThat(shadow).wasInvalidated();
    shadow.clearWasInvalidated();

    view.setArrowWidth(123);
    assertThat(shadow).wasInvalidated();
    shadow.clearWasInvalidated();

    view.setArrowWidthResource(R.dimen.tooltip_default_arrow_width);
    assertThat(shadow).wasInvalidated();
    shadow.clearWasInvalidated();

    view.setCornerRadius(123);
    assertThat(shadow).wasInvalidated();
    shadow.clearWasInvalidated();

    view.setCornerRadiusResource(R.dimen.tooltip_default_corner_radius);
    assertThat(shadow).wasInvalidated();
    shadow.clearWasInvalidated();

    view.setTooltipColor(123);
    assertThat(shadow).wasInvalidated();
    shadow.clearWasInvalidated();
}
 
Example #9
Source File: RouteFragmentTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
private void simulateTwoFingerDrag() {
    MotionEvent e = mock(MotionEvent.class);
    Mockito.when(e.getPointerCount()).thenReturn(2);
    Mockito.when(e.getAction()).thenReturn(MotionEvent.ACTION_MOVE);
    ShadowView view = shadowOf(act.findViewById(R.id.map));
    view.getOnTouchListener().onTouch(null, e);
}
 
Example #10
Source File: MapTest.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
private static ShadowView shadowOf(View view) {
  return (ShadowView) Shadow.extract(view);
}
 
Example #11
Source File: ShadowViewAssert.java    From tooltip-view with MIT License 4 votes vote down vote up
public ShadowViewAssert(ShadowView actual) {
    super(actual, ShadowViewAssert.class);
}
 
Example #12
Source File: Assertions.java    From tooltip-view with MIT License 4 votes vote down vote up
public static ShadowViewAssert assertThat(ShadowView actual) {
    return new ShadowViewAssert(actual);
}
 
Example #13
Source File: RouteFragmentTest.java    From open with GNU General Public License v3.0 4 votes vote down vote up
private void simulateUserDrag() {
    MotionEvent e = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 120f, 100f, 0);
    ShadowView view = shadowOf(act.findViewById(R.id.map));
    fragment.setCurrentXCor(3.0f);
    view.getOnTouchListener().onTouch(null, e);
}