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

View File

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

View File

@ -18,42 +18,103 @@
*/ */
package org.libreccm.core; package org.libreccm.core;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.libreccm.testutils.EqualsVerifier;
import org.libreccm.tests.categories.UnitTest; import org.libreccm.tests.categories.UnitTest;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; 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> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
@Category(UnitTest.class) @org.junit.experimental.categories.Category(UnitTest.class)
public class EqualsAndHashCodeTest extends EqualsVerifier { public class EqualsAndHashCodeTest {
private final Class<?> entityClass;
@Parameterized.Parameters(name = "{0}") @Parameterized.Parameters(name = "{0}")
public static Collection<Class<?>> data() { public static Collection<Class<?>> data() {
return Arrays.asList(new Class<?>[]{ return Arrays.asList(new Class<?>[]{
CcmObject.class, CcmObject.class,
EmailAddress.class, EmailAddress.class,});
// GroupMembership.class,
// Subject.class,
// Permission.class,
// PersonName.class,
// Privilege.class,
ResourceType.class,
// Role.class,
// User.class,
// Group.class
});
} }
public EqualsAndHashCodeTest(final Class<?> entityClass) { 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

@ -90,6 +90,7 @@ public class EqualsAndHashCodeTest {
.forClass(entityClass) .forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE) .suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS) .suppress(Warning.NONFINAL_FIELDS)
.suppress(Warning.ALL_FIELDS_SHOULD_BE_USED)
.withRedefinedSuperclass() .withRedefinedSuperclass()
.withPrefabValues(Component.class, component1, component2) .withPrefabValues(Component.class, component1, component2)
.withPrefabValues(WidgetLabel.class, widgetLabel1, widgetLabel2) .withPrefabValues(WidgetLabel.class, widgetLabel1, widgetLabel2)

View File

@ -21,7 +21,6 @@ package org.libreccm.formbuilder.actions;
import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning; import nl.jqno.equalsverifier.Warning;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.libreccm.formbuilder.Component; import org.libreccm.formbuilder.Component;
@ -30,13 +29,18 @@ import org.libreccm.tests.categories.UnitTest;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; 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> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
@Category(UnitTest.class) @org.junit.experimental.categories.Category(UnitTest.class)
public class EqualsAndHashCodeTest { public class EqualsAndHashCodeTest {
private final Class<?> entityClass; private final Class<?> entityClass;
@ -71,14 +75,66 @@ public class EqualsAndHashCodeTest {
final FormSection formSection2 = new FormSection(); final FormSection formSection2 = new FormSection();
formSection2.setAdminName("FormSection Two"); 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 EqualsVerifier
.forClass(entityClass) .forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE) .suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS) .suppress(Warning.NONFINAL_FIELDS)
.suppress(Warning.ALL_FIELDS_SHOULD_BE_USED)
.withRedefinedSuperclass() .withRedefinedSuperclass()
.withPrefabValues(Component.class, component1, component2) .withPrefabValues(Component.class, component1, component2)
.withPrefabValues(FormSection.class, formSection1, formSection2) .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(); .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; import org.junit.runners.Parameterized;
/** /**
* A base class for verifying the implementations of the {@code equals()} * A base class for verifying the implementations of the {@code equals()} and
* and {@code hashCode} methods of an object using the {@link Parameterized} * {@code hashCode} methods of an object using the {@link Parameterized} test
* test runner from JUnit. * runner from JUnit.
* *
* To use this class create a new JUnit test class which extends this class * To use this class create a new JUnit test class which extends this class and
* and which uses the {@link Parameterized} test runner. The class must have a * which uses the {@link Parameterized} test runner. The class must have a
* static method which provides the classes to be tested. Example for testing * static method which provides the classes to be tested. Example for testing
* the classes {@code Foo} and {@code Bar} (imports have been omitted): * 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 * <a href="EqualsVerifier">http://www.jqno.nl/equalsverifier/</a> utility. If
* the classes to verify are part of complex inheritance hierarchy you may need * 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 * 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. * in the {@code org.libreccm.core} package.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -80,6 +81,7 @@ public class EqualsVerifier {
.forClass(entityClass) .forClass(entityClass)
.suppress(Warning.STRICT_INHERITANCE) .suppress(Warning.STRICT_INHERITANCE)
.suppress(Warning.NONFINAL_FIELDS) .suppress(Warning.NONFINAL_FIELDS)
.suppress(Warning.ALL_FIELDS_SHOULD_BE_USED)
.withRedefinedSuperclass() .withRedefinedSuperclass()
.verify(); .verify();
} }

View File

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