com.google.android.flexbox.FlexboxLayout

Here are the examples of the java api class com.google.android.flexbox.FlexboxLayout taken from open source projects.

1. FlexboxAndroidTest#testFlexWrap_wrap()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexWrap_wrap() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_wrap_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    // The width of the FlexboxLayout is not enough for placing the three text views.
    // The third text view should be placed below the first one
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
}

2. FlexboxAndroidTest#testLoadFromLayoutXml()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testLoadFromLayoutXml() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_simple);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE));
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_CENTER));
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_CENTER));
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_CENTER));
    assertThat(flexboxLayout.getChildCount(), is(1));
    View child = flexboxLayout.getChildAt(0);
    FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) child.getLayoutParams();
    assertThat(lp.order, is(2));
    assertThat(lp.flexGrow, is(1f));
    assertThat(lp.alignSelf, is(FlexboxLayout.LayoutParams.ALIGN_SELF_STRETCH));
}

3. MainActivityTest#testEditFragment_changeFlexBasisPercent()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testEditFragment_changeFlexBasisPercent() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    onView(withId(R.id.textview1)).perform(click());
    onView(withId(R.id.edit_text_flex_basis_percent)).perform(replaceText("50"), closeSoftKeyboard());
    onView(withId(R.id.button_ok)).perform(click());
    TextView first = (TextView) activity.findViewById(R.id.textview1);
    TextView second = (TextView) activity.findViewById(R.id.textview2);
    TextView third = (TextView) activity.findViewById(R.id.textview3);
    assertNotNull(first);
    assertNotNull(second);
    assertNotNull(third);
    assertThat(first.getWidth(), is(flexboxLayout.getWidth() / 2));
}

4. MainActivityTest#testEditFragment_changeFlexGrow()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testEditFragment_changeFlexGrow() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    onView(withId(R.id.textview1)).perform(click());
    onView(withId(R.id.edit_text_flex_grow)).perform(replaceText("1"), closeSoftKeyboard());
    onView(withId(R.id.button_ok)).perform(click());
    TextView first = (TextView) activity.findViewById(R.id.textview1);
    TextView second = (TextView) activity.findViewById(R.id.textview2);
    TextView third = (TextView) activity.findViewById(R.id.textview3);
    assertNotNull(first);
    assertNotNull(second);
    assertNotNull(third);
    assertThat(first.getWidth(), is(flexboxLayout.getWidth() - second.getWidth() - third.getWidth()));
}

5. MainActivityTest#testEditFragment_changeOrder()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testEditFragment_changeOrder() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    onView(withId(R.id.textview1)).perform(click());
    onView(withId(R.id.edit_text_order)).perform(replaceText("3"), closeSoftKeyboard());
    onView(withId(R.id.button_ok)).perform(click());
    TextView first = (TextView) flexboxLayout.getReorderedChildAt(0);
    TextView second = (TextView) flexboxLayout.getReorderedChildAt(1);
    TextView third = (TextView) flexboxLayout.getReorderedChildAt(2);
    assertThat(first.getText().toString(), is("2"));
    assertThat(second.getText().toString(), is("3"));
    assertThat(third.getText().toString(), is("1"));
}

6. MainActivityTest#testConfigurationChange()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testConfigurationChange() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    onView(withId(R.id.add_fab)).perform(click());
    onView(withId(R.id.add_fab)).perform(click());
    int beforeCount = flexboxLayout.getChildCount();
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    // Verify the flex items are restored across the configuration change.
    assertThat(flexboxLayout.getChildCount(), is(beforeCount));
}

7. FlexboxAndroidTest#testEmptyChildren()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testEmptyChildren() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_empty_children);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getChildCount(), is(0));
}

8. FlexboxAndroidTest#testWrap_childMargin_vertical()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testWrap_childMargin_vertical() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_wrap_child_margin_vertical_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    // The sum of height of TextView1 and TextView2 is not enough for wrapping, but considering
    // the margin of the TextView2, the second TextView should be wrapped
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    TextView text2 = (TextView) activity.findViewById(R.id.text2);
    FlexboxLayout.LayoutParams lp2 = (FlexboxLayout.LayoutParams) text2.getLayoutParams();
    assertThat(flexboxLayout.getWidth(), is(text1.getWidth() + text2.getWidth() + lp2.leftMargin + lp2.rightMargin));
}

9. FlexboxAndroidTest#testWrap_childMargin_horizontal()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testWrap_childMargin_horizontal() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_wrap_child_margin_horizontal_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
    // The sum of width of TextView1 and TextView2 is not enough for wrapping, but considering
    // the margin for the TextView2, the second TextView should be wrapped
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    TextView text2 = (TextView) activity.findViewById(R.id.text2);
    FlexboxLayout.LayoutParams lp2 = (FlexboxLayout.LayoutParams) text2.getLayoutParams();
    assertThat(flexboxLayout.getHeight(), is(text1.getHeight() + text2.getHeight() + lp2.topMargin + lp2.bottomMargin));
}

10. FlexboxAndroidTest#testWrap_parentPadding_vertical()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testWrap_parentPadding_vertical() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_wrap_parent_padding_vertical_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    // The sum of height of TextView1 and TextView2 is not enough for wrapping, but considering
    // parent padding, the second TextView should be wrapped
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    TextView text2 = (TextView) activity.findViewById(R.id.text2);
    assertThat(flexboxLayout.getWidth(), is(flexboxLayout.getPaddingLeft() + flexboxLayout.getPaddingRight() + text1.getWidth() + text2.getWidth()));
}

11. FlexboxAndroidTest#testWrap_parentPadding_horizontal()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testWrap_parentPadding_horizontal() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_wrap_parent_padding_horizontal_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
    // The sum of width of TextView1 and TextView2 is not enough for wrapping, but considering
    // parent padding, the second TextView should be wrapped
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    TextView text2 = (TextView) activity.findViewById(R.id.text2);
    assertThat(flexboxLayout.getHeight(), is(flexboxLayout.getPaddingTop() + flexboxLayout.getPaddingBottom() + text1.getHeight() + text2.getHeight()));
}

12. FlexboxAndroidTest#testMaxHeight_works_as_lower_bound_expand_to()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testMaxHeight_works_as_lower_bound_expand_to() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_maxheight_upper_bound_test);
        }
    });
    // This test case verifies if the maxHeight attribute works as a upper bound
    // when the view would expand more than the maxHeight if the maxHeight weren't set
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    int maxHeight = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).maxHeight;
    onView(withId(R.id.text1)).check(hasHeight(maxHeight));
    assertEquals(flexboxLayout.getHeight(), textView1.getHeight() + textView2.getHeight());
}

