Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import interfaces.Buffer;
- import core.Loader;
- import interfaces.Entity;
- 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.List;
- import java.util.Random;
- import static org.junit.Assert.*;
- public class LoaderTest23 {
- private Buffer buffer;
- private Entity savedEntity;
- private int[] statusesCount;
- @Before
- public void setUp() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
- this.buffer = new Loader();
- Constructor<?>[] constructors = {getConstructor(Invoice.class), getConstructor(StoreClient.class), getConstructor(User.class)};
- Random random = new Random();
- int boundIndex = random.nextInt(25);
- BaseEntity.Status[] statuses = BaseEntity.Status.values();
- this.statusesCount = new int[statuses.length];
- for (int i = 0; i < 25; i++) {
- Constructor<?> constructor = constructors[random.nextInt(constructors.length)];
- Entity entity = (Entity) constructor.newInstance(i, i + 13);
- if (i == boundIndex) {
- this.savedEntity = entity;
- }
- int enumIndex = random.nextInt(statuses.length);
- entity.setStatus(statuses[enumIndex]);
- statusesCount[enumIndex]++;
- this.buffer.add(entity);
- }
- }
- private Constructor<?> getConstructor(Class<?> clazz) throws NoSuchMethodException {
- return clazz.getDeclaredConstructor(int.class, int.class);
- }
- @Test
- public void sizeAfterRemove() {
- int expectedCount = 25 - statusesCount[BaseEntity.Status.SOLD.ordinal()];
- this.buffer.removeSold();
- assertEquals(expectedCount, this.buffer.entitiesCount());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement