package fi.vincit.multiusertest.util;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;

import fi.vincit.multiusertest.annotation.TestUsers;

public class TestConfiguration {

    private Collection<UserIdentifier> creatorIdentifiers;
    private Collection<UserIdentifier> userIdentifiers;
    private Class<?> runner;

    public static TestConfiguration fromTestUsers(TestUsers testUsers) {
        if (testUsers != null) {
            return new TestConfiguration(
                    getDefinitions(testUsers.creators()),
                    getDefinitions(testUsers.users()),
                    testUsers.runner()
            );
        } else {
            return new TestConfiguration();
        }
    }

    private static Collection<UserIdentifier> getDefinitions(String[] definitions) {
        if (definitions != null) {
            Collection<UserIdentifier> userIdentifiers = new LinkedHashSet<>();
            for (String user : definitions) {
                userIdentifiers.add(UserIdentifier.parse(user));
            }
            return userIdentifiers;
        } else {
            return Collections.emptySet();
        }
    }

    TestConfiguration() {
        this.creatorIdentifiers = Collections.emptySet();
        this.userIdentifiers = Collections.emptySet();
        this.runner = null;
    }

    TestConfiguration(Collection<UserIdentifier> creatorIdentifiers, Collection<UserIdentifier> userIdentifiers, Class<?> runner) {
        this.creatorIdentifiers = creatorIdentifiers;
        this.userIdentifiers = userIdentifiers;
        this.runner = Optional.ofNullable(runner);
    }

    public Collection<UserIdentifier> getCreatorIdentifiers() {
        return creatorIdentifiers;
    }

    public Collection<UserIdentifier> getUserIdentifiers() {
        return userIdentifiers;
    }

    public Class<?> getRunner() {
        return runner;
    }
}

@@ -339,24 +339,33 @@
 private 
+Optional%3C
 Class%3C?%3E
  runner;
@@ -352,24 +352,25 @@
 nal%3CClass%3C?%3E
+%3E
  runner;%0A%0A  
@@ -1359,20 +1359,32 @@
 unner = 
-null
+Optional.empty()
 ;%0A    %7D%0A
@@ -1893,24 +1893,33 @@
  public 
+Optional%3C
 Class%3C?%3E
  getRunn
@@ -1910,16 +1910,17 @@
 Class%3C?%3E
+%3E
  getRunn

Change TestConfiguration to user Optional