13. FlexboxAndroidTest#testMaxHeight_initial_height_more_than_maxHeight()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testMaxHeight_initial_height_more_than_maxHeight() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_maxheight_test);
        }
    });
    // This test case verifies if the maxHeight attribute works as a maximum constraint
    // ff the initial view height is more than the value of maxHeight.
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    int maxHeight = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).maxHeight;
    onView(withId(R.id.text1)).check(hasHeight(maxHeight));
    onView(withId(R.id.text2)).check(hasHeight(flexboxLayout.getHeight() - maxHeight));
}

14. FlexboxAndroidTest#testMaxWidth_works_as_upper_bound_expand_to()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testMaxWidth_works_as_upper_bound_expand_to() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_maxwidth_upper_bound_test);
        }
    });
    // This test case verifies if the maxWidth attribute works as a upper bound
    // when the view would expand more than the maxWidth if the maxWidth weren't set
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    int maxWidth = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).maxWidth;
    onView(withId(R.id.text1)).check(hasWidth(maxWidth));
    assertEquals(flexboxLayout.getWidth(), textView1.getWidth() + textView2.getWidth());
}

15. FlexboxAndroidTest#testMaxWidth_initial_width_more_than_maxWidth()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testMaxWidth_initial_width_more_than_maxWidth() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_maxwidth_test);
        }
    });
    // This test case verifies if the maxWidth attribute works as a maximum constraint
    // ff the initial view width is more than the value of maxWidth.
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    int maxWidth = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).maxWidth;
    onView(withId(R.id.text1)).check(hasWidth(maxWidth));
    onView(withId(R.id.text2)).check(hasWidth(flexboxLayout.getWidth() - maxWidth));
}

16. FlexboxAndroidTest#testMinHeight_works_as_lower_bound_shrink_to()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testMinHeight_works_as_lower_bound_shrink_to() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_minheight_lower_bound_test);
        }
    });
    // This test case verifies if the minHeight attribute works as a lower bound
    // when the view would shrink less than the minHeight if the minHeight weren't set
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    TextView textView4 = (TextView) activity.findViewById(R.id.text4);
    int minHeight = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).minHeight;
    onView(withId(R.id.text1)).check(hasHeight(minHeight));
    assertEquals(flexboxLayout.getHeight(), textView1.getHeight() + textView2.getHeight() + textView3.getHeight() + textView4.getHeight());
}

17. FlexboxAndroidTest#testMinHeight_initial_height_less_than_minHeight()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testMinHeight_initial_height_less_than_minHeight() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_minheight_test);
        }
    });
    // This test case verifies if the minHeight attribute works as a minimum constraint
    // If the initial view height is less than the value of minHeight.
    // The textView1's layout_height is set to wrap_content and its text is "1" apparently
    // the initial measured height is less than the value of layout_minHeight (100dp)
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    int minHeight = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).minHeight;
    onView(withId(R.id.text1)).check(hasHeight(minHeight));
    onView(withId(R.id.text2)).check(hasHeight(flexboxLayout.getHeight() - minHeight));
}

18. FlexboxAndroidTest#testMinWidth_works_as_lower_bound_shrink_to()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testMinWidth_works_as_lower_bound_shrink_to() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_minwidth_lower_bound_test);
        }
    });
    // This test case verifies if the minWidth attribute works as a lower bound
    // when the view would shrink less than the minWidth if the minWidth weren't set
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    TextView textView4 = (TextView) activity.findViewById(R.id.text4);
    int minWidth = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).minWidth;
    onView(withId(R.id.text1)).check(hasWidth(minWidth));
    assertEquals(flexboxLayout.getWidth(), textView1.getWidth() + textView2.getWidth() + textView3.getWidth() + textView4.getWidth());
}

19. FlexboxAndroidTest#testMinWidth_initial_width_less_than_minWidth()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testMinWidth_initial_width_less_than_minWidth() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_minwidth_test);
        }
    });
    // This test case verifies if the minWidth attribute works as a minimum constraint
    // If the initial view width is less than the value of minWidth.
    // The textView1's layout_width is set to wrap_content and its text is "1" apparently
    // the initial measured width is less than the value of layout_minWidth (100dp)
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    int minWidth = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).minWidth;
    onView(withId(R.id.text1)).check(hasWidth(minWidth));
    onView(withId(R.id.text2)).check(hasWidth(flexboxLayout.getWidth() - minWidth));
}

20. FlexboxAndroidTest#testFlexDirection_column_reverse()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexDirection_column_reverse() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_wrap_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN_REVERSE);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN_REVERSE));
    onView(withId(R.id.text1)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isAbove(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
}

21. FlexboxAndroidTest#testFlexDirection_row_reverse()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexDirection_row_reverse() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_wrap_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE));
    // The layout direction should be right to left
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
}

22. FlexboxAndroidTest#testAlignItems_flexEnd_parentPadding()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_flexEnd_parentPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_parent_padding_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    assertThat(textView1.getBottom(), is(flexboxLayout.getBottom() - flexboxLayout.getPaddingBottom()));
    assertThat(textView2.getBottom(), is(flexboxLayout.getBottom() - flexboxLayout.getPaddingBottom()));
}

23. FlexboxAndroidTest#testAlignContent_spaceBetween_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_spaceBetween_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
}

24. FlexboxAndroidTest#testAlignContent_spaceBetween_withPadding()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_spaceBetween_withPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
}

25. FlexboxAndroidTest#testAlignContent_spaceBetween()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_spaceBetween() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
}

26. FlexboxAndroidTest#testAlignContent_flexEnd_parentPadding()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_flexEnd_parentPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_FLEX_END);
            flexboxLayout.setPadding(32, 32, 32, 32);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_FLEX_END));
    onView(withId(R.id.text1)).check(isAbove(withId(R.id.text3)));
    onView(withId(R.id.text2)).check(isAbove(withId(R.id.text3)));
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView3.getBottom(), is(flexboxLayout.getBottom() - flexboxLayout.getPaddingBottom()));
}

27. FlexboxAndroidTest#testJustifyContent_flexEnd_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_flexEnd_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_FLEX_END);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_FLEX_END));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isAbove(withId(R.id.text3)));
    onView(withId(R.id.text1)).check(isAbove(withId(R.id.text2)));
}

28. FlexboxAndroidTest#testJustifyContent_flexStart_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_flexStart_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_FLEX_START));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
}

29. FlexboxAndroidTest#testJustifyContent_flexEnd()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_flexEnd() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_FLEX_END);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_FLEX_END));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftOf(withId(R.id.text3)));
    onView(withId(R.id.text1)).check(isLeftOf(withId(R.id.text2)));
}

30. FlexboxAndroidTest#testJustifyContent_flexStart_withParentPadding()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_flexStart_withParentPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_with_parent_padding);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_FLEX_START));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    // Both the parent FrameLayout and the FlexboxLayout have different padding values
    // but the text1.getLeft should be the padding value for the FlexboxLayout, not including
    // the parent's padding value
    assertThat(text1.getLeft(), is(flexboxLayout.getPaddingLeft()));
    assertThat(text1.getTop(), is(flexboxLayout.getPaddingTop()));
}

