mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#36 Specifying expected diagnostic messages in processor tests
This commit is contained in:
parent
60126183a3
commit
c0bd8c7b18
@ -28,6 +28,11 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Test for illegal mappings between iterable and non-iterable types.
|
||||
*
|
||||
* @author Gunnar Morling
|
||||
*/
|
||||
@WithClasses({ ErronuousMapper.class })
|
||||
public class ErronuousCollectionMappingTest extends MapperTestBase {
|
||||
|
||||
@ -36,8 +41,14 @@ public class ErronuousCollectionMappingTest extends MapperTestBase {
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErronuousMapper.class, kind = Kind.ERROR, line = 28),
|
||||
@Diagnostic(type = ErronuousMapper.class, kind = Kind.ERROR, line = 30)
|
||||
@Diagnostic(type = ErronuousMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 28,
|
||||
messageRegExp = "Can't generate mapping method from iterable type to non-iterable type\\."),
|
||||
@Diagnostic(type = ErronuousMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 30,
|
||||
messageRegExp = "Can't generate mapping method from non-iterable type to iterable type\\.")
|
||||
}
|
||||
)
|
||||
public void shouldFailToGenerateMappingFromListToString() {
|
||||
|
@ -28,6 +28,11 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Test for using unknown attributes in {@code @Mapping}.
|
||||
*
|
||||
* @author Gunnar Morling
|
||||
*/
|
||||
@WithClasses({ ErroneousMapper.class, Source.class, Target.class, AnotherTarget.class })
|
||||
public class ErroneousMappingsTest extends MapperTestBase {
|
||||
|
||||
@ -36,8 +41,14 @@ public class ErroneousMappingsTest extends MapperTestBase {
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 27),
|
||||
@Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 30)
|
||||
@Diagnostic(type = ErroneousMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 27,
|
||||
messageRegExp = "Unknown property \"bar\" in return type.*"),
|
||||
@Diagnostic(type = ErroneousMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 30,
|
||||
messageRegExp = "Unknown property \"bar\" in parameter type.*")
|
||||
}
|
||||
)
|
||||
public void shouldFailToGenerateMappings() {
|
||||
|
@ -28,6 +28,11 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests failures expected for unmappable attributes.
|
||||
*
|
||||
* @author Gunnar Morling
|
||||
*/
|
||||
@WithClasses({ ErroneousMapper.class, Source.class, Target.class })
|
||||
public class ErroneousMappingsTest extends MapperTestBase {
|
||||
|
||||
@ -36,10 +41,22 @@ public class ErroneousMappingsTest extends MapperTestBase {
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 26),
|
||||
@Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 28),
|
||||
@Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 30),
|
||||
@Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 32)
|
||||
@Diagnostic(type = ErroneousMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 26,
|
||||
messageRegExp = "Can't map property \"boolean foo\" to \"int foo\"\\."),
|
||||
@Diagnostic(type = ErroneousMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 28,
|
||||
messageRegExp = "Can't map property \"int foo\" to \"boolean foo\"\\."),
|
||||
@Diagnostic(type = ErroneousMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 30,
|
||||
messageRegExp = "Can't generate mapping method with primitive return type\\."),
|
||||
@Diagnostic(type = ErroneousMapper.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 32,
|
||||
messageRegExp = "Can't generate mapping method with primitive parameter type\\.")
|
||||
}
|
||||
)
|
||||
public void shouldFailToGenerateMappings() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user