Skip to content
Prev Previous commit
Next Next commit
#3943: Added negative test.
  • Loading branch information
anenviousguest committed Feb 28, 2026
commit daa1c2d1c38364abd7dc4e9258586d9817d0709e
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._3943;

import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface Issue3943ErroneousMapper {

Issue3943ErroneousMapper INSTANCE = Mappers.getMapper( Issue3943ErroneousMapper.class );

Target map(int somethingElse);

class Target {

private final int value;

public Target(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface Issue3943Mapper {

TargetWithMatchingProperty mapImplicitly(int value);

// TargetWithMatchingProperty mapImplicitlyWithoutMatchingProperty(int somethingElse);

@Mapping(target = "value", source = "value")
TargetWithMatchingProperty mapWithMatchingProperty(int value);

Expand All @@ -24,26 +26,26 @@ public interface Issue3943Mapper {

class TargetWithMatchingProperty {

private final long value;
private final int value;

public TargetWithMatchingProperty(long value) {
public TargetWithMatchingProperty(int value) {
this.value = value;
}

public long getValue() {
public int getValue() {
return value;
}
}

class TargetWithoutMatchingProperty {

private final long nonMatchingProperty;
private final int nonMatchingProperty;

public TargetWithoutMatchingProperty(long nonMatchingProperty) {
public TargetWithoutMatchingProperty(int nonMatchingProperty) {
this.nonMatchingProperty = nonMatchingProperty;
}

public long getNonMatchingProperty() {
public int getNonMatchingProperty() {
return nonMatchingProperty;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
*/
package org.mapstruct.ap.test.bugs._3943;

import javax.tools.Diagnostic.Kind;

import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.*;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -35,4 +38,18 @@ void shouldGenerateValidCodeForBeanWithoutMatchingProperty() {
assertThat( target ).isNotNull();
assertThat( target.getNonMatchingProperty() ).isEqualTo( 42L );
}

@ProcessorTest
@WithClasses( { Issue3943ErroneousMapper.class } )
@ExpectedCompilationOutcome(
value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = Issue3943ErroneousMapper.class,
kind = Kind.ERROR,
line = 16,
message = "Unmapped target property: \"value\"." )
}
)
void shouldFailToGenerateCodeIfPropertyNameDoesNotMatch() {
}
}