package de.retest.recheck.printer;

import java.util.function.Function;
import java.util.stream.Collectors;

import de.retest.recheck.ignore.ShouldIgnore;
import de.retest.recheck.report.ActionReplayResult;
import de.retest.recheck.report.TestReplayResult;
import de.retest.recheck.ui.DefaultValueFinder;

public class TestReplayResultPrinter implements Printer<TestReplayResult> {

	private final Function<String, DefaultValueFinder> defaultValueFinder;
	private final ShouldIgnore ignore;

	public TestReplayResultPrinter( final Function<String, DefaultValueFinder> defaultValueFinder,
			final ShouldIgnore ignore ) {
		this.defaultValueFinder = defaultValueFinder;
		this.ignore = ignore;
	}

	@Override
	public String toString( final TestReplayResult difference, final String indent ) {
		final String status = indent + testResult( difference );
		final String differences = difference.getActionReplayResults().stream() //
				.map( a -> formatAction( a, indent ) ) //
				.collect( Collectors.joining( "\n" ) );
		return status + "\n" + differences;
	}

	private String testResult( final TestReplayResult result ) {
		final String name = result.getName();
		final int differences = result.getDifferencesCount();
		final int unique = result.getDifferences( ignore ).size();
		return String.format( "Test '%s' has %d differences (%d unique):", name, differences, unique );
	}

	private String formatAction( final ActionReplayResult result, final String indent ) {
		final DefaultValueFinder finder = defaultValueFinder.apply( result.getDescription() );
		final ActionReplayResultPrinter printer = new ActionReplayResultPrinter( finder, ignore );
		return printer.toString( result, indent );
	}
}

@@ -1184,59 +1184,8 @@
 es =
- result.getDifferencesCount();%0A%09%09final int unique =
  res
@@ -1278,20 +1278,8 @@
 nces
- (%25d unique)
 :%22, 
@@ -1299,16 +1299,8 @@
 nces
-, unique
  );%0A

Fix faulty output with "unique" differences