Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import core.Data;
- import interfaces.Entity;
- import interfaces.Repository;
- import model.BaseEntity;
- import model.Invoice;
- import model.StoreClient;
- import model.User;
- import org.junit.Before;
- import org.junit.Test;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.InvocationTargetException;
- import java.util.ArrayList;
- import java.util.Comparator;
- import java.util.List;
- import java.util.Random;
- import java.util.stream.Collectors;
- import static org.junit.Assert.*;
- public class DataTest3 {
- private Repository data;
- private int parentId;
- private Entity savedEntity;
- private int[] statusesCount;
- @Before
- public void setUp() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
- this.data = new Data();
- Constructor<?>[] constructors = {getConstructor(Invoice.class), getConstructor(StoreClient.class), getConstructor(User.class)};
- Random random = new Random();
- BaseEntity.Status[] statuses = BaseEntity.Status.values();
- this.statusesCount = new int[statuses.length];
- List<Integer> parentIds = new ArrayList<>();
- parentIds.add(0);
- for (int i = 0; i < 25; i++) {
- Constructor<?> constructor = constructors[random.nextInt(constructors.length)];
- int nextInt = random.nextInt(i + 1);
- Entity entity = (Entity) constructor.newInstance(i, parentIds.get(nextInt));
- parentIds.add(i);
- if (entity.getId() == 13) {
- this.parentId = entity.getParentId();
- savedEntity = entity;
- }
- int enumIndex = random.nextInt(statuses.length);
- entity.setStatus(statuses[enumIndex]);
- statusesCount[enumIndex]++;
- this.data.add(entity);
- }
- }
- private Constructor<?> getConstructor(Class<?> clazz) throws NoSuchMethodException {
- return clazz.getDeclaredConstructor(int.class, int.class);
- }
- @Test(expected = IllegalStateException.class)
- public void getIdWhenNull() {
- Repository repository = new Data();
- repository.peekMostRecent();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement