Skip to content

Commit

Permalink
BVTCK-32 Adding tests for passing null to ExecutableValidator methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling authored and hferentschik committed Jan 25, 2013
1 parent dd4607e commit 98818a0
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 0 deletions.
Expand Up @@ -41,6 +41,7 @@
import org.hibernate.beanvalidation.tck.tests.methodvalidation.model.User;
import org.hibernate.beanvalidation.tck.tests.methodvalidation.model.User.Basic;
import org.hibernate.beanvalidation.tck.tests.methodvalidation.model.User.Extended;
import org.hibernate.beanvalidation.tck.util.Groups;
import org.hibernate.beanvalidation.tck.util.TestUtil;
import org.hibernate.beanvalidation.tck.util.shrinkwrap.WebArchiveBuilder;

Expand All @@ -50,6 +51,7 @@
import static org.hibernate.beanvalidation.tck.util.TestUtil.assertCorrectPathNodeNames;
import static org.hibernate.beanvalidation.tck.util.TestUtil.kinds;
import static org.hibernate.beanvalidation.tck.util.TestUtil.names;

import static org.testng.Assert.assertEquals;

/**
Expand Down Expand Up @@ -373,4 +375,56 @@ public void testGetInvalidValueForCrossParameterConstraintOnParameterlessMethod(
assertCorrectNumberOfViolations( violations, 1 );
assertEquals( violations.iterator().next().getInvalidValue(), parameterValues );
}

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "5.1.2", id = "i")
public void testNullPassedForConstructorCausesException() throws Exception {
Constructor<User> constructor = null;
Object[] parameterValues = new Object[] { null };

executableValidator.validateConstructorParameters(
constructor,
parameterValues
);
}

//fails due to https://hibernate.onjira.com/browse/HV-681
@Test(expectedExceptions = IllegalArgumentException.class, groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "5.1.2", id = "i")
public void testNullPassedForParameterValuesCausesException() throws Exception {
Constructor<User> constructor = User.class.getConstructor( String.class );
Object[] parameterValues = null;

executableValidator.validateConstructorParameters(
constructor,
parameterValues
);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "5.1.2", id = "i")
public void testNullPassedForGroupsCausesException() throws Exception {
Constructor<User> constructor = User.class.getConstructor( String.class );
Object[] parameterValues = new Object[] { null };

executableValidator.validateConstructorParameters(
constructor,
parameterValues,
(Class<?>[]) null
);
}

//fails due to https://hibernate.onjira.com/browse/HV-681
@Test(expectedExceptions = IllegalArgumentException.class, groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "5.1.2", id = "i")
public void testNullPassedAsSingleGroupCausesException() throws Exception {
Constructor<User> constructor = User.class.getConstructor( String.class );
Object[] parameterValues = new Object[] { null };

executableValidator.validateConstructorParameters(
constructor,
parameterValues,
(Class<?>) null
);
}
}
Expand Up @@ -239,4 +239,56 @@ public void testUnexpectedType() throws Exception {

executableValidator.validateConstructorReturnValue( constructor, returnValue );
}

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "5.1.2", id = "l")
public void testNullPassedForConstructorCausesException() throws Exception {
Constructor<Customer> constructor = null;
Customer returnValue = new Customer();

executableValidator.validateConstructorReturnValue(
constructor,
returnValue
);
}

//fails due to https://hibernate.onjira.com/browse/HV-681
@Test(expectedExceptions = IllegalArgumentException.class, groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "5.1.2", id = "l")
public void testNullPassedForReturnValueCausesException() throws Exception {
Constructor<Customer> constructor = Customer.class.getConstructor();
Customer returnValue = null;

executableValidator.validateConstructorReturnValue(
constructor,
returnValue
);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "5.1.2", id = "l")
public void testNullPassedForGroupsCausesException() throws Exception {
Constructor<Customer> constructor = Customer.class.getConstructor();
Customer returnValue = new Customer();

executableValidator.validateConstructorReturnValue(
constructor,
returnValue,
(Class<?>[]) null
);
}

//fails due to https://hibernate.onjira.com/browse/HV-681
@Test(expectedExceptions = IllegalArgumentException.class, groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "5.1.2", id = "l")
public void testNullPassedAsSingleGroupCausesException() throws Exception {
Constructor<Customer> constructor = Customer.class.getConstructor();
Customer returnValue = new Customer();

executableValidator.validateConstructorReturnValue(
constructor,
returnValue,
(Class<?>) null
);
}
}
Expand Up @@ -41,6 +41,7 @@
import org.hibernate.beanvalidation.tck.tests.methodvalidation.model.User;
import org.hibernate.beanvalidation.tck.tests.methodvalidation.model.User.Basic;
import org.hibernate.beanvalidation.tck.tests.methodvalidation.model.User.Extended;
import org.hibernate.beanvalidation.tck.util.Groups;
import org.hibernate.beanvalidation.tck.util.TestUtil;
import org.hibernate.beanvalidation.tck.util.shrinkwrap.WebArchiveBuilder;

Expand All @@ -50,6 +51,7 @@
import static org.hibernate.beanvalidation.tck.util.TestUtil.assertCorrectPathNodeNames;
import static org.hibernate.beanvalidation.tck.util.TestUtil.kinds;
import static org.hibernate.beanvalidation.tck.util.TestUtil.names;

import static org.testng.Assert.assertEquals;

/**
Expand Down Expand Up @@ -408,4 +410,78 @@ public void testGetInvalidValueForCrossParameterConstraintOnParameterlessMethod(
assertCorrectNumberOfViolations( violations, 1 );
assertEquals( violations.iterator().next().getInvalidValue(), parameterValues );
}

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "5.1.2", id = "c")
public void testNullPassedForObjectCausesException() throws Exception {
Object object = null;
Method method = User.class.getMethod( "setFirstName", String.class );
Object[] parameterValues = new Object[] { null };

executableValidator.validateParameters(
object,
method,
parameterValues
);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "5.1.2", id = "c")
public void testNullPassedForMethodCausesException() throws Exception {
Object object = new User();
Method method = null;
Object[] parameterValues = new Object[] { null };

executableValidator.validateParameters(
object,
method,
parameterValues
);
}

//fails due to https://hibernate.onjira.com/browse/HV-681
@Test(expectedExceptions = IllegalArgumentException.class, groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "5.1.2", id = "c")
public void testNullPassedForParameterValuesCausesException() throws Exception {
Object object = new User();
Method method = User.class.getMethod( "setFirstName", String.class );
Object[] parameterValues = null;

executableValidator.validateParameters(
object,
method,
parameterValues
);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "5.1.2", id = "c")
public void testNullPassedForGroupsCausesException() throws Exception {
Object object = new User();
Method method = User.class.getMethod( "setFirstName", String.class );
Object[] parameterValues = new Object[] { null };

executableValidator.validateParameters(
object,
method,
parameterValues,
(Class<?>[]) null
);
}

//fails due to https://hibernate.onjira.com/browse/HV-681
@Test(expectedExceptions = IllegalArgumentException.class, groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "5.1.2", id = "c")
public void testNullPassedAsSingleGroupCausesException() throws Exception {
Object object = new User();
Method method = User.class.getMethod( "setFirstName", String.class );
Object[] parameterValues = new Object[] { null };

executableValidator.validateParameters(
object,
method,
parameterValues,
(Class<?>) null
);
}
}
Expand Up @@ -261,4 +261,64 @@ public void testUnexpectedType() throws Exception {

executableValidator.validateReturnValue( object, method, returnValue );
}

//fails due to https://hibernate.onjira.com/browse/HV-681
@Test(expectedExceptions = IllegalArgumentException.class, groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "5.1.2", id = "f")
public void testNullPassedForObjectCausesException() throws Exception {
Object object = null;
Method method = Customer.class.getMethod( "getAddress" );
Object returnValue = null;

executableValidator.validateReturnValue(
object,
method,
returnValue
);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "5.1.2", id = "f")
public void testNullPassedForMethodCausesException() throws Exception {
Object object = new Customer();
Method method = null;
Object returnValue = null;

executableValidator.validateReturnValue(
object,
method,
returnValue
);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = "5.1.2", id = "f")
public void testNullPassedForGroupsCausesException() throws Exception {
Object object = new Customer();
Method method = Customer.class.getMethod( "getAddress" );
Object returnValue = null;

executableValidator.validateReturnValue(
object,
method,
returnValue,
(Class<?>[]) null
);
}

//fails due to https://hibernate.onjira.com/browse/HV-681
@Test(expectedExceptions = IllegalArgumentException.class, groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "5.1.2", id = "f")
public void testNullPassedAsSingleGroupCausesException() throws Exception {
Object object = new Customer();
Method method = Customer.class.getMethod( "getAddress" );
Object returnValue = null;

executableValidator.validateReturnValue(
object,
method,
returnValue,
(Class<?>) null
);
}
}

0 comments on commit 98818a0

Please sign in to comment.