Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Decimal128): 加入支持Decimal128类型数据mock #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<version>1.16.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/jsonzou/jmockdata/MockConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import org.bson.types.Decimal128;

/**
* 模拟数据配置类
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Decimal128> {

@Override
public Decimal128 mock(DataConfig mockConfig) {
return new Decimal128(
BigDecimal.valueOf(
mockConfig.globalConfig().getMocker(Double.class).mock(mockConfig)
)
);
}

}
3 changes: 3 additions & 0 deletions src/test/java/com/github/jsonzou/jmockdata/JMockDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down