[ 
https://issues.apache.org/jira/browse/CONFIGURATION-817?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17565122#comment-17565122
 ] 

Rob Spoor commented on CONFIGURATION-817:
-----------------------------------------

How do we feel about using some more advanced JUnit 5 functionality? For 
instance, there is this test:
{code}    @Test
    public void testListWithEscapedElements() {
        final String[] values = {"test1", "test2\\,test3", "test4\\,test5"};
        final String listKey = "test.list";

        final BaseConfiguration config = new BaseConfiguration();
        config.addProperty(listKey, values);

        assertEquals(values.length, config.getList(listKey).size(), "Wrong 
number of list elements");

        final Configuration c = createConfiguration(config);
        final List<?> v = c.getList(listKey);

        assertEquals(values.length, v.size(), "Wrong number of elements in 
list");

        for (int i = 0; i < values.length; i++) {
            assertEquals(values[i].replace("\\", ""), v.get(i), "Wrong value at 
index " + i);
        }
    }{code}
I can turn that into this:
{code}    @TestFactory
    public Stream<DynamicTest> testListWithEscapedElements() {
        final String[] values = {"test1", "test2\\,test3", "test4\\,test5"};
        final String listKey = "test.list";

        final BaseConfiguration config = new BaseConfiguration();
        config.addProperty(listKey, values);

        assertEquals(values.length, config.getList(listKey).size(), "Wrong 
number of list elements");

        final Configuration c = createConfiguration(config);
        final List<?> v = c.getList(listKey);

        assertEquals(values.length, v.size(), "Wrong number of elements in 
list");

        return IntStream.range(0, values.length).mapToObj(i -> 
dynamicTest(String.valueOf(i), () -> {
            assertEquals(values[i].replace("\\", ""), v.get(i));
        }));
    }{code}
That way (assuming the test doesn't fail earlier), you get an overview of each 
index separately.

Another such example:
{code}    @Test
    public void testAddPropertyComplexStructures() {
        config.addProperty("tables/table/name", "tasks");
        config.addProperty("tables/table[last()]/@type", "system");
        config.addProperty("tables/table[last()]/fields/field/name", "taskid");
        config.addProperty("tables/table[last()]/fields/field[last()]/@type", 
"int");
        config.addProperty("tables table/name", "documents");
        assertEquals("tasks", config.getString("tables/table[1]/name"), "Wrong 
table 1");
        assertEquals("documents", config.getString("tables/table[2]/name"), 
"Wrong table 2");
        assertEquals("int", 
config.getString("tables/table[1]/fields/field[1]/@type"), "Wrong field type");
    }{code}
I can turn that into this:
{code}    @Nested
    public class AddPropertyComplexStructuresTest {

        @BeforeEach
        public void setUp() {
            config.addProperty("tables/table/name", "tasks");
            config.addProperty("tables/table[last()]/@type", "system");
            config.addProperty("tables/table[last()]/fields/field/name", 
"taskid");
            
config.addProperty("tables/table[last()]/fields/field[last()]/@type", "int");
            config.addProperty("tables table/name", "documents");
        }

        @Test
        public void testTable1() {
            assertEquals("tasks", config.getString("tables/table[1]/name"));
        }

        @Test
        public void testTable2() {
            assertEquals("documents", config.getString("tables/table[2]/name"));
        }

        @Test
        public void testFieldType() {
            assertEquals("int", 
config.getString("tables/table[1]/fields/field[1]/@type"), "Wrong field type");
        }
    }{code}
Or are this cases where the message should simply stay in place?

> Upgrade to JUnit 5
> ------------------
>
>                 Key: CONFIGURATION-817
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-817
>             Project: Commons Configuration
>          Issue Type: Task
>          Components: Build
>            Reporter: Rob Spoor
>            Priority: Minor
>
> From https://lists.apache.org/thread/ygtkpch0s7nss4vx8xfytwsbnv7mzss9
> {quote}Matt Juntunen - Monday, 4 July 2022 04:40:43 CEST
> Re: [VOTE] Release Apache Commons Configuration 2.8.0 based on RC3
> Thanks, Bruno and Gary!
> Gary,
> I think the unit tests as a whole could use some upgrading. I'm
> picturing a conversion to JUnit 5, during which we could ensure
> compatibility with the latest JDK versions. I'm not sure what to do
> about the javadoc warnings on the generated classes. From the comments
> in the pom, this seems to have been an issue since v2.4.
> Regards,
> Matt J{quote}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to