#81 adding unit test for ambiguous factory error

This commit is contained in:
sjaakd 2014-02-02 19:08:11 +01:00
parent 11ba30f8a5
commit 3f94c51884
8 changed files with 290 additions and 2 deletions

View File

@ -231,8 +231,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
Kind.ERROR,
String.format(
"Ambigious factory method: \"%s\" conflicts with \"%s\".",
result.getName(),
method.getName()
result,
method
),
method.getExecutable()
);

View File

@ -0,0 +1,45 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
/**
* @author Sjaak Derksen
*
*/
public class Bar {
private String prop;
private final String someTypeProp;
public Bar( String someTypeProp ) {
this.someTypeProp = someTypeProp;
}
public String getProp() {
return prop;
}
public void setProp(String prop) {
this.prop = prop;
}
public String getSomeTypeProp() {
return someTypeProp;
}
}

View File

@ -0,0 +1,58 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
import org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.a.BarFactory;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test;
/**
* @author Sjaak Derksen
*
*/
@IssueKey( "81" )
@WithClasses( { Bar.class, Foo.class, BarFactory.class, Source.class, SourceTargetMapperAndBarFactory.class,
Target.class } )
public class FactoryTest extends MapperTestBase {
@Test
@IssueKey("81")
@ExpectedCompilationOutcome(
value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = BarFactory.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 30,
messageRegExp = "^Ambigious factory method: \"org\\.mapstruct\\.ap\\.test\\.erroneous\\."
+ "ambiguousfactorymethod\\.Bar createBar\\(\\)\" conflicts with "
+ "\"org\\.mapstruct\\.ap\\.test\\.erroneous\\.ambiguousfactorymethod\\.Bar "
+ "org\\.mapstruct\\.ap\\.test\\.erroneous\\.ambiguousfactorymethod"
+ "\\.a\\.BarFactory\\.createBar\\(\\)\"\\.$")
}
)
public void shouldUseTwoFactoryMethods() {
}
}

View File

@ -0,0 +1,36 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
/**
* @author Sjaak Derksen
*
*/
public class Foo {
private String prop;
public String getProp() {
return prop;
}
public void setProp(String prop) {
this.prop = prop;
}
}

View File

@ -0,0 +1,37 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
/**
* @author Sjaak Derksen
*
*/
public class Source {
private Foo prop;
public Foo getProp() {
return prop;
}
public void setProp( Foo prop ) {
this.prop = prop;
}
}

View File

@ -0,0 +1,41 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
import org.mapstruct.Mapper;
import org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.a.BarFactory;
import org.mapstruct.factory.Mappers;
/**
* @author Sjaak Derksen
*
*/
@Mapper( uses = BarFactory.class )
public abstract class SourceTargetMapperAndBarFactory {
public static final SourceTargetMapperAndBarFactory INSTANCE =
Mappers.getMapper( SourceTargetMapperAndBarFactory.class );
public abstract Target sourceToTarget(Source source);
public abstract Bar fooToBar(Foo foo);
public Bar createBar() {
return new Bar("BAR");
}
}

View File

@ -0,0 +1,37 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
/**
* @author Sjaak Derksen
*
*/
public class Target {
private Bar prop;
public Bar getProp() {
return prop;
}
public void setProp(Bar prop) {
this.prop = prop;
}
}

View File

@ -0,0 +1,34 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.a;
import org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar;
/**
*
* @author Sjaak Derksen
*/
public class BarFactory {
public Bar createBar() {
return new Bar("BAR");
}
}