From aa08ebd8ebb20930b45123d74d461f0cfa9054b5 Mon Sep 17 00:00:00 2001 From: zhzhl <773975498@qq.com> Date: Wed, 5 Jan 2022 16:26:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(Decimal128):=20=E5=8A=A0=E5=85=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81Decimal128=E7=B1=BB=E5=9E=8B=E6=95=B0=E6=8D=AEmock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++++ .../github/jsonzou/jmockdata/MockConfig.java | 3 +++ .../jmockdata/mocker/Decimal128Mocker.java | 22 +++++++++++++++++++ .../jsonzou/jmockdata/JMockDataTest.java | 3 +++ 4 files changed, 34 insertions(+) create mode 100644 src/main/java/com/github/jsonzou/jmockdata/mocker/Decimal128Mocker.java diff --git a/pom.xml b/pom.xml index 2bfbf68f9..279d414e1 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,12 @@ 1.16.20 provided + + org.mongodb + mongo-java-driver + 3.5.0 + provided + junit junit diff --git a/src/main/java/com/github/jsonzou/jmockdata/MockConfig.java b/src/main/java/com/github/jsonzou/jmockdata/MockConfig.java index 7f66c426a..2c07e5865 100644 --- a/src/main/java/com/github/jsonzou/jmockdata/MockConfig.java +++ b/src/main/java/com/github/jsonzou/jmockdata/MockConfig.java @@ -15,6 +15,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.*; +import org.bson.types.Decimal128; /** * 模拟数据配置类 @@ -31,6 +32,7 @@ public class MockConfig { private static final DoubleMocker DOUBLE_MOCKER = new DoubleMocker(); private static final BigIntegerMocker BIG_INTEGER_MOCKER = new BigIntegerMocker(); private static final BigDecimalMocker BIG_DECIMAL_MOCKER = new BigDecimalMocker(); + private static final Decimal128Mocker DECIMAL_128_MOCKER = new Decimal128Mocker(); private static final StringMocker STRING_MOCKER = new StringMocker(); private static final DateMocker DATE_MOCKER = new DateMocker(); private static final LocalDateTimeMocker LOCAL_DATE_TIME_MOCKER = new LocalDateTimeMocker(); @@ -90,6 +92,7 @@ public MockConfig() { registerMocker(DOUBLE_MOCKER, double.class, Double.class); registerMocker(BIG_INTEGER_MOCKER, BigInteger.class); registerMocker(BIG_DECIMAL_MOCKER, BigDecimal.class); + registerMocker(DECIMAL_128_MOCKER, Decimal128.class); registerMocker(STRING_MOCKER, String.class); registerMocker(DATE_MOCKER, Date.class); registerMocker(LOCAL_DATE_TIME_MOCKER, LocalDateTime.class); diff --git a/src/main/java/com/github/jsonzou/jmockdata/mocker/Decimal128Mocker.java b/src/main/java/com/github/jsonzou/jmockdata/mocker/Decimal128Mocker.java new file mode 100644 index 000000000..178d9048e --- /dev/null +++ b/src/main/java/com/github/jsonzou/jmockdata/mocker/Decimal128Mocker.java @@ -0,0 +1,22 @@ +package com.github.jsonzou.jmockdata.mocker; + +import com.github.jsonzou.jmockdata.DataConfig; +import com.github.jsonzou.jmockdata.Mocker; +import java.math.BigDecimal; +import org.bson.types.Decimal128; + +/** + * Decimal128对象模拟器 + */ +public class Decimal128Mocker implements Mocker { + + @Override + public Decimal128 mock(DataConfig mockConfig) { + return new Decimal128( + BigDecimal.valueOf( + mockConfig.globalConfig().getMocker(Double.class).mock(mockConfig) + ) + ); + } + +} diff --git a/src/test/java/com/github/jsonzou/jmockdata/JMockDataTest.java b/src/test/java/com/github/jsonzou/jmockdata/JMockDataTest.java index 3741dda25..9279360ae 100644 --- a/src/test/java/com/github/jsonzou/jmockdata/JMockDataTest.java +++ b/src/test/java/com/github/jsonzou/jmockdata/JMockDataTest.java @@ -6,6 +6,7 @@ import com.github.jsonzou.jmockdata.bean.circular.AXB; import com.github.jsonzou.jmockdata.bean.enums.DayEnum; import com.github.jsonzou.jmockdata.bean.enums.ErrorEnum; +import org.bson.types.Decimal128; import org.junit.Test; import java.lang.reflect.Field; @@ -42,6 +43,8 @@ public void testBasic() { assertNotNull(str); DayEnum dayEnum = JMockData.mock(DayEnum.class); assertNotNull(dayEnum); + Decimal128 decimal128 = JMockData.mock(Decimal128.class); + assertNotNull(decimal128); try { JMockData.mock(ErrorEnum.class);