package com.nikhaldimann.viewselector.test.abstrakt;

import static com.nikhaldimann.viewselector.ViewSelectorAssertions.assertThatSelection;
import junit.framework.AssertionFailedError;

import org.junit.Test;

import android.widget.LinearLayout;
import android.widget.TextView;

import com.nikhaldimann.viewselector.test.util.ViewSelectorAndroidTestCase;

public abstract class AbstractViewSelectionAssertTest extends ViewSelectorAndroidTestCase {

    /**
     * Fails with a RuntimeException, so we can distinguish this from planned
     * assertion failures.
     */
    private void failHard() {
        throw new RuntimeException("Failed to cause an assertion failure");
    }

    @Test
    public void testHasAttributeEqualTo() {
        TextView view = viewFactory.createTextView();
        view.setText("foo");
        view.setTag("bar");
        assertThatSelection("TextView", view).hasAttributeEqualTo("text", "foo");
        assertThatSelection("TextView", view).hasAttributeEqualTo("tag", "bar");
    }

    @Test
    public void testFailingHasAttributeEqualTo() {
        try {
            assertThatSelection("TextView", viewFactory.createTextView())
                .hasAttributeEqualTo("text", "foo");
            failHard();
        } catch (AssertionFailedError ex) {
            // expected
        }
    }

    @Test
    public void testHasAttributesEqualTo() {
        TextView view = viewFactory.createTextView();
        view.setText("foo");
        TextView view2 = viewFactory.createTextView();
        view2.setText("bar");
        LinearLayout root = viewFactory.createLinearLayout();
        root.addView(view);
        root.addView(view2);
        assertThatSelection("TextView", root)
            .hasSize(2)
            .hasAttributesEqualTo("text", "foo", "bar");
    }

    @Test
    public void testFailingHasAttributesEqualTo() {
        TextView view = viewFactory.createTextView();
        view.setText("foo");
        TextView view2 = viewFactory.createTextView();
        view.setText("bar");
        LinearLayout root = viewFactory.createLinearLayout();
        root.addView(view);
        root.addView(view2);
        try {
            assertThatSelection("TextView", root).hasAttributesEqualTo("text", "foo", "baz");
            failHard();
        } catch (AssertionFailedError ex) {
            // expected
        }
    }

}

@@ -274,16 +274,90 @@
 tView;%0A%0A
+import com.nikhaldimann.viewselector.attributes.AttributeAccessException;%0A
 import c
@@ -1390,32 +1390,350 @@
        %7D%0A    %7D%0A%0A
+    @Test%0A    public void testNonExistentHasAttributeEqualTo() %7B%0A        try %7B%0A            assertThatSelection(%22TextView%22, viewFactory.createTextView())%0A                .hasAttributeEqualTo(%22foo%22, %22bar%22);%0A            failHard();%0A        %7D catch (AttributeAccessException ex) %7B%0A            // expected%0A        %7D%0A    %7D%0A%0A
     @Test%0A    pu

Test attribute assertions when attributes don't exist