package com.techshroom.unplanned.test;

import static org.junit.Assert.assertEquals;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.Set;

import org.junit.Test;

import com.techshroom.unplanned.core.util.LUtils;
import com.techshroom.unplanned.core.util.LUtils.LoggingGroup;

public class UtilityTest {

    /**
     * LUtils can limit the printing to certain groups.
     */
    @Test
    public void limitsGroups() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        // fool it into replacing the wrong streams so our life is easy.
        LUtils.init();
        PrintStream original = System.err;
        System.setErr(new PrintStream(out));
        for (Iterator<LoggingGroup> itr = LoggingGroup.ALL.iterator(); itr
                .hasNext();) {
            LoggingGroup g = itr.next();
            LUtils.setValidGroups(g);
            LUtils.print("YES", g);
            LUtils.print("NO", getRandomNotProvided(LoggingGroup.ALL, g));
        }
        // ensure all written
        System.err.flush();
        System.setErr(original);
        String str = out.toString();
        assertEquals("Logged wrong group: ", str, str.replace("NO", ""));
    }

    private <T> T getRandomNotProvided(Set<T> all, T g) {
        Iterator<T> itr = all.iterator();
        if (!itr.hasNext()) {
            return null;
        }
        T first = itr.next();
        if (g == first) {
            return itr.hasNext() ? itr.next() : null;
        }
        return first;
    }
}

@@ -193,16 +193,89 @@
 til.Set;
+%0Aimport java.util.function.Predicate;%0Aimport java.util.stream.Collectors;
 %0A%0Aimport
@@ -1035,601 +1035,498 @@
     
-LUtils.print(%22NO%22, getRandomNotProvided(LoggingGroup.ALL, g));%0A        %7D%0A        // ensure all written%0A        System.err.flush();%0A        System.setErr(original);%0A        String str = out.toString();%0A        assertEquals(%22Logged wrong group: %22, str, str.replace(%22NO%22, %22%22));%0A    %7D%0A%0A    private %3CT%3E T getRandomNotProvided(Set%3CT%3E all, T g) %7B%0A        Iterator%3CT%3E itr = all.iterator();%0A        if (!itr.hasNext()) %7B%0A            return null;%0A        %7D%0A        T first = itr.next();%0A        if (g == first) %7B%0A            return itr.hasNext() ? itr.next() : null;%0A        %7D%0A        return first;%0A    %7D
+Set%3CLoggingGroup%3E groups = LoggingGroup.ALL.stream()%0A                    .filter(Predicate.isEqual(g).negate())%0A                    .collect(Collectors.toSet());%0A            for (LoggingGroup nonGroup : groups) %7B%0A                LUtils.print(%22NO%22, nonGroup);%0A            %7D%0A        %7D%0A        // ensure all written%0A        System.err.flush();%0A        System.setErr(original);%0A        String str = out.toString();%0A        assertEquals(%22Logged wrong group: %22, str, str.replace(%22NO%22, %22%22));%0A    %7D%0A
 %0A%7D%0A

Change logging test