Skip to content

Commit

Permalink
make up codecov
Browse files Browse the repository at this point in the history
Change-Id: I2798ff31e9c2154289ec5a23c78b942840768417
  • Loading branch information
Linary committed Sep 9, 2019
1 parent 6ba6dbe commit 3328a85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package com.baidu.hugegraph.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;

import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
Expand All @@ -36,7 +35,6 @@
import org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule;
import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;

import com.baidu.hugegraph.HugeException;
import com.baidu.hugegraph.backend.BackendException;
import com.baidu.hugegraph.backend.id.EdgeId;
import com.baidu.hugegraph.backend.id.IdGenerator;
Expand Down Expand Up @@ -118,18 +116,6 @@ public static <T> T fromJson(String json, TypeReference<?> typeRef) {
}
}

public static <T> T fromJson(InputStream stream, Class<T> clazz) {
E.checkState(stream != null,
"Json stream can't be null for '%s'",
clazz.getSimpleName());
try {
return mapper.readValue(stream, clazz);
} catch (IOException e) {
throw new HugeException(
"Failed to read stream to class '%s'", clazz);
}
}

/**
* Number collection will be parsed to Double Collection via fromJson,
* this method used to cast element in collection to original number type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
package com.baidu.hugegraph.unit.util;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.tinkerpop.shaded.jackson.core.type.TypeReference;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -52,6 +54,7 @@
import com.baidu.hugegraph.unit.BaseUnitTest;
import com.baidu.hugegraph.unit.FakeObjects;
import com.baidu.hugegraph.util.JsonUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

public class JsonUtilTest extends BaseUnitTest {
Expand Down Expand Up @@ -288,4 +291,12 @@ public void testSerializeEdge() {
"\"properties\":{\"date\":%s," +
"\"weight\":0.8}}", dateTime), json);
}

@Test
public void testDeserializeList() {
String json = "[\"1\", \"2\", \"3\"]";
TypeReference typeRef = new TypeReference<List<Integer>>() {};
Assert.assertEquals(ImmutableList.of(1, 2, 3),
JsonUtil.fromJson(json, typeRef));
}
}

0 comments on commit 3328a85

Please sign in to comment.