diff options
Diffstat (limited to 'app/src/test/java/android')
-rw-r--r-- | app/src/test/java/android/content/Intent.java | 61 | ||||
-rw-r--r-- | app/src/test/java/android/os/Bundle.java | 101 | ||||
-rw-r--r-- | app/src/test/java/android/util/Base64.java | 19 |
3 files changed, 181 insertions, 0 deletions
diff --git a/app/src/test/java/android/content/Intent.java b/app/src/test/java/android/content/Intent.java new file mode 100644 index 00000000..92211558 --- /dev/null +++ b/app/src/test/java/android/content/Intent.java @@ -0,0 +1,61 @@ +package android.content; + +import android.os.Bundle; +import android.os.Parcelable; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class Intent { + final String[] action = new String[1]; + final Map<String, Object> fakeExtras = new HashMap<>(); + final List<String> categories = new ArrayList<>(); + + public Intent setAction(String action) { + this.action[0] = action; + return this; + } + + public String getAction() { + return action[0]; + } + + public Intent putExtra(String key, Bundle bundle) { + fakeExtras.put(key, bundle); + return this; + } + + public Bundle getBundleExtra(String key) { + Object o = fakeExtras.get(key); + if (o != null) { + return (Bundle) o; + } + return null; + } + + public Intent putExtra(String key, Parcelable extra) { + fakeExtras.put(key, extra); + return this; + } + + public Parcelable getParcelableExtra(String key) { + Object o = fakeExtras.get(key); + if (o != null) { + return (Parcelable) o; + } + return null; + } + + public Intent addCategory(String key) { + categories.add(key); + return this; + } + + public Set<String> getCategories() { + return new HashSet<>(categories); + } +} diff --git a/app/src/test/java/android/os/Bundle.java b/app/src/test/java/android/os/Bundle.java new file mode 100644 index 00000000..ea869cb2 --- /dev/null +++ b/app/src/test/java/android/os/Bundle.java @@ -0,0 +1,101 @@ +package android.os; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class Bundle { + + /** An unmodifiable {@code Bundle} that is always {@link #isEmpty() empty}. */ + public static final Bundle EMPTY; + + /** + * Special extras used to denote extras have been stripped off. + * @hide + */ + public static final Bundle STRIPPED; + + static { + EMPTY = new Bundle(); + + STRIPPED = new Bundle(); + STRIPPED.putInt("STRIPPED", 1); + } + + final Map<String, Boolean> fakeBooleanBundle = new HashMap<>(); + final Map<String, String> fakeStringBundle = new HashMap<>(); + final Map<String, Integer> fakeIntBundle = new HashMap<>(); + final Map<String, Parcelable> fakeParcelableBundle = new HashMap<>(); + + + public void putString(String key, String value) { + fakeStringBundle.put(key, value); + } + + public String getString(String key) { + return fakeStringBundle.get(key); + } + + public void putBoolean(String key, boolean value) { + fakeBooleanBundle.put(key, value); + } + + public boolean getBoolean(String key) { + return fakeBooleanBundle.getOrDefault(key, false); + } + + public void putInt(String key, int value) { + fakeIntBundle.put(key, value); + } + + public int getInt(String key) { + return fakeIntBundle.getOrDefault(key, 0); + } + + public void putParcelable(String key, Parcelable value) { + fakeParcelableBundle.put(key, value); + } + + public Parcelable getParcelable(String key) { + return fakeParcelableBundle.get(key); + } + + public Object get(String key) { + if (fakeBooleanBundle.containsKey(key)) { + return fakeBooleanBundle.get(key); + } else if (fakeIntBundle.containsKey(key)) { + return fakeIntBundle.get(key); + } else if (fakeStringBundle.containsKey(key)) { + return fakeStringBundle.get(key); + } else { + return fakeParcelableBundle.get(key); + } + } + + public Set<String> keySet() { + //this whole approach as a drawback: + //you should not add the same keys for values of different types + HashSet<String> keys = new HashSet<String>(); + keys.addAll(fakeBooleanBundle.keySet()); + keys.addAll(fakeIntBundle.keySet()); + keys.addAll(fakeStringBundle.keySet()); + keys.addAll(fakeParcelableBundle.keySet()); + return keys; + } + + public boolean containsKey(String key) { + return fakeBooleanBundle.containsKey(key) || + fakeStringBundle.containsKey(key) || + fakeIntBundle.containsKey(key) || + fakeParcelableBundle.containsKey(key); + } + + public void remove(String key) { + fakeBooleanBundle.remove(key); + fakeIntBundle.remove(key); + fakeParcelableBundle.remove(key); + fakeStringBundle.remove(key); + } + +} diff --git a/app/src/test/java/android/util/Base64.java b/app/src/test/java/android/util/Base64.java new file mode 100644 index 00000000..da40e9c4 --- /dev/null +++ b/app/src/test/java/android/util/Base64.java @@ -0,0 +1,19 @@ +package android.util; + +import java.util.Arrays; + +public class Base64 { + + /** + * Base64-encode the given data and return a newly allocated + * String with the result. + * + * @param input the data to encode + * @param flags controls certain features of the encoded output. + * Passing {@code DEFAULT} results in output that + * adheres to RFC 2045. + */ + public static String encodeToString(byte[] input, int flags) { + return Arrays.toString(java.util.Base64.getEncoder().encode(input)); + } +} |