Skip to content

Commit

Permalink
Persisting Mockito objects with moxy don't work anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-v authored and mergify-bot committed May 28, 2021
1 parent d1cde4d commit fdd735a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
17 changes: 13 additions & 4 deletions src/test/java/de/retest/recheck/RecheckImplIT.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package de.retest.recheck;

import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -13,6 +11,7 @@
import de.retest.recheck.ignore.CompoundFilter;
import de.retest.recheck.ignore.Filter;
import de.retest.recheck.ignore.Filters;
import de.retest.recheck.persistence.FileNamer;
import de.retest.recheck.ui.DefaultValueFinder;
import de.retest.recheck.ui.Path;
import de.retest.recheck.ui.descriptors.Element;
Expand Down Expand Up @@ -48,9 +47,19 @@ void diff_should_be_created_with_deleted_filtered() {
}

@Test
@SuppressWarnings( "deprecation" )
void diff_should_handle_legacy_spaces_accordingly() {
final FileNamerStrategy fileNamerStrategy = spy( new MavenConformFileNamerStrategy() );
doReturn( RecheckImplIT.class.getName() + " legacy spaces" ).when( fileNamerStrategy ).getTestClassName();
final FileNamerStrategy fileNamerStrategy = new FileNamerStrategy() {
@Override
public FileNamer createFileNamer( final String... baseNames ) {
return new MavenConformFileNamerStrategy().createFileNamer( baseNames );
}

@Override
public String getTestClassName() {
return RecheckImplIT.class.getName() + " legacy spaces";
}
};

execute( "with legacy spaces", RecheckOptions.builder() //
.setIgnore( METADATA_FILTER ) // Ignore metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@

import static de.retest.recheck.RecheckProperties.AGGREGATED_TEST_REPORT_FILE_NAME;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import de.retest.recheck.report.ActionReplayResult;
import de.retest.recheck.report.SuiteReplayResult;
import de.retest.recheck.report.TestReplayResult;
import de.retest.recheck.report.action.ActionReplayData;
import de.retest.recheck.ui.descriptors.Attributes;
import de.retest.recheck.ui.descriptors.IdentifyingAttributes;
import de.retest.recheck.ui.descriptors.RootElement;
import de.retest.recheck.ui.diff.ElementBuilder;
import de.retest.recheck.ui.diff.ElementBuilder.child2;
import de.retest.recheck.ui.diff.ElementDifference;
import de.retest.recheck.ui.diff.RootElementDifference;
import de.retest.recheck.ui.diff.StateDifference;

class RecheckTestReportUtilTest {

Expand All @@ -27,8 +38,7 @@ void setUp( @TempDir final Path temp ) {

@Test
void persist_should_create_report_when_there_are_no_diffs() {
final SuiteReplayResult replayResult = mock( SuiteReplayResult.class );
when( replayResult.getDifferencesCount() ).thenReturn( 0 );
final SuiteReplayResult replayResult = new SuiteReplayResult( "test", 23, null, "00", null );

RecheckTestReportUtil.persist( replayResult, testReport );

Expand All @@ -37,18 +47,33 @@ void persist_should_create_report_when_there_are_no_diffs() {

@Test
void persist_should_create_report_when_there_are_diffs() {
final SuiteReplayResult replayResult = mock( SuiteReplayResult.class );
when( replayResult.getDifferencesCount() ).thenReturn( 1 );
final SuiteReplayResult replayResult = new SuiteReplayResult( "test", 23, null, "00", null );
replayResult.addTest( createDummyReplayResultWithOneDiff() );

RecheckTestReportUtil.persist( replayResult, testReport );

assertThat( testReport ).exists();
}

TestReplayResult createDummyReplayResultWithOneDiff() {
final RootElement root = new RootElement( "retestId",
new IdentifyingAttributes( ElementBuilder
.createIdentifyingAttribute( de.retest.recheck.ui.Path.fromString( "comp1" ), child2.class ) ),
new Attributes(), null, "screen", 1, "title" );
final ActionReplayResult test = ActionReplayResult.createActionReplayResult( ActionReplayData.empty(),
new StateDifference( Arrays.asList( new RootElementDifference(
new ElementDifference( root, null, null, null, null, Collections.emptyList() ), root,
null ) ) ),
1, null );

final TestReplayResult testReplayResult = new TestReplayResult( "test", 1 );
testReplayResult.addAction( test );
return testReplayResult;
}

@Test
void persist_should_create_missing_folders() {
final SuiteReplayResult replayResult = mock( SuiteReplayResult.class );
when( replayResult.getDifferencesCount() ).thenReturn( 0 );
final SuiteReplayResult replayResult = new SuiteReplayResult( "test", 23, null, "00", null );

RecheckTestReportUtil.persist( replayResult, testReportMissingFolders );

Expand All @@ -57,7 +82,7 @@ void persist_should_create_missing_folders() {

@Test
void persist_should_create_aggregated_test_report() throws Exception {
final SuiteReplayResult replayResult = mock( SuiteReplayResult.class );
final SuiteReplayResult replayResult = new SuiteReplayResult( "test", 23, null, "00", null );

RecheckTestReportUtil.persist( replayResult, testReport );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.retest.recheck.review;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

import java.awt.Rectangle;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -206,7 +206,9 @@ public DefaultValueFinder getDefaultValueFinder() {

@Override
public void notifyAboutDifferences( final ActionReplayResult actionReplayResult ) {
final ElementIdentificationWarning warning = mock( ElementIdentificationWarning.class );
final ElementIdentificationWarning warning = new ElementIdentificationWarning( "testFileName",
new Random().nextInt(), "findByMethodName", "qualifiedTestName" );

actionReplayResult.getAllElementDifferences().stream() //
.map( ElementDifference::getAttributeDifferences ) //
.flatMap( Collection::stream ) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import de.retest.recheck.ui.descriptors.TextAttribute;
import de.retest.recheck.ui.image.Screenshot;

class ElementBuilder {
public class ElementBuilder {

public static Element buildElement() {
final IdentifyingAttributes identifyingAttributes =
Expand Down

0 comments on commit fdd735a

Please sign in to comment.