31. FlexboxAndroidTest#testJustifyContent_flexStart()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_flexStart() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_FLEX_START));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
}

32. FlexboxAndroidTest#testFlexItem_match_parent_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexItem_match_parent_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_item_match_parent_direction_column);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    TextView text2 = (TextView) activity.findViewById(R.id.text2);
    TextView text3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(text1.getHeight(), is(flexboxLayout.getHeight()));
    assertThat(text2.getHeight(), is(flexboxLayout.getHeight()));
    assertThat(text3.getHeight(), is(flexboxLayout.getHeight()));
    assertThat(flexboxLayout.getWidth(), is(text1.getWidth() + text2.getWidth() + text3.getWidth()));
}

33. FlexboxAndroidTest#testFlexItem_match_parent()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexItem_match_parent() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_item_match_parent);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    TextView text2 = (TextView) activity.findViewById(R.id.text2);
    TextView text3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(text1.getWidth(), is(flexboxLayout.getWidth()));
    assertThat(text2.getWidth(), is(flexboxLayout.getWidth()));
    assertThat(text3.getWidth(), is(flexboxLayout.getWidth()));
    assertThat(flexboxLayout.getHeight(), is(text1.getHeight() + text2.getHeight() + text3.getHeight()));
}

34. FlexboxAndroidTest#testFlexWrap_wrap_reverse_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexWrap_wrap_reverse_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_wrap_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    // The width of the FlexboxLayout is not enough for placing the three text views.
    // There should be two flex lines same as FLEX_WRAP_WRAP, but the layout starts from right
    // to left in FLEX_WRAP_WRAP_REVERSE
    onView(withId(R.id.text3)).check(isLeftOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftOf(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
}

35. FlexboxAndroidTest#testFlexWrap_nowrap_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexWrap_nowrap_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_wrap_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_NOWRAP);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    // The height of the FlexboxLayout is not enough for placing the three text views.
    // But the flexWrap attribute is set to FLEX_WRAP_NOWRAP, the third text view is placed
    // below the second one and overflowing the parent FlexboxLayout.
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
}

36. FlexboxAndroidTest#testFlexWrap_wrap_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexWrap_wrap_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_wrap_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    // The height of the FlexboxLayout is not enough for placing the three text views.
    // The third text view should be placed right of the first one
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
}

37. FlexboxAndroidTest#testFlexWrap_wrap_reverse()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexWrap_wrap_reverse() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_wrap_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    // The width of the FlexboxLayout is not enough for placing the three text views.
    // There should be two flex lines same as FLEX_WRAP_WRAP, but the layout starts from bottom
    // to top in FLEX_WRAP_WRAP_REVERSE
    onView(withId(R.id.text3)).check(isAbove(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isAbove(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
}

38. FlexboxAndroidTest#testFlexWrap_nowrap()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexWrap_nowrap() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_wrap_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_NOWRAP);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    // The width of the FlexboxLayout is not enough for placing the three text views.
    // But the flexWrap attribute is set to FLEX_WRAP_NOWRAP, the third text view is placed
    // to the right of the second one and overflowing the parent FlexboxLayout.
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
}

39. FlexboxAndroidTest#testOrderAttribute_removeViewInMiddle()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testOrderAttribute_removeViewInMiddle() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_order_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.removeViewAt(2);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertNotNull(flexboxLayout);
    assertThat(flexboxLayout.getChildCount(), is(3));
    // order: -1, index 1
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2)));
    // order: 0, index 3
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(4)));
    // order: 2, index 0
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(1)));
}

40. FlexboxAndroidTest#testOrderAttribute_removeLastView()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testOrderAttribute_removeLastView() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_order_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.removeViewAt(flexboxLayout.getChildCount() - 1);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertNotNull(flexboxLayout);
    assertThat(flexboxLayout.getChildCount(), is(3));
    // order: -1, index 1
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2)));
    // order: 0, index 2
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(3)));
    // order: 2, index 0
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(1)));
}

41. FlexboxAndroidTest#testOrderAttribute_addViewInMiddle()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testOrderAttribute_addViewInMiddle() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_order_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            TextView fifth = createTextView(activity, String.valueOf(5), 0);
            // Add the new TextView in the middle of the indices
            flexboxLayout.addView(fifth, 2);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertNotNull(flexboxLayout);
    assertThat(flexboxLayout.getChildCount(), is(5));
    // order: -1, index 1
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2)));
    // order: 0, index 2
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(5)));
    // order: 0, index 3
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(3)));
    // order: 0, index 4
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(3)).getText().toString(), is(String.valueOf(4)));
    // order: 2, index 0
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(4)).getText().toString(), is(String.valueOf(1)));
}

42. FlexboxAndroidTest#testChangeOrder_fromChildSetLayoutParams()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testChangeOrder_fromChildSetLayoutParams() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_order_test);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    final FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getChildCount(), is(4));
    // order: -1, index 1
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2)));
    // order: 0, index 2
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(3)));
    // order: 0, index 3
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(4)));
    // order: 2, index 0
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(3)).getText().toString(), is(String.valueOf(1)));
    // By changing the order and calling the setLayoutParams, the reordered array in the
    // FlexboxLayout (mReordereredIndices) will be recreated without adding a new View.
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            View view1 = flexboxLayout.getChildAt(0);
            FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) view1.getLayoutParams();
            lp.order = -3;
            view1.setLayoutParams(lp);
        }
    });
    // order: -3, index 0
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(3)).getText().toString(), is(String.valueOf(1)));
    // order: -1, index 1
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2)));
    // order: 0, index 2
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(3)));
    // order: 1, index 3
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(4)));
}

43. FlexboxAndroidTest#testOrderAttribute_fromCode()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testOrderAttribute_fromCode() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_order_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            TextView fifth = createTextView(activity, String.valueOf(5), 0);
            TextView sixth = createTextView(activity, String.valueOf(6), -10);
            flexboxLayout.addView(fifth);
            flexboxLayout.addView(sixth);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getChildCount(), is(6));
    // order: -10, index 5
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(6)));
    // order: -1, index 1
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(2)));
    // order: 0, index 2
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(3)));
    // order: 0, index 4
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(3)).getText().toString(), is(String.valueOf(5)));
    // order: 1, index 3
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(4)).getText().toString(), is(String.valueOf(4)));
    // order: 2, index 0
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(5)).getText().toString(), is(String.valueOf(1)));
}

44. FlexboxAndroidTest#testOrderAttribute_fromLayoutXml()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testOrderAttribute_fromLayoutXml() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_order_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertNotNull(flexboxLayout);
    assertThat(flexboxLayout.getChildCount(), is(4));
    // order: -1, index 1
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2)));
    // order: 0, index 2
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(3)));
    // order: 1, index 3
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(4)));
    // order: 2, index 0
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(3)).getText().toString(), is(String.valueOf(1)));
}

