Skip to content

Commit

Permalink
Fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mukta13 authored and wenshao committed Oct 17, 2024
1 parent 949c422 commit 4d71c70
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONB;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class JSONBTableTest3 {
final ObjectMapper mapper = new ObjectMapper();

@Test
public void test_0() {
A a = new A();
Expand All @@ -26,7 +32,7 @@ public void test_0() {

byte[] bytes = JSONB.toBytes(a);
A a1 = JSONB.parseObject(bytes, A.class);
assertEquals(JSON.toJSONString(a), JSON.toJSONString(a1));
assertMapsEqual(a, a1);
}

@Test
Expand All @@ -49,7 +55,17 @@ public void test_1() {

byte[] bytes = JSONB.toBytes(a);
A a1 = JSONB.parseObject(bytes, A.class);
assertEquals(JSON.toJSONString(a), JSON.toJSONString(a1));
assertMapsEqual(a, a1);
}

private void assertMapsEqual(A a, A a1) {
try {
Map<String, Object> mapa = mapper.readValue(JSON.toJSONString(a), Map.class);
Map<String, Object> mapa1 = mapper.readValue(JSON.toJSONString(a1), Map.class);
assertEquals(mapa, mapa1);
} catch (IOException e) {
throw new RuntimeException("Failed to read value as Map", e);
}
}

public static class A {
Expand Down

0 comments on commit 4d71c70

Please sign in to comment.