Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -18,6 +19,7 @@
import org.assertj.core.internal.Diff;
import org.assertj.core.internal.Failures;
import org.assertj.core.util.diff.Delta;
import org.opentest4j.FileInfo;

import static java.lang.String.format;

Expand Down Expand Up @@ -81,8 +83,22 @@ public void hasSameMapperContent(File expected) {
) );
diffs.removeIf( this::ignoreDelta );
if ( !diffs.isEmpty() ) {
FileInfo actualInfo;
FileInfo expectedInfo;
try {
actualInfo = new FileInfo( actual.getAbsolutePath(), Files.readAllBytes( actual.toPath() ) );
expectedInfo = new FileInfo( expected.getAbsolutePath(), Files.readAllBytes( expected.toPath() ) );
}
catch ( IOException e ) {
throw new RuntimeException( e );
}
throw Failures.instance()
.failure( info, ShouldHaveSameContent.shouldHaveSameContent( actual, expected, diffs ) );
.failure(
info,
ShouldHaveSameContent.shouldHaveSameContent( actual, expected, diffs ),
actualInfo,
expectedInfo
);
}
}
catch ( IOException e ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ boolean needsRecompilation(CompilationRequest compilationRequest, CompilationCac
return !compilationRequest.equals( compilationCache.getLastRequest() );
}

private static String getBasePath() {
static String getBasePath() {
try {
return new File( "." ).getCanonicalPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
package org.mapstruct.ap.testutil.runner;

import java.io.File;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -19,6 +16,7 @@

import static org.assertj.core.api.Assertions.fail;
import static org.mapstruct.ap.testutil.runner.CompilingExtension.NAMESPACE;
import static org.mapstruct.ap.testutil.runner.CompilingExtension.getBasePath;

/**
* A {@link org.junit.jupiter.api.extension.RegisterExtension RegisterExtension} to perform assertions on generated
Expand All @@ -36,6 +34,7 @@
public class GeneratedSource implements BeforeTestExecutionCallback, AfterTestExecutionCallback {

private static final String FIXTURES_ROOT = "fixtures/";
private static final String FIXTURES_DIR = getBasePath() + "/src/test/resources/fixtures/";

/**
* ThreadLocal, as the source dir must be injected for this extension to gain access
Expand Down Expand Up @@ -139,17 +138,16 @@ public JavaFileAssert forJavaFile(String path) {
private void handleFixtureComparison() {
for ( FixtureComparison fixture : fixturesFor ) {
String fixtureName = getFixtureName( fixture.mapperClass, fixture.variant );
URL expectedFile = getExpectedResource( fixtureName );
if ( expectedFile == null ) {
File expectedFile = getExpectedResource( fixtureName );
if ( !expectedFile.exists() ) {
fail( String.format(
"No reference file could be found for Mapper %s. You should create a file %s",
fixture.mapperClass.getName(),
FIXTURES_ROOT + fixtureName
) );
}
else {
File expectedResource = new File( URLDecoder.decode( expectedFile.getFile(), StandardCharsets.UTF_8 ) );
forMapper( fixture.mapperClass ).hasSameMapperContent( expectedResource );
forMapper( fixture.mapperClass ).hasSameMapperContent( expectedFile );
}
}
}
Expand All @@ -159,16 +157,15 @@ private String getFixtureName(Class<?> mapperClass, String variant) {
return mapperClass.getName().replace( '.', '/' ).concat( suffix );
}

private URL getExpectedResource(String fixtureName) {
ClassLoader classLoader = getClass().getClassLoader();
private File getExpectedResource(String fixtureName) {
for ( int version = Runtime.version().feature(); version >= 11 && compiler != Compiler.ECLIPSE; version-- ) {
URL resource = classLoader.getResource( FIXTURES_ROOT + "/" + version + "/" + fixtureName );
if ( resource != null ) {
return resource;
File fixtureFile = new File( FIXTURES_DIR + version + File.separator + fixtureName );
if ( fixtureFile.exists() ) {
return fixtureFile;
}
}

return classLoader.getResource( FIXTURES_ROOT + fixtureName );
return new File( FIXTURES_DIR + fixtureName );
}

private static final class FixtureComparison {
Expand Down
Loading