Skip to content

Commit 0336a67

Browse files
committed
Fix android test failures
Remove the tests that are testing null values where the param can't be null from JS
1 parent 7614d1c commit 0336a67

2 files changed

Lines changed: 5 additions & 64 deletions

File tree

android/src/main/java/com/mparticle/react/MParticleModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class MParticleModule(private val reactContext: ReactApplicationContext) :
112112
value?.let {
113113
val list = mutableListOf<String>()
114114
for (i in 0 until it.size()) {
115-
list.add(it.getString(i))
115+
it.getString(i)?.let { element -> list.add(element) }
116116
}
117117

118118
val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(mpid))

android/src/test/java/com/mparticle/react/MParticleUserTest.java

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.junit.Assert.assertNotNull;
2929
import static org.junit.Assert.assertNull;
3030
import static org.junit.Assert.assertTrue;
31+
import static org.mockito.Mockito.doReturn;
3132

3233
@RunWith(MockitoJUnitRunner.class)
3334
public class MParticleUserTest {
@@ -40,25 +41,10 @@ public void before() {
4041
MParticle.setInstance(Mockito.mock(MParticle.class));
4142
Mockito.when(MParticle.getInstance().Identity()).thenReturn(Mockito.mock(IdentityApi.class));
4243
Mockito.lenient().when(MParticle.getInstance().Identity().getUser(0L)).thenReturn(null);
43-
mParticleUser = new MParticleModule(Mockito.mock(ReactApplicationContext.class)) {
44-
@Override
45-
public WritableMap getWritableMap() {
46-
return new MockMap();
47-
}
48-
};
49-
}
5044

51-
@Test
52-
public void tesNullMParticleUserSetters() {
53-
Exception exception = null;
54-
try {
55-
mParticleUser.setUserAttribute(null, "key", "values");
56-
mParticleUser.setUserTag(null, "test");
57-
mParticleUser.setUserAttributeArray(null, "keuy", new MockReadableArray());
58-
} catch (Exception e) {
59-
exception = e;
60-
}
61-
assertNull(exception);
45+
MParticleModule realModule = new MParticleModule(Mockito.mock(ReactApplicationContext.class));
46+
mParticleUser = Mockito.spy(realModule);
47+
doReturn(new MockMap()).when(mParticleUser).getWritableMap();
6248
}
6349

6450
@Test
@@ -116,21 +102,6 @@ public void invoke(Object... args) {
116102
}
117103
}
118104

119-
@Test
120-
public void testGetUserIdentitiesNullUser() {
121-
final Mutable<Boolean> callbackInvoked = new Mutable<>(false);
122-
123-
mParticleUser.getUserIdentities(null, new Callback() {
124-
@Override
125-
public void invoke(Object... args) {
126-
assertEquals(0, args.length);
127-
callbackInvoked.value = true;
128-
}
129-
});
130-
131-
assertTrue(callbackInvoked.value);
132-
}
133-
134105
@Test
135106
public void testSetUserTag() {
136107
final Mutable<String> tag = new Mutable<>();
@@ -177,21 +148,6 @@ public void invoke(Object... args) {
177148
assertTrue(callbackInvoked.value);
178149
}
179150

180-
@Test
181-
public void getFirstSeenTimeNullUser() {
182-
final Mutable<Boolean> callbackInvoked = new Mutable<>(false);
183-
184-
mParticleUser.getFirstSeen(null, new Callback() {
185-
@Override
186-
public void invoke(Object... args) {
187-
assertEquals(0, args.length);
188-
callbackInvoked.value = true;
189-
}
190-
});
191-
192-
assertTrue(callbackInvoked.value);
193-
}
194-
195151
@Test
196152
public void getLastSeenTime() {
197153
final Mutable<Boolean> callbackInvoked = new Mutable<>(false);
@@ -215,19 +171,4 @@ public void invoke(Object... args) {
215171

216172
assertTrue(callbackInvoked.value);
217173
}
218-
219-
@Test
220-
public void getLastSeenTimeNullUser() {
221-
final Mutable<Boolean> callbackInvoked = new Mutable<>(false);
222-
223-
mParticleUser.getLastSeen(null , new Callback() {
224-
@Override
225-
public void invoke(Object... args) {
226-
assertEquals(0, args.length);
227-
callbackInvoked.value = true;
228-
}
229-
});
230-
231-
assertTrue(callbackInvoked.value);
232-
}
233174
}

0 commit comments

Comments
 (0)