CCM NG: Updated EqualsVerifier to current version. Some tests need to be migrated.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4067 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-05-12 13:46:06 +00:00
parent 89c003b321
commit 1d5364bf7f
7 changed files with 215 additions and 78 deletions

View File

@ -43,6 +43,10 @@ public final class ConfigurationInfo {
*/
private String descBundle;
/**
* Key for the localised title of the configuration class in the resource
* bundle.
*/
private String titleKey;
/**
@ -121,6 +125,7 @@ public final class ConfigurationInfo {
int hash = 3;
hash = 59 * hash + Objects.hashCode(name);
hash = 59 * hash + Objects.hashCode(descBundle);
hash = 59 * hash + Objects.hashCode(titleKey);
hash = 59 * hash + Objects.hashCode(descKey);
return hash;
}
@ -143,19 +148,26 @@ public final class ConfigurationInfo {
if (!Objects.equals(descBundle, other.getDescBundle())) {
return false;
}
if (!Objects.equals(titleKey, other.getTitleKey())) {
return false;
}
return Objects.equals(descKey, other.getDescKey());
}
@Override
public String toString() {
return String.format("%s{ "
+ "name = \"%s\", "
+ "descBundle = \"%s\", "
+ "descKey = \"%s\""
+ " }",
+ "name = \"%s\", "
+ "descBundle = \"%s\", "
+ "titleKey = \"%s\", "
+ "descKey = \"%s\""
+ " }",
super.toString(),
name,
descBundle,
titleKey,
descKey);
}

View File

@ -25,7 +25,6 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.libreccm.core.CcmObject;
import org.libreccm.security.Group;
import org.libreccm.security.Permission;
import org.libreccm.security.Role;
import org.libreccm.security.User;
import org.libreccm.tests.categories.UnitTest;
@ -108,6 +107,7 @@ public class EqualsAndHashCodeTest {
.forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS)
.suppress(Warning.ALL_FIELDS_SHOULD_BE_USED)
.withRedefinedSuperclass()
.withPrefabValues(Category.class, category1, category2)
.withPrefabValues(Domain.class, domain1, domain2)
@ -119,6 +119,10 @@ public class EqualsAndHashCodeTest {
.verify();
}
/**
* {@link User} has a protected constructor, so have have do this to create
* users for the test...
*/
private class TestUser extends User {
private static final long serialVersionUID = -9052762220990453621L;

View File

@ -18,42 +18,103 @@
*/
package org.libreccm.core;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.libreccm.testutils.EqualsVerifier;
import org.libreccm.tests.categories.UnitTest;
import java.util.Arrays;
import java.util.Collection;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.junit.Test;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.Domain;
import org.libreccm.security.Group;
import org.libreccm.security.Role;
import org.libreccm.security.User;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RunWith(Parameterized.class)
@Category(UnitTest.class)
public class EqualsAndHashCodeTest extends EqualsVerifier {
@org.junit.experimental.categories.Category(UnitTest.class)
public class EqualsAndHashCodeTest {
private final Class<?> entityClass;
@Parameterized.Parameters(name = "{0}")
public static Collection<Class<?>> data() {
return Arrays.asList(new Class<?>[]{
CcmObject.class,
EmailAddress.class,
// GroupMembership.class,
// Subject.class,
// Permission.class,
// PersonName.class,
// Privilege.class,
ResourceType.class,
// Role.class,
// User.class,
// Group.class
});
EmailAddress.class,});
}
public EqualsAndHashCodeTest(final Class<?> entityClass) {
super(entityClass);
this.entityClass = entityClass;
}
@Test
public void verifyEqualsAndHashCode() {
final CcmObject ccmObject1 = new CcmObject();
ccmObject1.setObjectId(-100);
ccmObject1.setDisplayName("Object 1");
final CcmObject ccmObject2 = new CcmObject();
ccmObject1.setObjectId(-200);
ccmObject1.setDisplayName("Object 2");
final Role role1 = new Role();
role1.setName("role1");
final Role role2 = new Role();
role2.setName("role2");
final Group group1 = new Group();
group1.setName("group1");
final Group group2 = new Group();
group2.setName("group2");
final User user1 = new TestUser();
user1.setName("user1");
final User user2 = new TestUser();
user2.setName("user2");
final Category category1 = new Category();
category1.setName("Category One");
final Category category2 = new Category();
category2.setName("Category Two");
EqualsVerifier
.forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS)
.suppress(Warning.ALL_FIELDS_SHOULD_BE_USED)
.withRedefinedSuperclass()
.withPrefabValues(CcmObject.class, ccmObject1, ccmObject2)
.withPrefabValues(Role.class, role1, role2)
.withPrefabValues(Group.class, group1, group2)
.withPrefabValues(User.class, user1, user2)
.withPrefabValues(Category.class, category1, category2)
.verify();
}
/**
* {@link User} has a protected constructor, so have have do this to create
* users for the test...
*/
private class TestUser extends User {
private static final long serialVersionUID = -9052762220990453621L;
protected TestUser() {
super();
}
}
}

View File

