/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.reflection.mockup;

import java.util.List;
import java.util.stream.Collectors;
import net.ranides.assira.generic.CompareUtils;
import net.ranides.assira.junit.NewAssert;
import net.ranides.assira.reflection.IClasses;
import net.ranides.assira.reflection.IMethod;
import net.ranides.assira.reflection.IMethods;
import net.ranides.assira.text.StringUtils;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class TestReflective {
    
    public static List<String> remove(List<String> input) {
        return input.stream()
            .filter(n -> !n.toString().contains("jacoco"))
            .map(n -> n.replaceAll("\\$[0-9]+", "#"))
            .collect(Collectors.toList());
    }
    
    public static String asText(IMethod m) {
        return m.name() + " " + m.arguments().types();
    }
    
    public static List<String> asText(List<?> list) {
        return list.stream().map(Object::toString).collect(Collectors.toList());
    }
    
    public static void print(List<String> $0, List<?> values) {
        values.sort(CompareUtils.comparator());
        System.out.printf("%s%n", StringUtils.join(values, ", ", v -> StringUtils.quote(v.toString())));
    }
    
    public static void print(List<String> $0, IMethods methods) {
        System.out.printf(">>>>%n");
        methods.each(c -> {
            System.out.printf("    %s%n", asText(c));
        });
    }
    
    public static void print(List<String> $0, IClasses methods) {
        System.out.printf(">>>>%n");
        methods.each(c -> {
            System.out.printf("   \"%s\",%n", c);
        });
    }
    
    public static <T> void assertEquals(List<String> expected, List<String> input) {
        NewAssert.assertEquivalent(expected, asText(remove(input)));
    }
    
    public static void assertEquals(List<String> expected, IMethods methods) {
        NewAssert.assertEquivalent(expected, remove(methods.list(m -> asText(m))));
    }
    
    public static void assertEquals(List<String> expected, IClasses classes) {
        NewAssert.assertEquivalent(expected, remove(classes.list(m -> m.toString())));
    }
    
}
