Skip to content

Commit

Permalink
BVAL-162: convert remaining JUnit 3 tests to JUnit 4
Browse files Browse the repository at this point in the history
  • Loading branch information
mbenson committed Oct 18, 2018
1 parent fcc4b5e commit 7bc48e0
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 44 deletions.
4 changes: 2 additions & 2 deletions bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -57,9 +63,8 @@ public class CollectionValidationTest extends TestCase {
/**
* {@inheritDoc}
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
validator = createValidator();
}

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

@Test
public void testValidateList() {
Author author = new Author();
author.setFirstName("Peter");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -82,6 +86,7 @@ public void testAssertDefaultGroupSequenceIsExpandableWithDefaultAtEndOfSequence
chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
}

@Test
public void testAssertDefaulGroupSequenceIsExpandableWithDefaultAtBeginningOfSequence() {
// create a dummy sequence
Group a = new Group(GroupA.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();

Expand Down

0 comments on commit 7bc48e0

Please sign in to comment.