45. MainActivityTest#testAlignContentSpinner()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@SuppressWarnings("unchecked")
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContentSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_align_content));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int spaceAroundPosition = spinnerAdapter.getPosition(activity.getString(R.string.space_around));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(spaceAroundPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_SPACE_AROUND));
    final int stretchPosition = spinnerAdapter.getPosition(activity.getString(R.string.stretch));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(stretchPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
}

46. MainActivityTest#testAlignItemsSpinner()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@SuppressWarnings("unchecked")
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItemsSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_align_items));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int baselinePosition = spinnerAdapter.getPosition(activity.getString(R.string.baseline));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(baselinePosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_BASELINE));
    final int flexEndPosition = spinnerAdapter.getPosition(activity.getString(R.string.flex_end));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(flexEndPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
}

47. MainActivityTest#testJustifyContentSpinner()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@SuppressWarnings("unchecked")
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContentSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_justify_content));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int spaceBetweenPosition = spinnerAdapter.getPosition(activity.getString(R.string.space_between));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(spaceBetweenPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN));
    final int centerPosition = spinnerAdapter.getPosition(activity.getString(R.string.center));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(centerPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_CENTER));
}

48. MainActivityTest#testFlexWrapSpinner()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@SuppressWarnings("unchecked")
@FlakyTest(tolerance = TOLERANCE)
public void testFlexWrapSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_flex_wrap));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int wrapReversePosition = spinnerAdapter.getPosition(activity.getString(R.string.wrap_reverse));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(wrapReversePosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
    final int noWrapPosition = spinnerAdapter.getPosition(activity.getString(R.string.nowrap));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(noWrapPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
}

49. MainActivityTest#testFlexDirectionSpinner()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@SuppressWarnings("unchecked")
@FlakyTest(tolerance = TOLERANCE)
public void testFlexDirectionSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_flex_direction));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int columnPosition = spinnerAdapter.getPosition(activity.getString(R.string.column));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(columnPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    final int rowReversePosition = spinnerAdapter.getPosition(activity.getString(R.string.row_reverse));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(rowReversePosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE));
}

50. MainActivityTest#testRemoveFlexItem()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testRemoveFlexItem() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    int beforeCount = flexboxLayout.getChildCount();
    onView(withId(R.id.remove_fab)).perform(click());
    assertThat(flexboxLayout.getChildCount(), is(beforeCount - 1));
}

51. MainActivityTest#testAddFlexItem()

Project: flexbox-layout
File: MainActivityTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAddFlexItem() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    int beforeCount = flexboxLayout.getChildCount();
    onView(withId(R.id.add_fab)).perform(click());
    assertThat(flexboxLayout.getChildCount(), is(beforeCount + 1));
}

52. FlexboxAndroidTest#testFirstItemLarge_vertical()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFirstItemLarge_vertical() throws Throwable {
    // This test verifies a empty flex line is not added when the first flex item is large
    // and judged wrapping is required with the first item.
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_first_item_large_vertical_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_STRETCH));
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
    // The sum of width of TextView1 and TextView2 is not enough for wrapping, but considering
    // the margin for the TextView2, the second TextView should be wrapped
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    TextView text2 = (TextView) activity.findViewById(R.id.text2);
    TextView text3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(flexboxLayout.getWidth(), is(text1.getWidth() + text2.getWidth() + text3.getWidth()));
}

53. FlexboxAndroidTest#testFirstItemLarge_horizontal()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFirstItemLarge_horizontal() throws Throwable {
    // This test verifies a empty flex line is not added when the first flex item is large
    // and judged wrapping is required with the first item.
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_first_item_large_horizontal_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_STRETCH));
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
    // The sum of width of TextView1 and TextView2 is not enough for wrapping, but considering
    // the margin for the TextView2, the second TextView should be wrapped
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    TextView text2 = (TextView) activity.findViewById(R.id.text2);
    TextView text3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(flexboxLayout.getHeight(), is(text1.getHeight() + text2.getHeight() + text3.getHeight()));
}

54. FlexboxAndroidTest#testWrapBefore_nowrap()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testWrapBefore_nowrap() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_wrap_before_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_NOWRAP);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    // layout_wrapBefore for the text2 and text3 are set to true, but the flexWrap is set to
    // FLEX_WRAP_NOWRAP, three text views should not be wrapped.
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
}

55. FlexboxAndroidTest#testWrapBefore()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testWrapBefore() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_wrap_before_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    // layout_wrapBefore for the text2 and text3 are set to true, the text2 and text3 should
    // be the first item for each flex line.
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    final TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(flexboxLayout.getHeight(), is(textView1.getHeight() + textView2.getHeight() + textView3.getHeight()));
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            FlexboxLayout.LayoutParams lp2 = (FlexboxLayout.LayoutParams) textView2.getLayoutParams();
            lp2.wrapBefore = false;
            textView2.setLayoutParams(lp2);
        }
    });
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    assertThat(flexboxLayout.getHeight(), is(textView1.getHeight() + textView3.getHeight()));
}

56. FlexboxAndroidTest#testView_visibility_invisible()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testView_visibility_invisible() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_views_visibility_invisible);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    // The text1 and text2's visibility are invisible, these views take space like visible views
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getVisibility(), is(View.INVISIBLE));
    assertThat(textView2.getVisibility(), is(View.INVISIBLE));
    assertThat(textView3.getTop(), is(textView1.getBottom()));
}

57. FlexboxAndroidTest#testView_visibility_gone_first_item_in_flex_line_vertical()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testView_visibility_gone_first_item_in_flex_line_vertical() throws Throwable {
    // This test verifies if the FlexboxLayout is visible when the visibility of the first
    // flex item in the second flex line (or arbitrary flex lines other than the first flex line)
    // is set to "gone"
    // There was an issue reported for that
    // https://github.com/google/flexbox-layout/issues/47
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_visibility_gone_first_item_in_flex_line_column);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertTrue(flexboxLayout.getWidth() > 0);
    assertThat(flexboxLayout.getWidth(), is(textView1.getWidth() + textView3.getWidth()));
}

58. FlexboxAndroidTest#testView_visibility_gone_first_item_in_flex_line_horizontal()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testView_visibility_gone_first_item_in_flex_line_horizontal() throws Throwable {
    // This test verifies if the FlexboxLayout is visible when the visibility of the first
    // flex item in the second flex line (or arbitrary flex lines other than the first flex line)
    // is set to "gone"
    // There was an issue reported for that
    // https://github.com/google/flexbox-layout/issues/47
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_visibility_gone_first_item_in_flex_line_row);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertTrue(flexboxLayout.getHeight() > 0);
    assertThat(flexboxLayout.getHeight(), is(textView1.getHeight() + textView3.getHeight()));
}

