Skip to content
Permalink
Browse files
BVAL-162: convert remaining JUnit 3 tests to JUnit 4
  • Loading branch information
mbenson committed Oct 18, 2018
1 parent fcc4b5e commit 7bc48e01a0730075bbe2397e38b723efefb1e650
Showing 6 changed files with 74 additions and 44 deletions.
@@ -81,11 +81,11 @@ boolean insertSequence(Collection<Group> groups) {

/**
* Assert that the default group can be expanded to <code>defaultGroups</code>.
* Package-private method intended for unit tests.
*
* @param defaultGroups
*/
@Deprecated
public void assertDefaultGroupSequenceIsExpandable(List<Group> defaultGroups) {
void assertDefaultGroupSequenceIsExpandable(List<Group> defaultGroups) {
Consumer<List<Group>> action = (groupList) -> {
final int idx = groupList.indexOf(Group.DEFAULT);
if (idx >= 0) {
@@ -16,6 +16,11 @@
*/
package org.apache.bval.jsr.extensions;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.List;
@@ -31,10 +36,7 @@
import org.apache.bval.jsr.ValidatorImpl;
import org.apache.bval.jsr.extensions.ExampleMethodService.Person;
import org.junit.Ignore;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.Test;

/**
* MethodValidatorImpl Tester.
@@ -44,15 +46,9 @@
* @since <pre>11/11/2009</pre>
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public class MethodValidatorImplTest extends TestCase {
public MethodValidatorImplTest(String name) {
super(name);
}

public static Test suite() {
return new TestSuite(MethodValidatorImplTest.class);
}
public class MethodValidatorImplTest {

@Test
public void testUnwrap() {
Validator v = getValidator();
ValidatorImpl cv = v.unwrap(ValidatorImpl.class);
@@ -61,6 +57,7 @@ public void testUnwrap() {
assertNotNull(v.forExecutables());
}

@Test
public void testValidateMethodParameters() throws NoSuchMethodException {
ExampleMethodService service = new ExampleMethodService();
ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
@@ -75,6 +72,7 @@ public void testValidateMethodParameters() throws NoSuchMethodException {
assertEquals(2, mv.validateParameters(service, method, params).size());
}

@Test
public void testValidateMoreMethodParameters() throws NoSuchMethodException {

ExampleMethodService service = new ExampleMethodService();
@@ -101,6 +99,7 @@ public void testValidateMoreMethodParameters() throws NoSuchMethodException {
assertEquals(1, mv.validateParameters(service, echoMethod, echoParams).size());
}

@Test
public void testValidateConstructorParameters() throws NoSuchMethodException {
ExampleMethodService service = new ExampleMethodService();
ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
@@ -116,6 +115,7 @@ public void testValidateConstructorParameters() throws NoSuchMethodException {
assertEquals(2, mv.validateConstructorParameters(constructor, params).size());
}

@Test
public void testValidateReturnValue() throws NoSuchMethodException {
ExampleMethodService service = new ExampleMethodService();
ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
@@ -126,6 +126,7 @@ public void testValidateReturnValue() throws NoSuchMethodException {
assertEquals(1, mv.validateReturnValue(service, method, "").size());
}

@Test
public void testValidateMoreReturnValue() throws NoSuchMethodException {
ExampleMethodService service = new ExampleMethodService();
ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
@@ -141,6 +142,7 @@ public void testValidateMoreReturnValue() throws NoSuchMethodException {
assertTrue(mv.validateReturnValue(service, echoMethod, returnedValue).isEmpty());
}

@Test
public void testValidateValidParam() throws NoSuchMethodException {
ExampleMethodService service = new ExampleMethodService();
ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
@@ -160,6 +162,7 @@ public void testValidateValidParam() throws NoSuchMethodException {
mv.validateParameters(service, personOp1, new Object[] { null }).isEmpty());
}

@Test
public void testValidateNotNullValidParam() throws NoSuchMethodException {
ExampleMethodService service = new ExampleMethodService();
ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
@@ -189,6 +192,7 @@ public void testValidateNotNullValidParam() throws NoSuchMethodException {
* <li>interface.class + impl.method</li>
* </ul>
*/
@Test
@Ignore("violates Liskov principle, forbidden by the spec - 4.5.5")
public void validateImplementedMethod() throws NoSuchMethodException {
UserMethodsImpl um = new UserMethodsImpl();
@@ -201,6 +205,7 @@ public void validateImplementedMethod() throws NoSuchMethodException {
mv.validateParameters(um, classMethod, new Object[] { "", "valid", null }).size());
}

@Test
public void testBVal158() throws NoSuchMethodException {
TypeWithPseudoAccessor target = new TypeWithPseudoAccessor();
Method m = TypeWithPseudoAccessor.class.getMethod("getAll");
@@ -18,7 +18,19 @@
*/
package org.apache.bval.jsr.groups;

import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Locale;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

import org.apache.bval.jsr.DefaultMessageInterpolator;
import org.apache.bval.jsr.example.Address;
import org.apache.bval.jsr.example.Author;
@@ -29,19 +41,13 @@
import org.apache.bval.jsr.example.Library;
import org.apache.bval.jsr.example.Person;
import org.apache.bval.jsr.util.TestUtils;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;

/**
* Description: <br/>
*/
public class CollectionValidationTest extends TestCase {
public class CollectionValidationTest {
static ValidatorFactory factory;

static {
@@ -57,9 +63,8 @@ public class CollectionValidationTest extends TestCase {
/**
* {@inheritDoc}
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
validator = createValidator();
}

@@ -72,6 +77,7 @@ protected Validator createValidator() {
return factory.getValidator();
}

@Test
public void testValidateList() {
Author author = new Author();
author.setFirstName("Peter");
@@ -116,6 +122,7 @@ public void testValidateList() {
assertNotNull(TestUtils.getViolation(violations, "addresses[2].addressline1"));
}

@Test
public void testValidateMapAndRedefinedDefaultGroupOnNonRootBean() {
Library lib = new Library();
lib.setLibraryName("Leibnitz Bibliothek");
@@ -174,6 +181,7 @@ public void testValidateMapAndRedefinedDefaultGroupOnNonRootBean() {
assertNotNull(TestUtils.getViolation(violations, "taggedBooks[science].author.addresses[0].city"));
}

@Test
public void testValidateArray() {
Library lib = new Library();
lib.setLibraryName("Unibibliothek");
@@ -18,18 +18,22 @@
*/
package org.apache.bval.jsr.groups;

import junit.framework.TestCase;
import static org.junit.Assert.fail;

import javax.validation.GroupDefinitionException;
import javax.validation.groups.Default;
import java.util.ArrayList;
import java.util.List;

import javax.validation.GroupDefinitionException;
import javax.validation.groups.Default;

import org.junit.Test;

/**
* @author Hardy Ferentschik
* @author Roman Stumm
*/
public class DefaultGroupSequenceTest extends TestCase {
public class DefaultGroupSequenceTest {
@Test
public void testAssertDefaultGroupSequenceIsExpandableWithDefaultAtEndOfSequence() {
// create a dummy sequence
Group a = new Group(GroupA.class);
@@ -82,6 +86,7 @@ public void testAssertDefaultGroupSequenceIsExpandableWithDefaultAtEndOfSequence
chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
}

@Test
public void testAssertDefaulGroupSequenceIsExpandableWithDefaultAtBeginningOfSequence() {
// create a dummy sequence
Group a = new Group(GroupA.class);
@@ -18,25 +18,31 @@
*/
package org.apache.bval.jsr.groups.implicit;

import junit.framework.TestCase;
import org.apache.bval.jsr.ApacheValidatorFactory;
import org.apache.bval.jsr.util.TestUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Set;

import org.apache.bval.jsr.ApacheValidatorFactory;
import org.apache.bval.jsr.util.TestUtils;
import org.junit.Before;
import org.junit.Test;

/**
* Description: test spec chapter 3.4.4. Implicit grouping<br/>
*/
public class ImplicitGroupingTest extends TestCase {
public class ImplicitGroupingTest {
private Validator validator;

@Override
protected void setUp() {
@Before
public void setUp() {
validator = ApacheValidatorFactory.getDefault().getValidator();
}

@Test
public void testValidateImplicitGrouping() {
Order order = new Order();
// When an Order object is validated on the Default group, ...
@@ -18,22 +18,27 @@
*/
package org.apache.bval.jsr.groups.inheritance;

import junit.framework.TestCase;
import org.apache.bval.jsr.ApacheValidatorFactory;
import org.apache.bval.jsr.util.TestUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Set;

import org.apache.bval.jsr.ApacheValidatorFactory;
import org.apache.bval.jsr.util.TestUtils;
import org.junit.Before;
import org.junit.Test;

/**
* Description: <br/>
*/
public class GroupInheritanceTest extends TestCase {
public class GroupInheritanceTest {
private Validator validator;

@Override
protected void setUp() {
@Before
public void setUp() {
validator = ApacheValidatorFactory.getDefault().getValidator();
}

@@ -44,6 +49,7 @@ protected void setUp() {
* * @NotNull on defaultCreditCard</pre>
* because Default and Billable are superinterfaces of BuyInOneClick.
*/
@Test
public void testValidGroupBuyInOneClick() {
BillableUser user = new BillableUser();

0 comments on commit 7bc48e0

Please sign in to comment.