forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: A simple test for WritableNativeMap. Also includes a test to verify that the key name exists in the error message if a dynamic cast exception occurs (this will be implemented in the future) Reviewed By: mdvacca Differential Revision: D12914375 fbshipit-source-id: 654674b1b32e7b3f38cc1364a2302d1ce08ec33e
- Loading branch information
1 parent
4099899
commit f14fca2
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
ReactAndroid/src/androidTest/java/com/facebook/react/tests/core/WritableNativeMapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.facebook.react.tests.core; | ||
|
||
import static org.fest.assertions.api.Assertions.assertThat; | ||
|
||
import android.support.test.runner.AndroidJUnit4; | ||
import com.facebook.react.bridge.UnexpectedNativeTypeException; | ||
import com.facebook.react.bridge.WritableNativeArray; | ||
import com.facebook.react.bridge.WritableNativeMap; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class WritableNativeMapTest { | ||
|
||
private WritableNativeMap mMap; | ||
|
||
@Before | ||
public void setup() { | ||
mMap = new WritableNativeMap(); | ||
mMap.putBoolean("boolean", true); | ||
mMap.putDouble("double", 1.2); | ||
mMap.putInt("int", 1); | ||
mMap.putString("string", "abc"); | ||
mMap.putMap("map", new WritableNativeMap()); | ||
mMap.putArray("array", new WritableNativeArray()); | ||
mMap.putBoolean("dvacca", true); | ||
mMap.setUseNativeAccessor(true); | ||
} | ||
|
||
@Test | ||
public void testBoolean() { | ||
assertThat(mMap.getBoolean("boolean")).isEqualTo(true); | ||
} | ||
|
||
@Test(expected = UnexpectedNativeTypeException.class) | ||
public void testBooleanInvalidType() { | ||
mMap.getBoolean("string"); | ||
} | ||
|
||
@Test | ||
public void testDouble() { | ||
assertThat(mMap.getDouble("double")).isEqualTo(1.2); | ||
} | ||
|
||
@Test(expected = UnexpectedNativeTypeException.class) | ||
public void testDoubleInvalidType() { | ||
mMap.getDouble("string"); | ||
} | ||
|
||
@Test | ||
public void testInt() { | ||
assertThat(mMap.getInt("int")).isEqualTo(1); | ||
} | ||
|
||
@Test(expected = UnexpectedNativeTypeException.class) | ||
public void testIntInvalidType() { | ||
mMap.getInt("string"); | ||
} | ||
|
||
@Test | ||
public void testString() { | ||
assertThat(mMap.getString("string")).isEqualTo("abc"); | ||
} | ||
|
||
@Test(expected = UnexpectedNativeTypeException.class) | ||
public void testStringInvalidType() { | ||
mMap.getString("int"); | ||
} | ||
|
||
@Test | ||
public void testMap() { | ||
assertThat(mMap.getMap("map")).isNotNull(); | ||
} | ||
|
||
@Test(expected = UnexpectedNativeTypeException.class) | ||
public void testMapInvalidType() { | ||
mMap.getMap("string"); | ||
} | ||
|
||
@Test | ||
public void testArray() { | ||
assertThat(mMap.getArray("array")).isNotNull(); | ||
} | ||
|
||
@Test(expected = UnexpectedNativeTypeException.class) | ||
public void testArrayInvalidType() { | ||
mMap.getArray("string"); | ||
} | ||
|
||
@Ignore("Needs to be implemented") | ||
@Test | ||
public void testErrorMessageContainsKey() { | ||
String key = "fkg"; | ||
try { | ||
mMap.getString(key); | ||
Assert.fail("Expected an UnexpectedNativeTypeException to be thrown"); | ||
} catch (UnexpectedNativeTypeException e) { | ||
assertThat(e.getMessage()).contains(key); | ||
} | ||
} | ||
} |