59. FlexboxAndroidTest#testView_visibility_gone()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testView_visibility_gone() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_views_visibility_gone);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    // The text1 and text2's visibility are gone, so the visible view starts from text3
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text4)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text4)).check(isRightOf(withId(R.id.text3)));
    onView(withId(R.id.text5)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text5)).check(isBelow(withId(R.id.text3)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    TextView textView4 = (TextView) activity.findViewById(R.id.text4);
    TextView textView5 = (TextView) activity.findViewById(R.id.text5);
    assertThat(textView1.getVisibility(), is(View.GONE));
    assertThat(textView2.getVisibility(), is(View.GONE));
    assertThat(textView4.getLeft(), is(textView3.getRight()));
    assertThat(textView5.getTop(), is(textView3.getBottom()));
}

60. FlexboxAndroidTest#testFlexBasisPercent_nowrap_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexBasisPercent_nowrap_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_basis_percent_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_NOWRAP);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    // The text1 length is 50%, the text2 length is 60% and the text3 has the fixed height,
    // but the flex wrap attribute is FLEX_WRAP_NOWRAP, and flexShrink attributes for all
    // children are the default value (1), three text views are shrank to fit in a single
    // flex line.
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int totalHeight = textView1.getHeight() + textView2.getHeight() + textView3.getHeight();
    // Allowing minor different length with the flex container since the sum of the three text
    // views width is not always the same as the flex container's main size caused by round
    // errors in calculating the percent lengths.
    assertTrue(totalHeight >= flexboxLayout.getHeight() - 3 || totalHeight <= flexboxLayout.getHeight() + 3);
}

61. FlexboxAndroidTest#testFlexBasisPercent_wrap_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexBasisPercent_wrap_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_basis_percent_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    // The text1 length is 50%, the text2 length is 60% and the wrap property is FLEX_WRAP_WRAP,
    // the text2 should be on the second flex line.
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    FlexboxLayout.LayoutParams lp1 = (FlexboxLayout.LayoutParams) textView1.getLayoutParams();
    FlexboxLayout.LayoutParams lp2 = (FlexboxLayout.LayoutParams) textView2.getLayoutParams();
    assertThat(textView1.getHeight(), is(Math.round(flexboxLayout.getHeight() * lp1.flexBasisPercent)));
    assertThat(textView2.getHeight(), is(Math.round(flexboxLayout.getHeight() * lp2.flexBasisPercent)));
}

62. FlexboxAndroidTest#testFlexBasisPercent_nowrap()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexBasisPercent_nowrap() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_basis_percent_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_NOWRAP);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    // The text1 length is 50%, the text2 length is 60% and the text3 has the fixed width,
    // but the flex wrap attribute is FLEX_WRAP_NOWRAP, and flexShrink attributes for all
    // children are the default value (1), three text views are shrank to fit in a single flex
    // line.
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int totalWidth = textView1.getWidth() + textView2.getWidth() + textView3.getWidth();
    // Allowing minor different length with the flex container since the sum of the three text
    // views width is not always the same as the flex container's main size caused by round
    // errors in calculating the percent lengths.
    assertTrue(totalWidth >= flexboxLayout.getWidth() - 3 || totalWidth <= flexboxLayout.getWidth() + 3);
}

63. FlexboxAndroidTest#testFlexBasisPercent_wrap()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexBasisPercent_wrap() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_basis_percent_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    // The text1 length is 50%, the text2 length is 60% and the wrap property is FLEX_WRAP_WRAP,
    // the text2 should be on the second flex line.
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    FlexboxLayout.LayoutParams lp1 = (FlexboxLayout.LayoutParams) textView1.getLayoutParams();
    FlexboxLayout.LayoutParams lp2 = (FlexboxLayout.LayoutParams) textView2.getLayoutParams();
    assertThat(textView1.getWidth(), is(Math.round(flexboxLayout.getWidth() * lp1.flexBasisPercent)));
    assertThat(textView2.getWidth(), is(Math.round(flexboxLayout.getWidth() * lp2.flexBasisPercent)));
}

64. FlexboxAndroidTest#testAlignItems_center_wrapReverse_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_center_wrapReverse_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_CENTER);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_CENTER));
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getWidth() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    // All TextView's widths are the same. No issues should be found if using the first
    // TextView to calculate the space above and below
    int spaceLeftAndRight = (flexLineSize - textView1.getWidth()) / 2;
    assertThat(textView1.getWidth(), not(flexLineSize));
    assertThat(textView2.getWidth(), not(flexLineSize));
    assertThat(textView3.getWidth(), not(flexLineSize));
    int lowerBound = flexboxLayout.getWidth() - spaceLeftAndRight - 1;
    int upperBound = flexboxLayout.getWidth() - spaceLeftAndRight + 1;
    assertTrue(lowerBound <= textView1.getRight() && textView1.getRight() <= upperBound);
    assertTrue(lowerBound <= textView2.getRight() && textView2.getRight() <= upperBound);
    assertTrue(flexboxLayout.getWidth() - flexLineSize - spaceLeftAndRight - 1 <= textView3.getRight() && textView3.getRight() <= flexboxLayout.getWidth() - flexLineSize - spaceLeftAndRight + 1);
}

65. FlexboxAndroidTest#testAlignItems_flexEnd_wrapReverse_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_flexEnd_wrapReverse_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getWidth() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getWidth(), not(flexLineSize));
    assertThat(textView2.getWidth(), not(flexLineSize));
    assertThat(textView3.getWidth(), not(flexLineSize));
    int lowerBound = flexboxLayout.getWidth() - flexLineSize - 1;
    int upperBound = flexboxLayout.getWidth() - flexLineSize + 1;
    assertTrue(lowerBound <= textView1.getLeft() && textView1.getLeft() <= upperBound);
    assertTrue(lowerBound <= textView2.getLeft() && textView2.getLeft() <= upperBound);
    assertThat(textView3.getLeft(), is(0));
}

66. FlexboxAndroidTest#testAlignItems_center_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_center_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_CENTER);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_CENTER));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getWidth() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    // All TextView's widths are the same. No issues should be found if using the first
    // TextView to calculate the space left and right
    int spaceLeftAndRight = (flexLineSize - textView1.getWidth()) / 2;
    assertThat(textView1.getWidth(), not(flexLineSize));
    assertThat(textView2.getWidth(), not(flexLineSize));
    assertThat(textView3.getWidth(), not(flexLineSize));
    assertTrue(spaceLeftAndRight - 1 <= textView1.getLeft() && textView1.getLeft() <= spaceLeftAndRight + 1);
    assertTrue(spaceLeftAndRight - 1 <= textView2.getLeft() && textView2.getLeft() <= spaceLeftAndRight + 1);
    assertTrue(flexLineSize + spaceLeftAndRight - 1 <= textView3.getLeft() && textView2.getLeft() <= flexLineSize + spaceLeftAndRight + 1);
}

