package io.quarkus.container.image.deployment;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Optional;

import org.junit.jupiter.api.Test;

class ContainerImageConfigEffectiveGroupTest {

    public static final String USER_NAME_SYSTEM_PROPERTY = "user.name";

    private ContainerImageConfig sut = new ContainerImageConfig();

    @Test
    void testFromLowercaseUsername() {
        testWithNewUsername("test", () -> {
            sut.group = Optional.of(System.getProperty(USER_NAME_SYSTEM_PROPERTY));
            assertEquals(sut.getEffectiveGroup(), Optional.of("test"));
        });
    }

    @Test
    void testFromUppercaseUsername() {
        testWithNewUsername("TEST", () -> {
            sut.group = Optional.of(System.getProperty(USER_NAME_SYSTEM_PROPERTY));
            assertEquals(sut.getEffectiveGroup(), Optional.of("test"));
        });
    }

    @Test
    void testFromOther() {
        testWithNewUsername("WhateveR", () -> {
            sut.group = Optional.of("OtheR");
            assertEquals(sut.getEffectiveGroup(), Optional.of("OtheR"));
        });
    }

    private void testWithNewUsername(String newUserName, Runnable test) {
        String previousUsernameValue = System.getProperty(USER_NAME_SYSTEM_PROPERTY);
        System.setProperty(USER_NAME_SYSTEM_PROPERTY, newUserName);

        test.run();

        System.setProperty(USER_NAME_SYSTEM_PROPERTY, previousUsernameValue);
    }
}

@@ -884,32 +884,308 @@
      %7D);%0A    %7D%0A%0A
+    @Test%0A    void testFromSpaceInUsername() %7B%0A        testWithNewUsername(%22user name%22, () -%3E %7B%0A            sut.group = Optional.of(System.getProperty(USER_NAME_SYSTEM_PROPERTY));%0A            assertEquals(sut.getEffectiveGroup(), Optional.of(%22user-name%22));%0A        %7D);%0A    %7D%0A%0A
     @Test%0A    vo

Test for spaces removal from quarkus.container-image.group when it's set to the username