#237 Improving test/method names

This commit is contained in:
Gunnar Morling 2014-06-24 22:43:04 +02:00
parent 02c81ae651
commit 9a21198265
8 changed files with 35 additions and 45 deletions

View File

@ -16,12 +16,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.mapstruct.ap.test.npe; package org.mapstruct.ap.test.nullcheck;
import java.math.BigInteger; import java.math.BigInteger;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class MyBigIntMapper { public class MyBigIntMapper {

View File

@ -16,12 +16,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.mapstruct.ap.test.npe; package org.mapstruct.ap.test.nullcheck;
import java.math.BigInteger; import java.math.BigInteger;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class MyBigIntWrapper { public class MyBigIntWrapper {
@ -32,7 +31,7 @@ public class MyBigIntWrapper {
return myBigInt; return myBigInt;
} }
public void setMyBigInt( BigInteger myBigInt ) { public void setMyBigInt(BigInteger myBigInt) {
this.myBigInt = myBigInt; this.myBigInt = myBigInt;
} }
} }

View File

@ -16,21 +16,22 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.mapstruct.ap.test.npe; package org.mapstruct.ap.test.nullcheck;
import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for correct handling of null checks. * Test for correct handling of null checks.
* *
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@WithClasses( { @WithClasses({
SourceTargetMapper.class, SourceTargetMapper.class,
NullObjectMapper.class, NullObjectMapper.class,
NullObject.class, NullObject.class,
@ -38,12 +39,12 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
MyBigIntWrapper.class, MyBigIntWrapper.class,
Source.class, Source.class,
Target.class Target.class
} ) })
@RunWith( AnnotationProcessorTestRunner.class ) @RunWith(AnnotationProcessorTestRunner.class)
public class NullPtrCheckTest { public class NullCheckTest {
@IssueKey( "214" ) @Test(expected = NullPointerException.class)
@Test( expected = NullPointerException.class ) @IssueKey("214")
public void shouldThrowNullptrWhenCustomMapperIsInvoked() { public void shouldThrowNullptrWhenCustomMapperIsInvoked() {
Source source = new Source(); Source source = new Source();
@ -52,41 +53,40 @@ public class NullPtrCheckTest {
SourceTargetMapper.INSTANCE.sourceToTarget( source ); SourceTargetMapper.INSTANCE.sourceToTarget( source );
} }
@IssueKey( "214" )
@Test @Test
public void shouldSurroundTypeConversionWithNPECheck() { @IssueKey("214")
public void shouldSurroundTypeConversionWithNullCheck() {
Source source = new Source(); Source source = new Source();
source.setSomeObject( new NullObject() ); source.setSomeObject( new NullObject() );
source.setSomeInteger( 7 ); source.setSomeInteger( 7 );
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
assertThat( target.getNumber() ).isNull(); assertThat( target.getNumber() ).isNull();
} }
@IssueKey( "214" )
@Test @Test
public void shouldSurroundArrayListConstructionWithNPECheck() { @IssueKey("214")
public void shouldSurroundArrayListConstructionWithNullCheck() {
Source source = new Source(); Source source = new Source();
source.setSomeObject( new NullObject() ); source.setSomeObject( new NullObject() );
source.setSomeInteger( 7 ); source.setSomeInteger( 7 );
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
assertThat( target.getSomeList() ).isNull(); assertThat( target.getSomeList() ).isNull();
} }
@IssueKey( "237" )
@Test @Test
public void shouldMapMappedTypeConversion() { @IssueKey("237")
public void shouldSurroundConversionPassedToMappingMethodWithNullCheck() {
Source source = new Source(); Source source = new Source();
source.setSomeObject( new NullObject() ); source.setSomeObject( new NullObject() );
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
assertThat( target.getSomeList() ).isNull(); assertThat( target.getSomeList() ).isNull();
assertThat( target.getSomeInteger() ).isNull(); assertThat( target.getSomeInteger() ).isNull();
} }
} }

View File

@ -16,10 +16,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.mapstruct.ap.test.npe; package org.mapstruct.ap.test.nullcheck;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class NullObject { public class NullObject {

View File

@ -16,10 +16,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.mapstruct.ap.test.npe; package org.mapstruct.ap.test.nullcheck;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class NullObjectMapper { public class NullObjectMapper {

View File

@ -16,12 +16,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.mapstruct.ap.test.npe; package org.mapstruct.ap.test.nullcheck;
import java.util.List; import java.util.List;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class Source { public class Source {
@ -35,7 +34,7 @@ public class Source {
return someObject; return someObject;
} }
public void setSomeObject( NullObject someObject ) { public void setSomeObject(NullObject someObject) {
this.someObject = someObject; this.someObject = someObject;
} }
@ -43,7 +42,7 @@ public class Source {
return number; return number;
} }
public void setNumber( String number ) { public void setNumber(String number) {
this.number = number; this.number = number;
} }
@ -51,7 +50,7 @@ public class Source {
return someList; return someList;
} }
public void setSomeList( List<String> someList ) { public void setSomeList(List<String> someList) {
this.someList = someList; this.someList = someList;
} }
@ -59,7 +58,7 @@ public class Source {
return someInteger; return someInteger;
} }
public void setSomeInteger( Integer someInteger ) { public void setSomeInteger(Integer someInteger) {
this.someInteger = someInteger; this.someInteger = someInteger;
} }

View File

@ -16,16 +16,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.mapstruct.ap.test.npe; package org.mapstruct.ap.test.nullcheck;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@Mapper (uses = { NullObjectMapper.class, MyBigIntMapper.class } ) @Mapper(uses = { NullObjectMapper.class, MyBigIntMapper.class })
public interface SourceTargetMapper { public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );

View File

@ -16,12 +16,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.mapstruct.ap.test.npe; package org.mapstruct.ap.test.nullcheck;
import java.util.List; import java.util.List;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class Target { public class Target {
@ -35,7 +34,7 @@ public class Target {
return someObject; return someObject;
} }
public void setSomeObject( String someObject ) { public void setSomeObject(String someObject) {
this.someObject = someObject; this.someObject = someObject;
} }
@ -43,7 +42,7 @@ public class Target {
return number; return number;
} }
public void setNumber( Integer number ) { public void setNumber(Integer number) {
this.number = number; this.number = number;
} }
@ -51,7 +50,7 @@ public class Target {
return someList; return someList;
} }
public void setSomeList( List<String> someList ) { public void setSomeList(List<String> someList) {
this.someList = someList; this.someList = someList;
} }
@ -59,10 +58,7 @@ public class Target {
return someInteger; return someInteger;
} }
public void setSomeInteger( MyBigIntWrapper someInteger ) { public void setSomeInteger(MyBigIntWrapper someInteger) {
this.someInteger = someInteger; this.someInteger = someInteger;
} }
} }