Code example for ViewGroup

Methods: addViewremoveAllViews, findViewWithTag

0
        assertThat((ViewGroup) root.findViewWithTag("tag23")).isEqualTo(null);
    } 
 
    @Test 
    public void shouldfindViewWithTagFromCorrectViewGroup() { 
        root.removeAllViews();
        child1.setTag("tag1");
        child2.setTag("tag2");
        child3.setTag("tag3");
        root.addView(child1);
        root.addView(child2);
        root.addView(child3);
 
        child3a.setTag("tag1");
        child3b.setTag("tag2");
 
        //can find views by tag from root 
        assertThat(root.findViewWithTag("tag1")).isSameAs(child1);
        assertThat(root.findViewWithTag("tag2")).isSameAs((View) child2);
        assertThat((ViewGroup) root.findViewWithTag("tag3")).isSameAs(child3);
 
        //can find views by tag from child3 
        assertThat(child3.findViewWithTag("tag1")).isSameAs(child3a);
        assertThat(child3.findViewWithTag("tag2")).isSameAs(child3b);
    }