package fi.vincit.multiusertest.util;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import fi.vincit.multiusertest.annotation.TestUsers;

public class TestConfiguration {

    private Set<UserIdentifier> creatorIdentifiers;
    private Set<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 Set<UserIdentifier> getDefinitions(String[] definitions) {
        if (definitions != null) {
            Set<UserIdentifier> userIdentifiers = new HashSet<>();
            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(Set<UserIdentifier> creatorIdentifiers, Set<UserIdentifier> userIdentifiers, Class<?> runner) {
        this.creatorIdentifiers = creatorIdentifiers;
        this.userIdentifiers = userIdentifiers;
        this.runner = runner;
    }

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

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

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

@@ -112,34 +112,18 @@
 til.
-HashSet;%0Aimport java.util.
+LinkedHash
 Set;
@@ -216,35 +216,42 @@
  %7B%0A%0A    private 
-Set
+Collection
 %3CUserIdentifier%3E
@@ -283,19 +283,26 @@
 private 
-Set
+Collection
 %3CUserIde
@@ -769,19 +769,26 @@
  static 
-Set
+Collection
 %3CUserIde
@@ -882,19 +882,26 @@
         
-Set
+Collection
 %3CUserIde
@@ -931,16 +931,22 @@
 s = new 
+Linked
 HashSet%3C
@@ -1384,19 +1384,26 @@
 uration(
-Set
+Collection
 %3CUserIde
@@ -1431,19 +1431,26 @@
 ifiers, 
-Set
+Collection
 %3CUserIde
@@ -1618,22 +1618,43 @@
 unner = 
+Optional.ofNullable(
 runner
+)
 ;%0A    %7D%0A

Change TestConfiguration to return Collections, make sure results are in order