Skip to content

Commit

Permalink
Realism update for EditTextPreference, by removing implementation in …
Browse files Browse the repository at this point in the history
…shadow that did not match the Android API.
  • Loading branch information
blurpy committed Mar 24, 2014
1 parent 3914035 commit df5fa5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 35 deletions.
@@ -1,40 +1,9 @@
package org.robolectric.shadows;

import android.content.Context;
import android.preference.EditTextPreference;
import android.util.AttributeSet;
import android.widget.EditText;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

@Implements(EditTextPreference.class)
public class ShadowEditTextPreference extends ShadowDialogPreference {

private EditText mEditText;

public void __constructor__(Context context) {
__constructor__(context, null, 0);
}

public void __constructor__(Context context, AttributeSet attributeSet) {
__constructor__(context, attributeSet, 0);
}

public void __constructor__(Context context, AttributeSet attributeSet, int defStyle) {
super.__constructor__(context, attributeSet, defStyle);

mEditText = new EditText(context, attrs);
mEditText.setEnabled(true);
}

@Implementation
public EditText getEditText() {
return mEditText;
}

@Implementation
public void setText(java.lang.String text) {
mEditText.setText(text);
}

}
23 changes: 19 additions & 4 deletions src/test/java/org/robolectric/shadows/EditTextPreferenceTest.java
Expand Up @@ -2,13 +2,15 @@

import android.content.Context;
import android.preference.EditTextPreference;
import android.widget.EditText;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.TestRunners;

import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.*;
import static org.fest.assertions.api.Assertions.assertThat;

@RunWith(TestRunners.WithDefaults.class)
Expand All @@ -32,9 +34,22 @@ public void testConstructor() {
}

@Test
public void testSetText() {
preference.setText(SOME_TEXT);
assertThat((String) preference.getEditText().getText().toString()).isEqualTo(SOME_TEXT);
public void setTextInEditTextShouldStoreText() {
final EditText editText = preference.getEditText();
editText.setText(SOME_TEXT);

assertThat(editText.getText().toString()).isEqualTo(SOME_TEXT);
}

@Test
public void setTextShouldStoreText() {
preference.setText("some other text");
assertThat(preference.getText()).isEqualTo("some other text");
}

@Test
public void setTextShouldStoreNull() {
preference.setText(null);
assertNull(preference.getText());
}
}

0 comments on commit df5fa5b

Please sign in to comment.