Started writing tests
This commit is contained in:
parent
e2de94eb7b
commit
93e8c9a90e
3 changed files with 77 additions and 0 deletions
6
pom.xml
6
pom.xml
|
@ -53,6 +53,12 @@
|
|||
<artifactId>ebul-reflection</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package info.ebenoit.ebul.cmp;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class carries information about a dependency's target. Dependencies may be specified by name or by type.
|
||||
*
|
||||
|
@ -29,6 +33,7 @@ public class DependencyInfo
|
|||
*/
|
||||
public DependencyInfo( final String name )
|
||||
{
|
||||
Objects.requireNonNull( name );
|
||||
this.name = name;
|
||||
this.klass = null;
|
||||
}
|
||||
|
@ -45,6 +50,7 @@ public class DependencyInfo
|
|||
public DependencyInfo( final Class< ? > klass )
|
||||
throws ComponentDefinitionException
|
||||
{
|
||||
Objects.requireNonNull( klass );
|
||||
this.name = null;
|
||||
this.klass = klass;
|
||||
if ( klass.isPrimitive( ) ) {
|
||||
|
|
65
src/test/java/info/ebenoit/ebul/cmp/TestDependencyInfo.java
Normal file
65
src/test/java/info/ebenoit/ebul/cmp/TestDependencyInfo.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
package info.ebenoit.ebul.cmp;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
|
||||
/** Tests for {@link DependencyInfo} */
|
||||
public class TestDependencyInfo
|
||||
{
|
||||
|
||||
/** Test: name-based constructor throws {@link NullPointerException} if name is <code>null</code> */
|
||||
@Test( expected = NullPointerException.class )
|
||||
public void testNewWithNullName( )
|
||||
{
|
||||
new DependencyInfo( (String) null );
|
||||
}
|
||||
|
||||
|
||||
/** Test: class-based constructor throws {@link NullPointerException} if class is <code>null</code> */
|
||||
@Test( expected = NullPointerException.class )
|
||||
public void testNewWithNullClass( )
|
||||
{
|
||||
new DependencyInfo( (Class< ? >) null );
|
||||
}
|
||||
|
||||
|
||||
/** Test: class-based constructor throws {@link ComponentDefinitionException} if class is a primitive type */
|
||||
@Test( expected = ComponentDefinitionException.class )
|
||||
public void testNewWithPrimitiveType( )
|
||||
{
|
||||
new DependencyInfo( int.class );
|
||||
}
|
||||
|
||||
|
||||
/** Test: class-based constructor throws {@link ComponentDefinitionException} if class is an array type */
|
||||
@Test( expected = ComponentDefinitionException.class )
|
||||
public void testNewWithArrayType( )
|
||||
{
|
||||
new DependencyInfo( Object[].class );
|
||||
}
|
||||
|
||||
|
||||
/** Test: equals() method */
|
||||
@Test
|
||||
public void testEquals( )
|
||||
{
|
||||
DependencyInfo[] di = new DependencyInfo[] {
|
||||
new DependencyInfo( "test" ) , new DependencyInfo( "test" ) , new DependencyInfo( "test2" ) ,
|
||||
new DependencyInfo( String.class ) , new DependencyInfo( String.class ) ,
|
||||
new DependencyInfo( Object.class )
|
||||
};
|
||||
|
||||
assertTrue( di[ 0 ].equals( di[ 0 ] ) );
|
||||
assertTrue( di[ 0 ].equals( di[ 1 ] ) );
|
||||
assertFalse( di[ 0 ].equals( di[ 2 ] ) );
|
||||
assertFalse( di[ 0 ].equals( di[ 3 ] ) );
|
||||
|
||||
assertTrue( di[ 3 ].equals( di[ 3 ] ) );
|
||||
assertTrue( di[ 3 ].equals( di[ 4 ] ) );
|
||||
assertFalse( di[ 3 ].equals( di[ 5 ] ) );
|
||||
assertFalse( di[ 3 ].equals( di[ 0 ] ) );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue