refactor - DBWriterTest: parametrize the set of tests
This commit is contained in:
parent
ba27ec6b31
commit
bfde3c7315
|
@ -1,6 +1,10 @@
|
|||
package de.danoeh.antennapod.core.storage;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
@ -15,43 +19,43 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
public class DBWriterTest {
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public static class ItemEnqueuePositionCalculatorTest {
|
||||
|
||||
@Test
|
||||
public void testEnqueueDefault() {
|
||||
|
||||
ItemEnqueuePositionCalculator calculator =
|
||||
new ItemEnqueuePositionCalculator(new Options());
|
||||
|
||||
List<FeedItem> curQueue = tQueue();
|
||||
|
||||
int posActual1 = calculator.calcPosition(0, tFI(101), curQueue);
|
||||
assertEquals("case default, i.e., add to the end", curQueue.size(), posActual1);
|
||||
|
||||
int posActual2 = calculator.calcPosition(1, tFI(102), curQueue);
|
||||
assertEquals("case default (2nd item)", curQueue.size(), posActual2);
|
||||
@Parameters(name = "{index}: case<{0}>, expected:{1}")
|
||||
public static Iterable<Object[]> data() {
|
||||
Options optDefault = new Options();
|
||||
Options optEnqAtFront = new Options().setEnqueueAtFront(true);
|
||||
|
||||
return Arrays.asList(new Object[][] {
|
||||
{"case default, i.e., add to the end", QUEUE_DEFAULT.size(), optDefault , 0},
|
||||
{"case default (2nd item)", QUEUE_DEFAULT.size(), optDefault , 1},
|
||||
{"case option enqueue at front", 0, optEnqAtFront , 0},
|
||||
{"case option enqueue at front (2nd item)", 1, optEnqAtFront , 1}
|
||||
});
|
||||
}
|
||||
|
||||
private static final List<FeedItem> QUEUE_DEFAULT = Arrays.asList(tFI(11), tFI(12), tFI(13), tFI(14));
|
||||
|
||||
@Parameter
|
||||
public String message;
|
||||
|
||||
@Parameter(1)
|
||||
public int posExpected;
|
||||
|
||||
@Parameter(2)
|
||||
public Options options;
|
||||
|
||||
@Parameter(3)
|
||||
public int posAmongAdded; // the position of feed item to be inserted among the list to be inserted.
|
||||
|
||||
|
||||
@Test
|
||||
public void testEnqueueAtFront() {
|
||||
public void test() {
|
||||
ItemEnqueuePositionCalculator calculator = new ItemEnqueuePositionCalculator(options);
|
||||
|
||||
ItemEnqueuePositionCalculator calculator =
|
||||
new ItemEnqueuePositionCalculator(new Options()
|
||||
.setEnqueueAtFront(true));
|
||||
|
||||
List<FeedItem> curQueue = tQueue();
|
||||
|
||||
int posActual1 = calculator.calcPosition(0, tFI(101), curQueue);
|
||||
assertEquals("case option enqueue at front", 0, posActual1);
|
||||
|
||||
int posActual2 = calculator.calcPosition(1, tFI(102), curQueue);
|
||||
assertEquals("case option enqueue at front (2nd item)", 1, posActual2);
|
||||
|
||||
}
|
||||
|
||||
private static List<FeedItem> tQueue() {
|
||||
return Arrays.asList(tFI(11), tFI(12), tFI(13), tFI(14));
|
||||
int posActual = calculator.calcPosition(posAmongAdded, tFI(101), QUEUE_DEFAULT);
|
||||
assertEquals(message, posExpected , posActual);
|
||||
}
|
||||
|
||||
private static FeedItem tFI(int id) {
|
||||
|
|
Loading…
Reference in New Issue