67. FlexboxAndroidTest#testAlignItems_flexEnd_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_flexEnd_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getWidth(), not(flexLineSize));
    assertThat(textView2.getWidth(), not(flexLineSize));
    assertThat(textView3.getWidth(), not(flexLineSize));
    assertTrue(flexLineSize - 1 <= textView1.getRight() && textView1.getRight() <= flexLineSize + 1);
    assertTrue(flexLineSize - 1 <= textView2.getRight() && textView2.getRight() <= flexLineSize + 1);
    assertThat(textView3.getRight(), is(flexboxLayout.getRight()));
}

68. FlexboxAndroidTest#testAlignItems_flexStart_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_flexStart_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_START));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getWidth() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getWidth(), not(flexLineSize));
    assertThat(textView2.getWidth(), not(flexLineSize));
    assertThat(textView3.getWidth(), not(flexLineSize));
    assertTrue(flexLineSize - 1 <= textView3.getLeft() && textView3.getLeft() <= flexLineSize + 1);
}

69. FlexboxAndroidTest#testAlignItems_center_wrapReverse()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_center_wrapReverse() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_CENTER);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_CENTER));
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    // All TextView's heights are the same. No issues should be found if using the first
    // TextView to calculate the space above and below
    int spaceAboveAndBelow = (flexLineSize - textView1.getHeight()) / 2;
    assertThat(textView1.getHeight(), not(flexLineSize));
    assertThat(textView2.getHeight(), not(flexLineSize));
    assertThat(textView3.getHeight(), not(flexLineSize));
    int lowerBound = flexboxLayout.getHeight() - spaceAboveAndBelow - 1;
    int upperBound = flexboxLayout.getHeight() - spaceAboveAndBelow + 1;
    assertTrue(lowerBound <= textView1.getBottom() && textView1.getBottom() <= upperBound);
    assertTrue(lowerBound <= textView2.getBottom() && textView2.getBottom() <= upperBound);
    assertTrue(flexboxLayout.getHeight() - flexLineSize - spaceAboveAndBelow - 1 <= textView3.getBottom() && textView3.getBottom() <= flexboxLayout.getHeight() - flexLineSize - spaceAboveAndBelow + 1);
}

70. FlexboxAndroidTest#testAlignItems_flexEnd_wrapReverse()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_flexEnd_wrapReverse() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getHeight(), not(flexLineSize));
    assertThat(textView2.getHeight(), not(flexLineSize));
    assertThat(textView3.getHeight(), not(flexLineSize));
    int lowerBound = flexboxLayout.getHeight() - flexLineSize - 1;
    int upperBound = flexboxLayout.getHeight() - flexLineSize + 1;
    assertTrue(lowerBound <= textView1.getTop() && textView1.getTop() <= upperBound);
    assertTrue(lowerBound <= textView2.getTop() && textView2.getTop() <= upperBound);
    assertThat(textView3.getTop(), is(0));
}

71. FlexboxAndroidTest#testAlignItems_center()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_center() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_CENTER);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_CENTER));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    // All TextView's heights are the same. No issues should be found if using the first
    // TextView to calculate the space above and below
    int spaceAboveAndBelow = (flexLineSize - textView1.getHeight()) / 2;
    assertThat(textView1.getHeight(), not(flexLineSize));
    assertThat(textView2.getHeight(), not(flexLineSize));
    assertThat(textView3.getHeight(), not(flexLineSize));
    assertTrue(spaceAboveAndBelow - 1 <= textView1.getTop() && textView1.getTop() <= spaceAboveAndBelow + 1);
    assertTrue(spaceAboveAndBelow - 1 <= textView2.getTop() && textView2.getTop() <= spaceAboveAndBelow + 1);
    assertTrue(flexLineSize + spaceAboveAndBelow - 1 <= textView3.getTop() && textView3.getTop() <= flexLineSize + spaceAboveAndBelow + 1);
}

72. FlexboxAndroidTest#testAlignItems_flexEnd_parentPadding_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_flexEnd_parentPadding_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_parent_padding_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    assertThat(textView1.getRight(), is(flexboxLayout.getRight() - flexboxLayout.getPaddingRight()));
    assertThat(textView2.getRight(), is(flexboxLayout.getRight() - flexboxLayout.getPaddingRight()));
}

73. FlexboxAndroidTest#testAlignItems_flexEnd()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_flexEnd() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getHeight(), not(flexLineSize));
    assertThat(textView2.getHeight(), not(flexLineSize));
    assertThat(textView3.getHeight(), not(flexLineSize));
    assertTrue(flexLineSize - 1 <= textView1.getBottom() && textView1.getBottom() <= flexLineSize + 1);
    assertTrue(flexLineSize - 1 <= textView2.getBottom() && textView2.getBottom() <= flexLineSize + 1);
    assertThat(textView3.getBottom(), is(flexboxLayout.getBottom()));
}

74. FlexboxAndroidTest#testAlignItems_flexStart()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_flexStart() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_items_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_START));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getHeight(), not(flexLineSize));
    assertThat(textView2.getHeight(), not(flexLineSize));
    assertThat(textView3.getHeight(), not(flexLineSize));
    assertTrue(flexLineSize - 1 <= textView3.getTop() && textView3.getTop() <= flexLineSize + 1);
}

75. FlexboxAndroidTest#testAlignSelf_stretch_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignSelf_stretch_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_self_stretch_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    // There should be 2 flex lines in the layout with the given layout.
    // Only the first TextView's alignSelf is set to ALIGN_SELF_STRETCH
    int flexLineSize = flexboxLayout.getWidth() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertTrue(flexLineSize - 1 <= textView1.getWidth() && textView1.getWidth() <= flexLineSize + 1);
    assertThat(textView2.getWidth(), not(flexLineSize));
    assertThat(textView3.getWidth(), not(flexLineSize));
}

76. FlexboxAndroidTest#testAlignSelf_stretch()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignSelf_stretch() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_self_stretch_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    // There should be 2 flex lines in the layout with the given layout.
    // Only the first TextView's alignSelf is set to ALIGN_SELF_STRETCH
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertTrue(flexLineSize - 1 <= textView1.getHeight() && textView1.getHeight() <= flexLineSize + 1);
    assertThat(textView2.getHeight(), not(flexLineSize));
    assertThat(textView3.getHeight(), not(flexLineSize));
}

77. FlexboxAndroidTest#testAlignItems_stretch()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignItems_stretch() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_stretch_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_STRETCH));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertTrue(flexLineSize - 1 <= textView1.getHeight() && textView1.getHeight() <= flexLineSize + 1);
    assertTrue(flexLineSize - 1 <= textView2.getHeight() && flexLineSize <= flexLineSize + 1);
    assertTrue(flexLineSize - 1 <= textView3.getHeight() && textView3.getHeight() <= flexLineSize + 1);
}

