From 03b72816f98f78429993860fc8217e16706820df Mon Sep 17 00:00:00 2001 From: Dario Safa <dario.akhavansafa@uzh.ch> Date: Mon, 3 May 2021 15:36:16 +0200 Subject: [PATCH] DefaultTest -> convert into ParametrizedTest --- .../logic/layout/format/DefaultTest.java | 57 +++++++------------ 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/DefaultTest.java b/src/test/java/org/jabref/logic/layout/format/DefaultTest.java index c746de8c858..2a44b69b141 100644 --- a/src/test/java/org/jabref/logic/layout/format/DefaultTest.java +++ b/src/test/java/org/jabref/logic/layout/format/DefaultTest.java @@ -1,49 +1,36 @@ package org.jabref.logic.layout.format; +import java.util.stream.Stream; + import org.jabref.logic.layout.ParamLayoutFormatter; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; public class DefaultTest { - @Test - public void testSimpleText() { - ParamLayoutFormatter a = new Default(); - a.setArgument("DEFAULT TEXT"); - assertEquals("Bob Bruce", a.format("Bob Bruce")); - } - - @Test - public void testFormatNullExpectReplace() { - ParamLayoutFormatter a = new Default(); - a.setArgument("DEFAULT TEXT"); - assertEquals("DEFAULT TEXT", a.format(null)); - } - - @Test - public void testFormatEmpty() { - ParamLayoutFormatter a = new Default(); - a.setArgument("DEFAULT TEXT"); - assertEquals("DEFAULT TEXT", a.format("")); - } - - @Test - public void testNoArgumentSet() { - ParamLayoutFormatter a = new Default(); - assertEquals("Bob Bruce and Jolly Jumper", a.format("Bob Bruce and Jolly Jumper")); - } + ParamLayoutFormatter paramLayoutFormatter = new Default(); - @Test - public void testNoArgumentSetNullInput() { - ParamLayoutFormatter a = new Default(); - assertEquals("", a.format(null)); + @ParameterizedTest + @MethodSource("formatTests") + void paramLayoutFormatTest(String expectedString, String inputString, String formatterArgument){ + if (!formatterArgument.isEmpty()){ + paramLayoutFormatter.setArgument(formatterArgument); + } + assertEquals(expectedString, paramLayoutFormatter.format(inputString)); } - @Test - public void testNoArgumentSetEmptyInput() { - ParamLayoutFormatter a = new Default(); - assertEquals("", a.format("")); + private static Stream<Arguments> formatTests() { + return Stream.of( + Arguments.of("Bob Bruce", "Bob Bruce", "DEFAULT TEXT"), + Arguments.of("DEFAULT TEXT", null, "DEFAULT TEXT"), + Arguments.of("DEFAULT TEXT", "", "DEFAULT TEXT"), + Arguments.of("Bob Bruce and Jolly Jumper", "Bob Bruce and Jolly Jumper", ""), + Arguments.of("", null, ""), + Arguments.of("", "", "") + ); } }