Skip to content

Use mockneat library for generating random values #51

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
24 changes: 6 additions & 18 deletions src/main/java/name/valery1707/problem/ParseJsonList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toUnmodifiableMap;
import static net.andreinc.mockneat.unit.objects.Filler.filler;
import static net.andreinc.mockneat.unit.types.Ints.ints;

public interface ParseJsonList {

Expand Down Expand Up @@ -63,14 +62,6 @@ class DemoDto {

private String code;

public DemoDto() {
}

public DemoDto(String code) {
this();
this.code = code;
}

public String getCode() {
return code;
}
Expand All @@ -82,13 +73,10 @@ public void setCode(String code) {
}

static String generate(ObjectMapper mapper, int count) throws JsonProcessingException {
List<DemoDto> list = IntStream
.generate(() -> ThreadLocalRandom.current().nextInt(count * 1000))
.distinct()
.limit(count)
.mapToObj(String::valueOf)
.map(DemoDto::new)
.collect(toList());
List<DemoDto> list = filler(DemoDto::new)
.setter(DemoDto::setCode, ints().bound(count * 1000).map(String::valueOf))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of code will be used as the key for the map and it should be distinct

.list(count)
.get();
return mapper.writeValueAsString(list);
}

Expand Down