[android] - replace low level json parsing

This commit is contained in:
tobrun
2018-01-02 15:24:36 +01:00
committed by Tobrun
parent dadd90e4e9
commit c62b0af24f
4 changed files with 86 additions and 58 deletions

View File

@@ -0,0 +1,44 @@
package com.mapbox.mapboxsdk.testapp.offline;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.OfflineUtils;
import org.junit.Test;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import static com.mapbox.mapboxsdk.testapp.activity.offline.OfflineActivity.JSON_CHARSET;
import static junit.framework.Assert.assertEquals;
import static junit.framework.TestCase.assertTrue;
public class OfflineUtilsTest extends BaseActivityTest {
private static final String REGION_NAME = "hello world";
private static final String CONVERTED_REGION_NAME = "{\"FIELD_REGION_NAME\":\"hello world\"}";
@Override
protected Class getActivityClass() {
return EspressoTestActivity.class;
}
@Test
public void testOfflineUtilsConvertToBytes() throws UnsupportedEncodingException {
byte[] expected = CONVERTED_REGION_NAME.getBytes(JSON_CHARSET);
byte[] actual = OfflineUtils.convertRegionName(REGION_NAME);
assertTrue("Bytes arrays should match", Arrays.equals(expected, actual));
}
@Test
public void testOfflineUtilsConvertToString() throws UnsupportedEncodingException {
String actual = OfflineUtils.convertRegionName(CONVERTED_REGION_NAME.getBytes(JSON_CHARSET));
assertEquals("Strings should match", REGION_NAME, actual);
}
@Test
public void testOfflineUtilsConvertNoOp() {
String convertNoOp = OfflineUtils.convertRegionName(OfflineUtils.convertRegionName(REGION_NAME));
assertEquals("Strings should match", REGION_NAME, convertNoOp);
}
}