@ -87,15 +87,16 @@ public class EqualsAndHashCodeTest {
formSection2.setAdminName("FormSection Two");
EqualsVerifier
.forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS)
.withRedefinedSuperclass()
.withPrefabValues(Component.class, component1, component2)
.withPrefabValues(WidgetLabel.class, widgetLabel1, widgetLabel2)
.withPrefabValues(Widget.class, widget1, widget2)
.withPrefabValues(FormSection.class, formSection1, formSection2)
.verify();
.forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS)
.suppress(Warning.ALL_FIELDS_SHOULD_BE_USED)
.withRedefinedSuperclass()
.withPrefabValues(Component.class, component1, component2)
.withPrefabValues(WidgetLabel.class, widgetLabel1, widgetLabel2)
.withPrefabValues(Widget.class, widget1, widget2)
.withPrefabValues(FormSection.class, formSection1, formSection2)
.verify();
}
}

View File

@ -21,7 +21,6 @@ package org.libreccm.formbuilder.actions;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.libreccm.formbuilder.Component;
@ -30,13 +29,18 @@ import org.libreccm.tests.categories.UnitTest;
import java.util.Arrays;
import java.util.Collection;
import org.libreccm.categorization.Category;
import org.libreccm.core.CcmObject;
import org.libreccm.security.Group;
import org.libreccm.security.Role;
import org.libreccm.security.User;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RunWith(Parameterized.class)
@Category(UnitTest.class)
@org.junit.experimental.categories.Category(UnitTest.class)
public class EqualsAndHashCodeTest {
private final Class<?> entityClass;
@ -71,14 +75,66 @@ public class EqualsAndHashCodeTest {
final FormSection formSection2 = new FormSection();
formSection2.setAdminName("FormSection Two");
final CcmObject ccmObject1 = new CcmObject();
ccmObject1.setObjectId(-100);
ccmObject1.setDisplayName("Object 1");
final CcmObject ccmObject2 = new CcmObject();
ccmObject1.setObjectId(-200);
ccmObject1.setDisplayName("Object 2");
final Role role1 = new Role();
role1.setName("role1");
final Role role2 = new Role();
role2.setName("role2");
final Group group1 = new Group();
group1.setName("group1");
final Group group2 = new Group();
group2.setName("group2");
final User user1 = new TestUser();
user1.setName("user1");
final User user2 = new TestUser();
user2.setName("user2");
final Category category1 = new Category();
category1.setName("Category One");
final Category category2 = new Category();
category2.setName("Category Two");
EqualsVerifier
.forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS)
.withRedefinedSuperclass()
.withPrefabValues(Component.class, component1, component2)
.withPrefabValues(FormSection.class, formSection1, formSection2)
.verify();
.forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS)
.suppress(Warning.ALL_FIELDS_SHOULD_BE_USED)
.withRedefinedSuperclass()
.withPrefabValues(Component.class, component1, component2)
.withPrefabValues(FormSection.class, formSection1, formSection2)
.withPrefabValues(CcmObject.class, ccmObject1, ccmObject2)
.withPrefabValues(Role.class, role1, role2)
.withPrefabValues(Group.class, group1, group2)
.withPrefabValues(User.class, user1, user2)
.withPrefabValues(Category.class, category1, category2)
.verify();
}
/**
* {@link User} has a protected constructor, so have have do this to create
* users for the test...
*/
private class TestUser extends User {
private static final long serialVersionUID = -9052762220990453621L;
protected TestUser() {
super();
}
}
}

View File

@ -23,12 +23,12 @@ import org.junit.Test;
import org.junit.runners.Parameterized;
/**
* A base class for verifying the implementations of the {@code equals()}
* and {@code hashCode} methods of an object using the {@link Parameterized}
* test runner from JUnit.
* A base class for verifying the implementations of the {@code equals()} and
* {@code hashCode} methods of an object using the {@link Parameterized} test
* runner from JUnit.
*
* To use this class create a new JUnit test class which extends this class
* and which uses the {@link Parameterized} test runner. The class must have a
* To use this class create a new JUnit test class which extends this class and
* which uses the {@link Parameterized} test runner. The class must have a
* static method which provides the classes to be tested. Example for testing
* the classes {@code Foo} and {@code Bar} (imports have been omitted):
*
@ -61,7 +61,8 @@ import org.junit.runners.Parameterized;
* <a href="EqualsVerifier">http://www.jqno.nl/equalsverifier/</a> utility. If
* the classes to verify are part of complex inheritance hierarchy you may need
* to create your own test using the {@code EqualsVerifier}. An example in
* ccm-core is the <a href="../../../../../ccm-core/xref-test/org/libreccm/core/ResourceEntityTest.html"><code>ResourceEntityTest</code></a>
* ccm-core is the
* <a href="../../../../../ccm-core/xref-test/org/libreccm/core/ResourceEntityTest.html"><code>ResourceEntityTest</code></a>
* in the {@code org.libreccm.core} package.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -77,10 +78,11 @@ public class EqualsVerifier {
@Test
public void verifyEqualsAndHashCode() {
nl.jqno.equalsverifier.EqualsVerifier
.forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS)
.withRedefinedSuperclass()
.verify();
.forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS)
.suppress(Warning.ALL_FIELDS_SHOULD_BE_USED)
.withRedefinedSuperclass()
.verify();
}
}

View File

@ -542,7 +542,8 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>1.7.8</version>
<!--<version>1.7.8</version>-->
<version>2.0.2</version>
</dependency>
<!-- h2 database in used to check some database related things -->