Merge branch 'master' of git://github.com/pivotal/robolectric into robo-staging
diff --git a/src/main/java/com/xtremelabs/robolectric/Robolectric.java b/src/main/java/com/xtremelabs/robolectric/Robolectric.java
index aa49955..938dfd9 100644
--- a/src/main/java/com/xtremelabs/robolectric/Robolectric.java
+++ b/src/main/java/com/xtremelabs/robolectric/Robolectric.java
@@ -108,10 +108,7 @@
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
-import android.view.animation.AlphaAnimation;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-import android.view.animation.TranslateAnimation;
+import android.view.animation.*;
import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
@@ -231,6 +228,7 @@
ShadowAndroidHttpClient.class,
ShadowAnimation.class,
ShadowAnimationDrawable.class,
+ ShadowAnimationSet.class,
ShadowAnimationUtils.class,
ShadowApplication.class,
ShadowAppWidgetManager.class,
@@ -516,6 +514,10 @@
return (ShadowAnimationDrawable) shadowOf_(instance);
}
+ public static ShadowAnimationSet shadowOf(AnimationSet instance) {
+ return (ShadowAnimationSet) shadowOf_(instance);
+ }
+
public static ShadowAnimationUtils shadowOf(AnimationUtils instance) {
return (ShadowAnimationUtils) shadowOf_(instance);
}
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowAnimationSet.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowAnimationSet.java
new file mode 100644
index 0000000..5160bf8
--- /dev/null
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowAnimationSet.java
@@ -0,0 +1,30 @@
+package com.xtremelabs.robolectric.shadows;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.view.animation.Animation;
+import android.view.animation.AnimationSet;
+
+import com.xtremelabs.robolectric.internal.Implementation;
+import com.xtremelabs.robolectric.internal.Implements;
+import com.xtremelabs.robolectric.internal.RealObject;
+
+@Implements(AnimationSet.class)
+public class ShadowAnimationSet extends ShadowAnimation {
+ private ArrayList<Animation> animationList = new ArrayList<Animation>();
+
+ @RealObject
+ private AnimationSet realAnimationSet;
+
+
+ @Implementation
+ public void addAnimation(Animation anim) {
+ animationList.add(anim);
+ }
+
+ @Implementation
+ public List<Animation> getAnimations() {
+ return animationList;
+ }
+}
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowListPreference.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowListPreference.java
index 20a1b06..b324e85 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowListPreference.java
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowListPreference.java
@@ -11,6 +11,8 @@
CharSequence[] entries;
CharSequence[] entryValues;
+ String value;
+
@Implementation
public CharSequence[] getEntries() {
return entries;
@@ -40,4 +42,14 @@
public void setEntryValues(int entryValuesResId) {
this.entryValues = context.getResources().getStringArray(entryValuesResId);
}
+
+ @Implementation
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Implementation
+ public String getValue() {
+ return value;
+ }
}
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTranslateAnimation.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTranslateAnimation.java
index 9a79387..f0beafe 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTranslateAnimation.java
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTranslateAnimation.java
@@ -16,6 +16,18 @@
private int toYType;
private float toYValue;
+ public void __constructor__(float fromXValue, float toXValue,
+ float fromYValue, float toYValue) {
+ this.fromXType = TranslateAnimation.ABSOLUTE;
+ this.fromXValue = fromXValue;
+ this.toXType = TranslateAnimation.ABSOLUTE;
+ this.toXValue = toXValue;
+ this.fromYType = TranslateAnimation.ABSOLUTE;
+ this.fromYValue = fromYValue;
+ this.toYType = TranslateAnimation.ABSOLUTE;
+ this.toYValue = toYValue;
+ }
+
public void __constructor__(int fromXType, float fromXValue, int toXType, float toXValue,
int fromYType, float fromYValue, int toYType, float toYValue) {
this.fromXType = fromXType;
diff --git a/src/test/java/com/xtremelabs/robolectric/shadows/AnimationSetTest.java b/src/test/java/com/xtremelabs/robolectric/shadows/AnimationSetTest.java
new file mode 100644
index 0000000..ef968a8
--- /dev/null
+++ b/src/test/java/com/xtremelabs/robolectric/shadows/AnimationSetTest.java
@@ -0,0 +1,45 @@
+package com.xtremelabs.robolectric.shadows;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import android.view.animation.*;
+
+import com.xtremelabs.robolectric.WithTestDefaultsRunner;
+
+import static com.xtremelabs.robolectric.Robolectric.shadowOf;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+@RunWith(WithTestDefaultsRunner.class)
+public class AnimationSetTest {
+ private AnimationSet set;
+ private ShadowAnimationSet shadow;
+
+ @Before
+ public void setUp() {
+ set = new AnimationSet(true);
+ shadow = shadowOf(set);
+ }
+
+
+ @Test
+ public void testAnimationList() {
+ Animation alpha = new AlphaAnimation(1f, 2f);
+ Animation translate = new TranslateAnimation(1f, 2f, 3f, 4f);
+ Animation rotate = new RotateAnimation(1f, 2f);
+ set.addAnimation(alpha);
+ set.addAnimation(translate);
+ set.addAnimation(rotate);
+
+ List<Animation> list = shadow.getAnimations();
+ assertThat(list.size(), equalTo(3));
+ assertThat(list.get(0), sameInstance(alpha));
+ assertThat(list.get(1), sameInstance(translate));
+ assertThat(list.get(2), sameInstance(rotate));
+ }
+
+}
diff --git a/src/test/java/com/xtremelabs/robolectric/shadows/ListPreferenceTest.java b/src/test/java/com/xtremelabs/robolectric/shadows/ListPreferenceTest.java
index a085291..1b9212b 100644
--- a/src/test/java/com/xtremelabs/robolectric/shadows/ListPreferenceTest.java
+++ b/src/test/java/com/xtremelabs/robolectric/shadows/ListPreferenceTest.java
@@ -9,6 +9,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -63,4 +64,11 @@
listPreference.setEntryValues(R.array.greetings);
assertThat(listPreference.getEntryValues(), notNullValue());
}
+
+ @Test
+ public void shouldSetValue() {
+ assertThat(listPreference.getValue(), nullValue());
+ listPreference.setValue("testing");
+ assertThat(listPreference.getValue(), equalTo("testing"));
+ }
}
diff --git a/src/test/java/com/xtremelabs/robolectric/shadows/TranslateAnimationTest.java b/src/test/java/com/xtremelabs/robolectric/shadows/TranslateAnimationTest.java
index c8b3429..716fe6d 100644
--- a/src/test/java/com/xtremelabs/robolectric/shadows/TranslateAnimationTest.java
+++ b/src/test/java/com/xtremelabs/robolectric/shadows/TranslateAnimationTest.java
@@ -1,5 +1,6 @@
package com.xtremelabs.robolectric.shadows;
+import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import com.xtremelabs.robolectric.WithTestDefaultsRunner;
import org.junit.Before;
@@ -33,4 +34,19 @@
assertThat(shadow.getToYType(), equalTo(7));
assertThat(shadow.getToYValue(), equalTo(8f));
}
+
+ @Test
+ public void animationParametersFromConstructor2() throws Exception {
+ TranslateAnimation animation2 = new TranslateAnimation(1, 2, 3, 4);
+ ShadowTranslateAnimation shadow2 = shadowOf(animation2);
+ int defType = Animation.ABSOLUTE;
+ assertThat(shadow2.getFromXType(), equalTo(defType));
+ assertThat(shadow2.getFromXValue(), equalTo(1f));
+ assertThat(shadow2.getToXType(), equalTo(defType));
+ assertThat(shadow2.getToXValue(), equalTo(2f));
+ assertThat(shadow2.getFromYType(), equalTo(defType));
+ assertThat(shadow2.getFromYValue(), equalTo(3f));
+ assertThat(shadow2.getToYType(), equalTo(defType));
+ assertThat(shadow2.getToYValue(), equalTo(4f));
+ }
}