78. FlexboxAndroidTest#testAlignContent_stretch_parentWrapContent_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_stretch_parentWrapContent_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            ViewGroup.LayoutParams parentLp = flexboxLayout.getLayoutParams();
            parentLp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            flexboxLayout.setLayoutParams(parentLp);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    // the third TextView is wrapped to the next flex line
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    // alignContent is only effective if the parent's height/width mode is MeasureSpec.EXACTLY.
    // The size of the flex lines don't change even if the alingContent is set to
    // ALIGN_CONTENT_STRETCH
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView3.getLeft(), is(textView1.getWidth()));
}

79. FlexboxAndroidTest#testAlignContent_spaceAround_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_spaceAround_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_SPACE_AROUND);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_SPACE_AROUND));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int spaceAround = flexboxLayout.getWidth() - textView1.getWidth() - textView3.getWidth();
    // Divide by the number of flex lines * 2
    spaceAround /= 4;
    assertTrue(spaceAround - 1 <= textView1.getLeft() && textView1.getLeft() <= spaceAround + 1);
    int spaceLowerBound = textView1.getRight() + spaceAround * 2 - 1;
    int spaceUpperBound = textView1.getRight() + spaceAround * 2 + 1;
    assertTrue(spaceLowerBound <= textView3.getLeft() && textView3.getLeft() <= spaceUpperBound);
}

80. FlexboxAndroidTest#testAlignContent_center_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_center_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_CENTER);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_CENTER));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int spaceLeftAndRight = flexboxLayout.getWidth() - textView1.getWidth() - textView3.getWidth();
    spaceLeftAndRight /= 2;
    assertTrue(spaceLeftAndRight - 1 <= textView1.getLeft() && textView1.getLeft() <= spaceLeftAndRight + 1);
    int spaceLowerBound = flexboxLayout.getRight() - spaceLeftAndRight - 1;
    int spaceUpperBound = flexboxLayout.getRight() - spaceLeftAndRight + 1;
    assertTrue(spaceLowerBound <= textView3.getRight() && textView3.getRight() <= spaceUpperBound);
}

81. FlexboxAndroidTest#testAlignContent_flexEnd_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_flexEnd_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_FLEX_END);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_FLEX_END));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftOf(withId(R.id.text3)));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text3)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getRight(), is(flexboxLayout.getRight() - textView3.getWidth()));
}

82. FlexboxAndroidTest#testAlignContent_flexStart_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_flexStart_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_FLEX_START);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_FLEX_START));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    // the third TextView is wrapped to the next flex line
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView3.getLeft(), is(textView1.getWidth()));
}

83. FlexboxAndroidTest#testAlignContent_stretch_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_stretch_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    // the third TextView is wrapped to the next flex line
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int flexLineCrossSize = flexboxLayout.getWidth() / 2;
    // Two flex line's cross sizes are expanded to the half of the width of the FlexboxLayout.
    // The third textView's left should be aligned with the second flex line.
    assertThat(textView3.getLeft(), is(flexLineCrossSize));
}

84. FlexboxAndroidTest#testAlignContent_stretch_parentWrapContent()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_stretch_parentWrapContent() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            ViewGroup.LayoutParams parentLp = flexboxLayout.getLayoutParams();
            parentLp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            flexboxLayout.setLayoutParams(parentLp);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    // the third TextView is wrapped to the next flex line
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    // alignContent is only effective if the parent's height/width mode is MeasureSpec.EXACTLY.
    // The size of the flex lines don't change even if the alingContent is set to
    // ALIGN_CONTENT_STRETCH
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView3.getTop(), is(textView1.getHeight()));
}

85. FlexboxAndroidTest#testAlignContent_spaceAround()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_spaceAround() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_SPACE_AROUND);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_SPACE_AROUND));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int spaceAround = flexboxLayout.getHeight() - textView1.getHeight() - textView3.getHeight();
    // Divide by the number of flex lines * 2
    spaceAround /= 4;
    assertTrue(spaceAround - 1 <= textView1.getTop() && textView1.getTop() <= spaceAround + 1);
    int spaceLowerBound = textView1.getBottom() + spaceAround * 2 - 1;
    int spaceUpperBound = textView1.getBottom() + spaceAround * 2 + 1;
    assertTrue(spaceLowerBound <= textView3.getTop() && textView3.getTop() <= spaceUpperBound);
}

86. FlexboxAndroidTest#testAlignContent_center()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_center() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_CENTER);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_CENTER));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int spaceAboveAndBottom = flexboxLayout.getHeight() - textView1.getHeight() - textView3.getHeight();
    spaceAboveAndBottom /= 2;
    assertTrue(spaceAboveAndBottom - 1 <= textView1.getTop() && textView1.getTop() <= spaceAboveAndBottom + 1);
    assertTrue(flexboxLayout.getBottom() - spaceAboveAndBottom - 1 <= textView3.getBottom() && textView3.getBottom() <= flexboxLayout.getBottom() - spaceAboveAndBottom + 1);
}

87. FlexboxAndroidTest#testAlignContent_flexEnd_parentPadding_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_flexEnd_parentPadding_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_FLEX_END);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
            flexboxLayout.setPadding(32, 32, 32, 32);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_FLEX_END));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isLeftOf(withId(R.id.text3)));
    onView(withId(R.id.text2)).check(isLeftOf(withId(R.id.text3)));
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView3.getRight(), is(flexboxLayout.getRight() - flexboxLayout.getPaddingRight()));
}

88. FlexboxAndroidTest#testAlignContent_flexEnd()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_flexEnd() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_FLEX_END);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_FLEX_END));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isAbove(withId(R.id.text3)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isAbove(withId(R.id.text3)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getBottom(), is(flexboxLayout.getBottom() - textView3.getHeight()));
}

89. FlexboxAndroidTest#testAlignContent_flexStart()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_flexStart() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_FLEX_START);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_FLEX_START));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    // the third TextView is wrapped to the next flex line
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView3.getTop(), is(textView1.getHeight()));
}

90. FlexboxAndroidTest#testAlignContent_stretch()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testAlignContent_stretch() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_align_content_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    // the third TextView is wrapped to the next flex line
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int flexLineCrossSize = flexboxLayout.getHeight() / 2;
    // Two flex line's cross sizes are expanded to the half of the height of the FlexboxLayout.
    // The third textView's top should be aligned witht the second flex line.
    assertThat(textView3.getTop(), is(flexLineCrossSize));
}

91. FlexboxAndroidTest#testFlexGrow_including_view_gone()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexGrow_including_view_gone() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_grow_test);
            TextView textView2 = (TextView) activity.findViewById(R.id.text2);
            textView2.setVisibility(View.GONE);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    // the third TextView is expanded to the right edge of the FlexboxLayout
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView2.getVisibility(), is(View.GONE));
    assertThat(textView3.getWidth(), is(flexboxLayout.getWidth() - textView1.getWidth()));
}

