diff --git a/pom.xml b/pom.xml
index 904c797..76569eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,6 +53,12 @@
ebul-reflection
0.0.1-SNAPSHOT
+
+ junit
+ junit
+ 4.12
+ test
+
diff --git a/src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java b/src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java
index 4a7e89d..1521386 100644
--- a/src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java
+++ b/src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java
@@ -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( ) ) {
diff --git a/src/test/java/info/ebenoit/ebul/cmp/TestDependencyInfo.java b/src/test/java/info/ebenoit/ebul/cmp/TestDependencyInfo.java
new file mode 100644
index 0000000..b0f47c6
--- /dev/null
+++ b/src/test/java/info/ebenoit/ebul/cmp/TestDependencyInfo.java
@@ -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 null
*/
+ @Test( expected = NullPointerException.class )
+ public void testNewWithNullName( )
+ {
+ new DependencyInfo( (String) null );
+ }
+
+
+ /** Test: class-based constructor throws {@link NullPointerException} if class is null
*/
+ @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 ] ) );
+ }
+}