Android Open Source - android-view-selector View Selector Assertions






From Project

Back to project page android-view-selector.

License

The source code is released under:

Copyright (c) 2013 Nik Haldimann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Soft...

If you think the Android project android-view-selector listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nikhaldimann.viewselector;
/*from  w  w  w .  jav a 2s  .  c om*/
import org.fest.assertions.api.Assertions;

import android.app.Activity;
import android.view.View;

import com.nikhaldimann.viewselector.attributes.ViewSelectionAttribute;
import com.nikhaldimann.viewselector.selection.ViewSelection;

/**
 * Static assertion entry points for fluent FEST-style assertions. Example usage:
 *
 * <pre>
 *    // Assert that activity has 5 views that are TextViews
 *    assertThat(selection("TextView", activity)).hasSize(5);
 *
 *    // ... or equivalent:
 *    assertThatSelection("TextView", activity).hasSize(5);
 *
 *    // Assert that all TextViews in activity have the text "Hello World"
 *    assertThatSelection("TextView", activity).attribute("text")
 *        .containsOnly("Hello World");
 *
 *    // ... or equivalent:
 *    assertThat(extractAttribute("text").from(selection("TextView", activity)))
 *        .containsOnly("Hello World");
 *
 *    // Assert that the 3 TextViews in activity have the texts "foo", "bar", "baz",
 *    // in that order
 *    assertThatSelection("TextView", activity).attribute("text")
 *        .containsExactly("foo", "bar", "baz");
 * </pre>
 */
public class ViewSelectorAssertions extends Assertions {

    private ViewSelectorAssertions() { }

    /**
     * Fluent assertion entry point for {@link ViewSelection}. Often used together
     * with {@link #selection(String, Activity)} to create the selection.
     */
    public static ViewSelectionAssert assertThat(ViewSelection actual) {
        return new ViewSelectionAssert(actual);
    }

    /**
     * Fluent assertion entry point for a selection of views from the given activity
     * based on the given selector. It may be helpful to statically import this rather
     * than {@link #assertThat(ViewSelection)} to avoid conflicts with other statically
     * imported {@code assertThat()} methods.
     */
    public static ViewSelectionAssert assertThatSelection(String selector, Activity activity) {
        return assertThat(selection(selector, activity));
    }

    /**
     * Fluent assertion entry point for a selection of views from the given view
     * based on the given selector. It may be helpful to statically import this rather
     * than {@link #assertThat(ViewSelection)} to avoid conflicts with other statically
     * imported {@code assertThat()} methods.
     */
    public static ViewSelectionAssert assertThatSelection(String selector, View view) {
        return assertThat(selection(selector, view));
    }

    /**
     * @return the selection of views from the given activity based on the given selector
     */
    public static ViewSelection selection(String selector, Activity activity) {
        return selection(selector, activity.findViewById(android.R.id.content));
    }

    /**
     * @return the selection of views from the given view based on the given selector
     */
    public static ViewSelection selection(String selector, View view) {
        return ViewSelector.compile(selector).selectViews(view);
    }

    /**
     * Fluent assertion entry point for {@link ViewSelectionAttribute}. Often used
     * together with {@link #extractAttribute(String)} to extract attributes from
     * a selection.
     */
    public static ViewSelectionAttributeAssert assertThat(ViewSelectionAttribute actual) {
        return new ViewSelectionAttributeAssert(actual);
    }

    /**
     * Mimics the FEST 2.x API for extracting generic properties from a collection,
     * but here with specific logic for extracting attributes from Android views.
     * @param attributeName name of the attribute to extract
     * @return an attribute extractor which can be passed a selection
     */
    public static Attributes extractAttribute(String attributeName) {
        return new Attributes(attributeName);
    }

}




Java Source Code List

com.nikhaldimann.viewselector.Attributes.java
com.nikhaldimann.viewselector.InvalidSelectorException.java
com.nikhaldimann.viewselector.ViewSelectionAssert.java
com.nikhaldimann.viewselector.ViewSelectionAttributeAssert.java
com.nikhaldimann.viewselector.ViewSelectorAssertions.java
com.nikhaldimann.viewselector.ViewSelector.java
com.nikhaldimann.viewselector.android.AllTests.java
com.nikhaldimann.viewselector.android.ViewSelectionAssertTest.java
com.nikhaldimann.viewselector.android.ViewSelectorAssertionsTest.java
com.nikhaldimann.viewselector.android.ViewSelectorTest.java
com.nikhaldimann.viewselector.android.activities.HelloWorldExampleActivityTest.java
com.nikhaldimann.viewselector.android.activities.HelloWorldExampleFragmentActivityTest.java
com.nikhaldimann.viewselector.android.activities.ListViewExampleActivityTest.java
com.nikhaldimann.viewselector.android.activities.SimpleFragmentTest.java
com.nikhaldimann.viewselector.android.attributes.ViewAttributesTest.java
com.nikhaldimann.viewselector.android.checker.AttributeSpecifierCheckerTest.java
com.nikhaldimann.viewselector.android.checker.ClassCheckerTest.java
com.nikhaldimann.viewselector.android.testutil.AndroidTestViewFactory.java
com.nikhaldimann.viewselector.attributes.AttributeAccessException.java
com.nikhaldimann.viewselector.attributes.ViewAttributes.java
com.nikhaldimann.viewselector.attributes.ViewSelectionAttribute.java
com.nikhaldimann.viewselector.checker.AttributeSpecifierChecker.java
com.nikhaldimann.viewselector.checker.ClassChecker.java
com.nikhaldimann.viewselector.checker.MatchPredicate.java
com.nikhaldimann.viewselector.checker.MatchPredicates.java
com.nikhaldimann.viewselector.checker.ViewTraversalChecker.java
com.nikhaldimann.viewselector.robolectric.RobolectricTestHelloWorldActivity.java
com.nikhaldimann.viewselector.robolectric.RobolectricTestHelloWorldFragmentActivity.java
com.nikhaldimann.viewselector.selection.ViewSelection.java