92. FlexboxAndroidTest#testFlexGrow_withExactParentLength_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexGrow_withExactParentLength_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_grow_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    // the third TextView is expanded to the bottom edge of the FlexboxLayout
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView3.getHeight(), is(flexboxLayout.getHeight() - textView1.getHeight() - textView2.getHeight()));
}

93. FlexboxAndroidTest#testFlexGrow_withExactParentLength()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexGrow_withExactParentLength() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_flex_grow_test);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    // the third TextView is expanded to the right edge of the FlexboxLayout
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView3.getWidth(), is(flexboxLayout.getWidth() - textView1.getWidth() - textView2.getWidth()));
}

94. FlexboxAndroidTest#testJustifyContent_spaceAround_flexDirection_column_withPadding()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_spaceAround_flexDirection_column_withPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    final int padding = 40;
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
            flexboxLayout.setPadding(padding, padding, padding, padding);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    float space = flexboxLayout.getHeight() - textView1.getHeight() - textView2.getHeight() - textView3.getHeight() - padding * 2;
    // Divide by the number of children * 2
    space = space / 6;
    assertTrue(space - 1 <= textView1.getTop() - padding && textView1.getTop() - padding <= space + 1);
    float spaceLowerBound = space * 2 - 1;
    float spaceUpperBound = space * 2 + 1;
    assertTrue(spaceLowerBound <= textView2.getTop() - textView1.getBottom() && textView2.getTop() - textView1.getBottom() <= spaceUpperBound);
    assertTrue(spaceLowerBound <= textView3.getTop() - textView2.getBottom() && textView3.getTop() - textView2.getBottom() <= spaceUpperBound);
    assertTrue(space - 1 <= flexboxLayout.getBottom() - textView3.getBottom() - padding && flexboxLayout.getBottom() - textView3.getBottom() - padding <= space + 1);
}

95. FlexboxAndroidTest#testJustifyContent_spaceAround_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_spaceAround_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    float space = flexboxLayout.getHeight() - textView1.getHeight() - textView2.getHeight() - textView3.getHeight();
    // Divide by the number of children * 2
    space = space / 6;
    assertTrue(space - 1 <= textView1.getTop() && textView1.getTop() <= space + 1);
    float spaceLowerBound = space * 2 - 1;
    float spaceUpperBound = space * 2 + 1;
    assertTrue(spaceLowerBound <= textView2.getTop() - textView1.getBottom() && textView2.getTop() - textView1.getBottom() <= spaceUpperBound);
    assertTrue(spaceLowerBound <= textView3.getTop() - textView2.getBottom() && textView3.getTop() - textView2.getBottom() <= spaceUpperBound);
    assertTrue(space - 1 <= flexboxLayout.getBottom() - textView3.getBottom() && flexboxLayout.getBottom() - textView3.getBottom() <= space + 1);
}

96. FlexboxAndroidTest#testJustifyContent_spaceBetween_flexDirection_column_withPadding()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_spaceBetween_flexDirection_column_withPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    final int padding = 40;
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
            flexboxLayout.setPadding(padding, padding, padding, padding);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int space = flexboxLayout.getHeight() - textView1.getHeight() - textView2.getHeight() - textView3.getHeight() - padding * 2;
    space = space / 2;
    assertThat(textView1.getTop(), is(padding));
    assertThat(flexboxLayout.getBottom() - textView3.getBottom(), is(padding));
    assertTrue(space - 1 <= textView2.getTop() - textView1.getBottom() && textView2.getTop() - textView1.getBottom() <= space + 1);
    assertTrue(space - 1 <= textView3.getTop() - textView2.getBottom() && textView3.getTop() - textView2.getBottom() <= space + 1);
}

97. FlexboxAndroidTest#testJustifyContent_spaceBetween_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_spaceBetween_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int space = flexboxLayout.getHeight() - textView1.getHeight() - textView2.getHeight() - textView3.getHeight();
    space = space / 2;
    assertTrue(space - 1 <= textView2.getTop() - textView1.getBottom() && textView2.getTop() - textView1.getBottom() <= space + 1);
    assertTrue(space - 1 <= textView3.getTop() - textView2.getBottom() && textView3.getTop() - textView2.getBottom() <= space + 1);
}

98. FlexboxAndroidTest#testJustifyContent_center_flexDirection_column()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_center_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_CENTER);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_CENTER));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int space = flexboxLayout.getHeight() - textView1.getHeight() - textView2.getHeight() - textView3.getHeight();
    space = space / 2;
    assertTrue(space - 1 <= textView1.getTop() && textView1.getTop() <= space + 1);
    assertTrue(space - 1 <= flexboxLayout.getBottom() - textView3.getBottom() && flexboxLayout.getBottom() - textView3.getBottom() <= space + 1);
}

99. FlexboxAndroidTest#testJustifyContent_spaceAround_withPadding()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_spaceAround_withPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    final int padding = 40;
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND);
            flexboxLayout.setPadding(padding, padding, padding, padding);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int space = flexboxLayout.getWidth() - textView1.getWidth() - textView2.getWidth() - textView3.getWidth() - padding * 2;
    // Divide by the number of children * 2
    space = space / 6;
    assertTrue(space - 1 <= textView1.getLeft() - padding && textView1.getLeft() - padding <= space + 1);
    int spaceLowerBound = space * 2 - 1;
    int spaceUpperBound = space * 2 + 1;
    assertTrue(spaceLowerBound <= textView2.getLeft() - textView1.getRight() && textView2.getLeft() - textView1.getRight() <= spaceUpperBound);
    assertTrue(spaceLowerBound <= textView3.getLeft() - textView2.getRight() && textView3.getLeft() - textView2.getRight() <= spaceUpperBound);
    assertTrue(space - 1 <= flexboxLayout.getRight() - textView3.getRight() - padding && flexboxLayout.getRight() - textView3.getRight() - padding <= space + 1);
}

100. FlexboxAndroidTest#testJustifyContent_spaceAround()

Project: flexbox-layout
File: FlexboxAndroidTest.java
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testJustifyContent_spaceAround() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    mActivityRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activity.setContentView(R.layout.activity_justify_content_test);
            FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND);
        }
    });
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int space = flexboxLayout.getWidth() - textView1.getWidth() - textView2.getWidth() - textView3.getWidth();
    // Divide by the number of children * 2
    space = space / 6;
    assertTrue(space - 1 <= textView1.getLeft() && textView1.getLeft() <= space + 1);
    int spaceLowerBound = space * 2 - 1;
    int spaceUpperBound = space * 2 + 1;
    assertTrue(spaceLowerBound <= textView2.getLeft() - textView1.getRight() && textView2.getLeft() - textView1.getRight() <= spaceUpperBound);
    assertTrue(spaceLowerBound <= textView3.getLeft() - textView2.getRight() && textView3.getLeft() - textView2.getRight() <= spaceUpperBound);
    assertTrue(space - 1 <= flexboxLayout.getRight() - textView3.getRight() && flexboxLayout.getRight() - textView3.getRight() <= space + 1);
}