Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Testing in Android UI Testing with Espresso Testing the Spinner

Generic matchesSafely method when Overriding a BoundedMatcher

Hi, Is there is away where I can implement the matchesSafely method without the need of use an outer value to compere with. In the video Testing Spinner we were forced to compare with the outer givenColor. Thanks!

 final int givenColour = Color.GREEN;
// Arrange
        BoundedMatcher backgoundColourMatcher = new BoundedMatcher<View,LinearLayout>(LinearLayout.class) {
            @Override
            protected boolean matchesSafely(LinearLayout linearLayout) {
              int actualColour =  ((ColorDrawable)linearLayout.getBackground()).getColor();

//Here we are using a outer value
 return givenColour == actualColour;
            }

            @Override
            public void describeTo(Description description) {
//Here we are using a outer value               
 description.appendText("Background color should be equal: "+ givenColour);
            }
        };
        onView(withId(R.id.linearLayout)).check()
    }