Search in sources :

Example 26 with AttributeSet

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));
}
Also used : EditText(android.widget.EditText) AttributeSet(android.util.AttributeSet) Test(org.junit.Test)

Example 27 with AttributeSet

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);
}
Also used : EditText(android.widget.EditText) AttributeSet(android.util.AttributeSet) Test(org.junit.Test)

Example 28 with AttributeSet

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);
}
Also used : EditText(android.widget.EditText) AttributeSet(android.util.AttributeSet) Before(org.junit.Before)

Example 29 with 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);
}
Also used : AttributeSet(android.util.AttributeSet) Test(org.junit.Test)

Example 30 with AttributeSet

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();
}
Also used : AttributeSet(android.util.AttributeSet) Test(org.junit.Test)

Aggregations

AttributeSet (android.util.AttributeSet)262 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)160 IOException (java.io.IOException)125 XmlResourceParser (android.content.res.XmlResourceParser)113 TypedArray (android.content.res.TypedArray)78 Resources (android.content.res.Resources)46 Test (org.junit.Test)42 TypedValue (android.util.TypedValue)34 InflateException (android.view.InflateException)28 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)24 PackageManager (android.content.pm.PackageManager)22 Context (android.content.Context)20 ComponentName (android.content.ComponentName)18 XmlPullParser (org.xmlpull.v1.XmlPullParser)17 Intent (android.content.Intent)11 RemoteException (android.os.RemoteException)11 Bundle (android.os.Bundle)9 ArrayList (java.util.ArrayList)9 ActivityInfo (android.content.pm.ActivityInfo)7 ApplicationInfo (android.content.pm.ApplicationInfo)7