package de.retest.recheck.ui.review;

import java.util.Collections;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import de.retest.recheck.report.ActionReplayResult;
import de.retest.recheck.ui.descriptors.IdentifyingAttributes;
import de.retest.recheck.ui.diff.ElementDifference;
import de.retest.recheck.ui.diff.RootElementDifference;
import de.retest.recheck.ui.image.Screenshot;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor( access = AccessLevel.PRIVATE )
public class ScreenshotChanges {

	private static final ScreenshotChanges EMPTY_SCREENSHOTS = new ScreenshotChanges( Collections.emptyMap() );

	private final Map<IdentifyingAttributes, Screenshot> screenshotMap;

	public static ScreenshotChanges empty() {
		return EMPTY_SCREENSHOTS;
	}

	public static ScreenshotChanges actual( final ActionReplayResult result ) {
		return new ScreenshotChanges( result.getStateDifference().getRootElementDifferences().stream() //
				.filter( actualScreenshotNotNull() ) //
				.map( RootElementDifference::getElementDifference ) //
				.collect( Collectors.toMap( ElementDifference::getIdentifyingAttributes,
						ElementDifference::getActualScreenshot ) ) );
	}

	private static Predicate<RootElementDifference> actualScreenshotNotNull() {
		return difference -> difference.getActualScreenshot() != null;
	}

	public Screenshot getScreenshot( final IdentifyingAttributes attribute ) {
		return screenshotMap.get( attribute );
	}
}

@@ -372,32 +372,82 @@
 mentDifference;%0A
+import de.retest.recheck.ui.diff.StateDifference;%0A
 import de.retest
@@ -962,24 +962,163 @@
  result ) %7B%0A
+%09%09final StateDifference stateDifference = result.getStateDifference();%0A%09%09if ( stateDifference == null ) %7B%0A%09%09%09return EMPTY_SCREENSHOTS;%0A%09%09%7D%0A
 %09%09return new
@@ -1137,27 +1137,17 @@
 hanges( 
-result.getS
+s
 tateDiff
@@ -1152,18 +1152,16 @@
 fference
-()
 .getRoot

Fix when differences are null