use of android.util.AttributeSet in project robolectric by robolectric.
the class ShadowEditTextTest method givenInitializingWithAttributeSet_whenMaxLengthDefined_thenRestrictTextLengthToMaxLength.
@Test
public void givenInitializingWithAttributeSet_whenMaxLengthDefined_thenRestrictTextLengthToMaxLength() {
int maxLength = anyInteger();
AttributeSet attrs = Robolectric.buildAttributeSet().addAttribute(android.R.attr.maxLength, maxLength + "").build();
EditText editText = new EditText(RuntimeEnvironment.application, attrs);
String excessiveInput = stringOfLength(maxLength * 2);
editText.setText(excessiveInput);
assertThat((CharSequence) editText.getText().toString()).isEqualTo(excessiveInput.subSequence(0, maxLength));
}
use of android.util.AttributeSet in project robolectric by robolectric.
the class ShadowEditTextTest method givenInitializingWithAttributeSet_whenMaxLengthNotDefined_thenTextLengthShouldHaveNoRestrictions.
@Test
public void givenInitializingWithAttributeSet_whenMaxLengthNotDefined_thenTextLengthShouldHaveNoRestrictions() {
AttributeSet attrs = Robolectric.buildAttributeSet().build();
EditText editText = new EditText(RuntimeEnvironment.application, attrs);
String input = anyString();
editText.setText(input);
assertThat(editText.getText().toString()).isEqualTo(input);
}
use of android.util.AttributeSet in project robolectric by robolectric.
the class ShadowEditTextTest method setup.
@Before
public void setup() {
AttributeSet attributeSet = Robolectric.buildAttributeSet().addAttribute(android.R.attr.maxLength, "5").build();
editText = new EditText(application, attributeSet);
}
use of android.util.AttributeSet in project robolectric by robolectric.
the class ShadowViewTest method shouldCallOnClickWithAttribute.
@Test
public void shouldCallOnClickWithAttribute() throws Exception {
MyActivity myActivity = buildActivity(MyActivity.class).create().get();
AttributeSet attrs = Robolectric.buildAttributeSet().addAttribute(android.R.attr.onClick, "clickMe").build();
view = new View(myActivity, attrs);
view.performClick();
assertTrue("Should have been called", myActivity.called);
}
use of android.util.AttributeSet in project robolectric by robolectric.
the class AttributeSetBuilderTest method getStyleAttribute_doesNotThrowException.
@Test
public void getStyleAttribute_doesNotThrowException() throws Exception {
AttributeSet roboAttributeSet = Robolectric.buildAttributeSet().build();
roboAttributeSet.getStyleAttribute();
}
Aggregations