From bfde3c731514f1a761710d634c39a80ad75bdf10 Mon Sep 17 00:00:00 2001 From: orionlee Date: Fri, 18 May 2018 15:20:21 -0700 Subject: [PATCH] refactor - DBWriterTest: parametrize the set of tests --- .../antennapod/core/storage/DBWriterTest.java | 64 ++++++++++--------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DBWriterTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DBWriterTest.java index 0d494534c..d6ccbba3a 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DBWriterTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DBWriterTest.java @@ -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 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 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 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 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 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) {