Skip to content

Commit

Permalink
add view resolvers and assertions for compound buttons such as radio …
Browse files Browse the repository at this point in the history
…buttons or check boxes
  • Loading branch information
mttkay committed Jul 25, 2011
1 parent bd233a2 commit 539af9b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import android.test.InstrumentationTestCase;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.github.calculon.CalculonTestCase;

Expand Down Expand Up @@ -51,6 +55,18 @@ public static TextView text(int id) {
return (TextView) getActivity().findViewById(id);
}

public static CheckBox checkBox(int id) {
return (CheckBox) getActivity().findViewById(id);
}

public static ToggleButton toggleButton(int id) {
return (ToggleButton) getActivity().findViewById(id);
}

public static RadioButton radioButton(int id) {
return (RadioButton) getActivity().findViewById(id);
}

public static ViewGroup parent(int id) {
return (ViewGroup) getActivity().findViewById(id);
}
Expand Down Expand Up @@ -92,4 +108,8 @@ public static ListViewAssertion assertThat(ListView view) {
public static TextViewAssertion assertThat(TextView view) {
return new TextViewAssertion(testCase, getActivity(), view);
}

public static CompoundButtonAssertion assertThat(CompoundButton view) {
return new CompoundButtonAssertion(testCase, getActivity(), view);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.calculon.assertion;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import android.app.Activity;
import android.test.InstrumentationTestCase;
import android.widget.CompoundButton;

public class CompoundButtonAssertion extends ViewAssertion {

private CompoundButton compoundButton;

public CompoundButtonAssertion(InstrumentationTestCase testCase, Activity activity,
CompoundButton compoundButton) {
super(testCase, activity, compoundButton);
this.compoundButton = compoundButton;
}

public void checked() {
assertTrue("expected view to be checked, but it wasn't", compoundButton.isChecked());
}

public void unchecked() {
assertFalse("expected view to not be checked, but it was", compoundButton.isChecked());
}
}

0 comments on commit 539af9b

Please sign in to comment.