package io.quarkus.test.junit.launcher;

import static io.quarkus.test.junit.IntegrationTestUtil.DEFAULT_WAIT_TIME_SECONDS;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.OptionalLong;

import org.eclipse.microprofile.config.Config;

public final class ConfigUtil {

    private ConfigUtil() {
    }

    public static List<String> argLineValue(Config config) {
        List<String> strings = config.getOptionalValues("quarkus.test.arg-line", String.class)
                .orElse(config.getOptionalValues("quarkus.test.argLine", String.class) // legacy value
                        .orElse(Collections.emptyList()));
        if (strings.isEmpty()) {
            return strings;
        }
        List<String> sanitizedString = new ArrayList<>(strings.size());
        for (String s : strings) {
            String trimmed = s.trim();
            if (trimmed.isEmpty()) {
                continue;
            }
            sanitizedString.add(trimmed);
        }
        return sanitizedString;
    }

    public static Duration waitTimeValue(Config config) {
        return Duration.ofSeconds(config.getValue("quarkus.test.wait-time", OptionalLong.class)
                .orElse(config.getValue("quarkus.test.jar-wait-time", OptionalLong.class) // legacy value
                        .orElse(DEFAULT_WAIT_TIME_SECONDS)));
    }
}

@@ -446,28 +446,23 @@
     
-List%3C
 String
-%3E
  str
-ings
+Value
  = c
@@ -475,33 +475,32 @@
 getOptionalValue
-s
 (%22quarkus.test.a
@@ -570,17 +570,16 @@
 nalValue
-s
 (%22quarku
@@ -661,31 +661,12 @@
 lse(
-Collections.emptyList()
+null
 ));%0A
@@ -684,22 +684,21 @@
 (str
-ings.isEmpty()
+Value == null
 ) %7B%0A
@@ -716,23 +716,39 @@
  return 
-strings
+Collections.emptyList()
 ;%0A      
@@ -763,36 +763,76 @@
     
-List%3C
 String
-%3E sanitizedString
+%5B%5D parts = strValue.split(%22%5C%5Cs+%22);%0A        List%3CString%3E result
  = n
@@ -850,22 +850,20 @@
 t%3C%3E(
-strings.size()
+parts.length
 );%0A 
@@ -889,14 +889,12 @@
 s : 
-string
+part
 s) %7B
@@ -1022,31 +1022,22 @@
         
-sanitizedString
+result
 .add(tri
@@ -1072,23 +1072,14 @@
 urn 
-sanitizedString
+result
 ;%0A  

Fix quarkus.test.arg-line multiple args handling