CCM NG: Tests and fixed bugs found by tests
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3442 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
11fae39504
commit
0cd20cfaee
|
|
@ -88,7 +88,7 @@ public class GroupMembership implements Serializable {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!(obj instanceof GroupMembership)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final GroupMembership other = (GroupMembership) obj;
|
final GroupMembership other = (GroupMembership) obj;
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,12 @@ public class Party extends CcmObject implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EmailAddress> getEmailAddresses() {
|
public List<EmailAddress> getEmailAddresses() {
|
||||||
|
if (emailAddresses == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
return Collections.unmodifiableList(emailAddresses);
|
return Collections.unmodifiableList(emailAddresses);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void setEmailAddresses(final List<EmailAddress> eMailAddresses) {
|
protected void setEmailAddresses(final List<EmailAddress> eMailAddresses) {
|
||||||
this.emailAddresses = eMailAddresses;
|
this.emailAddresses = eMailAddresses;
|
||||||
|
|
@ -80,7 +84,8 @@ public class Party extends CcmObject implements Serializable {
|
||||||
return Collections.unmodifiableList(grantedPermissions);
|
return Collections.unmodifiableList(grantedPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setGrantedPermissions(final List<Permission> grantedPermissions) {
|
protected void setGrantedPermissions(
|
||||||
|
final List<Permission> grantedPermissions) {
|
||||||
this.grantedPermissions = grantedPermissions;
|
this.grantedPermissions = grantedPermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,7 +100,7 @@ public class Party extends CcmObject implements Serializable {
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = super.hashCode();
|
int hash = super.hashCode();
|
||||||
hash = 41 * hash + Objects.hashCode(this.emailAddresses);
|
hash = 41 * hash + Objects.hashCode(emailAddresses);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +113,7 @@ public class Party extends CcmObject implements Serializable {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!(obj instanceof Party)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Party other = (Party) obj;
|
final Party other = (Party) obj;
|
||||||
|
|
@ -116,7 +121,7 @@ public class Party extends CcmObject implements Serializable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Objects.equals(this.emailAddresses, other.getEmailAddresses());
|
return Objects.equals(emailAddresses, other.getEmailAddresses());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -113,8 +113,12 @@ public class Permission implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreationDate() {
|
public Date getCreationDate() {
|
||||||
|
if (creationDate == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
return new Date(creationDate.getTime());
|
return new Date(creationDate.getTime());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setCreationDate(final Date creationDate) {
|
public void setCreationDate(final Date creationDate) {
|
||||||
this.creationDate = new Date(creationDate.getTime());
|
this.creationDate = new Date(creationDate.getTime());
|
||||||
|
|
@ -148,7 +152,7 @@ public class Permission implements Serializable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getClass() != obj.getClass()) {
|
if (!(obj instanceof Permission)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Permission other = (Permission) obj;
|
final Permission other = (Permission) obj;
|
||||||
|
|
@ -201,4 +205,5 @@ public class Permission implements Serializable {
|
||||||
creationDate,
|
creationDate,
|
||||||
creationIp);
|
creationIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ public class PersonName implements Serializable {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!(obj instanceof PersonName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PersonName other = (PersonName) obj;
|
final PersonName other = (PersonName) obj;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import javax.persistence.Table;
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "privileges")
|
@Table(name = "ccm_privileges")
|
||||||
public class Privilege implements Serializable {
|
public class Privilege implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -3986038536996049440L;
|
private static final long serialVersionUID = -3986038536996049440L;
|
||||||
|
|
@ -75,7 +75,7 @@ public class Privilege implements Serializable {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!(obj instanceof Privilege)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Privilege other = (Privilege) obj;
|
final Privilege other = (Privilege) obj;
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,6 @@ public class Resource extends CcmObject implements Serializable {
|
||||||
|
|
||||||
// @Column(name = "resource_type")
|
// @Column(name = "resource_type")
|
||||||
// private String resourceType;
|
// private String resourceType;
|
||||||
|
|
||||||
public LocalizedString getTitle() {
|
public LocalizedString getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
@ -120,8 +119,12 @@ public class Resource extends CcmObject implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
|
if (created == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
return new Date(created.getTime());
|
return new Date(created.getTime());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setCreated(final Date created) {
|
public void setCreated(final Date created) {
|
||||||
this.created = new Date(created.getTime());
|
this.created = new Date(created.getTime());
|
||||||
|
|
@ -158,7 +161,6 @@ public class Resource extends CcmObject implements Serializable {
|
||||||
// public void setResourceType(final String resourceType) {
|
// public void setResourceType(final String resourceType) {
|
||||||
// this.resourceType = resourceType;
|
// this.resourceType = resourceType;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 5;
|
int hash = 5;
|
||||||
|
|
@ -174,7 +176,7 @@ public class Resource extends CcmObject implements Serializable {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!(obj instanceof Resource)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Resource other = (Resource) obj;
|
final Resource other = (Resource) obj;
|
||||||
|
|
@ -205,7 +207,7 @@ public class Resource extends CcmObject implements Serializable {
|
||||||
return super.toString(
|
return super.toString(
|
||||||
String.format(", title = %s, "
|
String.format(", title = %s, "
|
||||||
+ "created = %tF %<tT%s",
|
+ "created = %tF %<tT%s",
|
||||||
title.toString(),
|
Objects.toString(title),
|
||||||
created,
|
created,
|
||||||
data));
|
data));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ public class Role implements Serializable {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!(obj instanceof Role)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Role other = (Role) obj;
|
final Role other = (Role) obj;
|
||||||
|
|
@ -126,7 +126,7 @@ public class Role implements Serializable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.roleId != other.roleId) {
|
if (this.roleId != other.getRoleId()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Objects.equals(this.name, other.getName())) {
|
if (!Objects.equals(this.name, other.getName())) {
|
||||||
|
|
@ -156,8 +156,8 @@ public class Role implements Serializable {
|
||||||
super.toString(),
|
super.toString(),
|
||||||
roleId,
|
roleId,
|
||||||
name,
|
name,
|
||||||
sourceGroup.toString(),
|
Objects.toString(sourceGroup),
|
||||||
implicitGroup.toString());
|
Objects.toString(implicitGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ public class User extends Party implements Serializable {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!(obj instanceof User)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final User other = (User) obj;
|
final User other = (User) obj;
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,12 @@ public class UserGroup extends Party implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Role> getRoles() {
|
public List<Role> getRoles() {
|
||||||
|
if (roles == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
return Collections.unmodifiableList(roles);
|
return Collections.unmodifiableList(roles);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void setRoles(final List<Role> roles) {
|
protected void setRoles(final List<Role> roles) {
|
||||||
this.roles = roles;
|
this.roles = roles;
|
||||||
|
|
@ -82,8 +86,12 @@ public class UserGroup extends Party implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GroupMembership> getMembers() {
|
public List<GroupMembership> getMembers() {
|
||||||
|
if (members == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
return Collections.unmodifiableList(members);
|
return Collections.unmodifiableList(members);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void setMembers(final List<GroupMembership> members) {
|
protected void setMembers(final List<GroupMembership> members) {
|
||||||
this.members = members;
|
this.members = members;
|
||||||
|
|
@ -99,7 +107,7 @@ public class UserGroup extends Party implements Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 5;
|
int hash = super.hashCode();
|
||||||
hash = 83 * hash + Objects.hashCode(this.name);
|
hash = 83 * hash + Objects.hashCode(this.name);
|
||||||
hash = 83 * hash + Objects.hashCode(this.roles);
|
hash = 83 * hash + Objects.hashCode(this.roles);
|
||||||
return hash;
|
return hash;
|
||||||
|
|
@ -114,7 +122,7 @@ public class UserGroup extends Party implements Serializable {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!(obj instanceof UserGroup)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final UserGroup other = (UserGroup) obj;
|
final UserGroup other = (UserGroup) obj;
|
||||||
|
|
@ -128,7 +136,8 @@ public class UserGroup extends Party implements Serializable {
|
||||||
return Objects.equals(this.roles, other.getRoles());
|
return Objects.equals(this.roles, other.getRoles());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canEquals(final Object obj) {
|
@Override
|
||||||
|
public boolean canEqual(final Object obj) {
|
||||||
return obj instanceof UserGroup;
|
return obj instanceof UserGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.categorization;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
import org.libreccm.jpautils.EqualsVerifier;
|
||||||
|
import org.libreccm.tests.categories.UnitTest;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
|
@org.junit.experimental.categories.Category(UnitTest.class)
|
||||||
|
public class EqualsAndHashCodeTest extends EqualsVerifier {
|
||||||
|
|
||||||
|
@Parameterized.Parameters(name = "{0}")
|
||||||
|
public static Collection<Class<?>> data() {
|
||||||
|
return Arrays.asList(new Class<?>[]{
|
||||||
|
Categorization.class,
|
||||||
|
org.libreccm.categorization.Category.class,
|
||||||
|
Domain.class,
|
||||||
|
DomainOwnership.class});
|
||||||
|
}
|
||||||
|
|
||||||
|
public EqualsAndHashCodeTest(final Class<?> entitiesClass) {
|
||||||
|
super(entitiesClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.categorization;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
import org.libreccm.jpautils.ToStringVerifier;
|
||||||
|
import org.libreccm.tests.categories.UnitTest;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
|
@org.junit.experimental.categories.Category(UnitTest.class)
|
||||||
|
public class ToStringTest extends ToStringVerifier {
|
||||||
|
|
||||||
|
@Parameterized.Parameters(name = "{0}")
|
||||||
|
public static Collection<Class<?>> data() {
|
||||||
|
return Arrays.asList(new Class<?>[]{
|
||||||
|
Categorization.class,
|
||||||
|
org.libreccm.categorization.Category.class,
|
||||||
|
Domain.class,
|
||||||
|
DomainOwnership.class});
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToStringTest(final Class<?> entitiesClass) {
|
||||||
|
super(entitiesClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package org.libreccm.core;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import org.junit.experimental.categories.Category;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.Parameterized;
|
|
||||||
import org.libreccm.categorization.Categorization;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainOwnership;
|
|
||||||
import org.libreccm.tests.categories.UnitTest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
@Category(UnitTest.class)
|
|
||||||
public class CategorizationEntitiesTest extends EntitiesTestCore {
|
|
||||||
|
|
||||||
@Parameterized.Parameters
|
|
||||||
public static Collection<Class<?>> data() {
|
|
||||||
return Arrays.asList(new Class<?>[]{
|
|
||||||
Categorization.class,
|
|
||||||
org.libreccm.categorization.Category.class,
|
|
||||||
Domain.class,
|
|
||||||
DomainOwnership.class});
|
|
||||||
}
|
|
||||||
|
|
||||||
public CategorizationEntitiesTest(final Class<?> entitiesClass) {
|
|
||||||
super(entitiesClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package org.libreccm.core;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import org.junit.experimental.categories.Category;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.Parameterized;
|
|
||||||
import org.libreccm.tests.categories.UnitTest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The tests in this class are used to verify the implementations of the
|
|
||||||
* {@code equals}, {@code hashCode} and {@code toString} methods of the entities
|
|
||||||
* in the {@code org.libreccm.core} package.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
@Category(UnitTest.class)
|
|
||||||
public class CcmCoreEntitiesTest extends EntitiesTestCore {
|
|
||||||
|
|
||||||
@Parameterized.Parameters(name = "{0}")
|
|
||||||
public static Collection<Class<?>> data() {
|
|
||||||
return Arrays.asList(new Class<?>[]{
|
|
||||||
CcmObject.class,
|
|
||||||
EmailAddress.class,
|
|
||||||
GroupMembership.class,
|
|
||||||
Party.class,
|
|
||||||
Permission.class,
|
|
||||||
PersonName.class,
|
|
||||||
Privilege.class,
|
|
||||||
Resource.class,
|
|
||||||
Role.class,
|
|
||||||
User.class,
|
|
||||||
UserGroup.class});
|
|
||||||
}
|
|
||||||
|
|
||||||
public CcmCoreEntitiesTest(final Class<?> entityClass) {
|
|
||||||
super(entityClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -10,15 +10,11 @@ import nl.jqno.equalsverifier.Warning;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.beans.BeanInfo;
|
|
||||||
import java.beans.IntrospectionException;
|
import java.beans.IntrospectionException;
|
||||||
import java.beans.Introspector;
|
|
||||||
import java.beans.PropertyDescriptor;
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,6 +34,7 @@ public class EntitiesTestCore {
|
||||||
EqualsVerifier
|
EqualsVerifier
|
||||||
.forClass(entityClass)
|
.forClass(entityClass)
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
.suppress(Warning.STRICT_INHERITANCE)
|
||||||
|
.suppress(Warning.NONFINAL_FIELDS)
|
||||||
.withRedefinedSuperclass()
|
.withRedefinedSuperclass()
|
||||||
.verify();
|
.verify();
|
||||||
}
|
}
|
||||||
|
|
@ -49,14 +46,7 @@ public class EntitiesTestCore {
|
||||||
IllegalArgumentException,
|
IllegalArgumentException,
|
||||||
InvocationTargetException {
|
InvocationTargetException {
|
||||||
final Object obj = entityClass.newInstance();
|
final Object obj = entityClass.newInstance();
|
||||||
// final BeanInfo beanInfo = Introspector.getBeanInfo(entityClass);
|
|
||||||
//
|
|
||||||
// final PropertyDescriptor[] properties = beanInfo
|
|
||||||
// .getPropertyDescriptors();
|
|
||||||
// for (PropertyDescriptor property : properties) {
|
|
||||||
// final Method setter = property.getWriteMethod();
|
|
||||||
|
|
||||||
// setter.invoke(obj, new Object[]{null});
|
|
||||||
final Field[] fields = entityClass.getDeclaredFields();
|
final Field[] fields = entityClass.getDeclaredFields();
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
if (!Modifier.isStatic(field.getModifiers())
|
if (!Modifier.isStatic(field.getModifiers())
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.core;
|
||||||
|
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
import org.libreccm.jpautils.EqualsVerifier;
|
||||||
|
import org.libreccm.tests.categories.UnitTest;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
|
@Category(UnitTest.class)
|
||||||
|
public class EqualsAndHashCodeTest extends EqualsVerifier {
|
||||||
|
|
||||||
|
@Parameterized.Parameters(name = "{0}")
|
||||||
|
public static Collection<Class<?>> data() {
|
||||||
|
return Arrays.asList(new Class<?>[]{
|
||||||
|
CcmObject.class,
|
||||||
|
EmailAddress.class,
|
||||||
|
GroupMembership.class,
|
||||||
|
Party.class,
|
||||||
|
Permission.class,
|
||||||
|
PersonName.class,
|
||||||
|
Privilege.class,
|
||||||
|
Role.class,
|
||||||
|
User.class,
|
||||||
|
UserGroup.class});
|
||||||
|
}
|
||||||
|
|
||||||
|
public EqualsAndHashCodeTest(final Class<?> entityClass) {
|
||||||
|
super(entityClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,156 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2015 LibreCCM Foundation.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.libreccm.core;
|
|
||||||
|
|
||||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
|
||||||
import nl.jqno.equalsverifier.Warning;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.experimental.categories.Category;
|
|
||||||
import org.libreccm.tests.categories.UnitTest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@Category(UnitTest.class)
|
|
||||||
public class EqualsTest {
|
|
||||||
|
|
||||||
public EqualsTest() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpClass() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownClass() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyCcmObject() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(CcmObject.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyEmailAddress() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(EmailAddress.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyGroupMembership() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(GroupMembership.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyParty() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(Party.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyPermission() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(Permission.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyPersonName() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(PersonName.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyPrivilege() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(Privilege.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyResource() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(Resource.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyRole() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(Role.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyUser() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(User.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void verifyUserGroup() {
|
|
||||||
EqualsVerifier
|
|
||||||
.forClass(UserGroup.class)
|
|
||||||
.suppress(Warning.STRICT_INHERITANCE)
|
|
||||||
.withRedefinedSuperclass()
|
|
||||||
.verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.core;
|
||||||
|
|
||||||
|
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||||
|
import nl.jqno.equalsverifier.Warning;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
import org.libreccm.l10n.LocalizedString;
|
||||||
|
import org.libreccm.tests.categories.UnitTest;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@Category(UnitTest.class)
|
||||||
|
public class ResourceEntityTest {
|
||||||
|
|
||||||
|
public ResourceEntityTest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpClass() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void tearDownClass() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyEqualsAndHashCode() {
|
||||||
|
final Resource resource1 = new Resource();
|
||||||
|
final LocalizedString title1 = new LocalizedString();
|
||||||
|
title1.addValue(Locale.ENGLISH, "Resource 1");
|
||||||
|
resource1.setTitle(title1);
|
||||||
|
|
||||||
|
final Resource resource2 = new Resource();
|
||||||
|
final LocalizedString title2 = new LocalizedString();
|
||||||
|
title2.addValue(Locale.ENGLISH, "Resource 2");
|
||||||
|
resource2.setTitle(title2);
|
||||||
|
|
||||||
|
EqualsVerifier
|
||||||
|
.forClass(Resource.class)
|
||||||
|
.suppress(Warning.STRICT_INHERITANCE)
|
||||||
|
.suppress(Warning.NONFINAL_FIELDS)
|
||||||
|
.withPrefabValues(Resource.class, resource1, resource2)
|
||||||
|
.withRedefinedSuperclass()
|
||||||
|
.verify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.core;
|
||||||
|
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
import org.libreccm.jpautils.ToStringVerifier;
|
||||||
|
import org.libreccm.tests.categories.UnitTest;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
|
@Category(UnitTest.class)
|
||||||
|
public class ToStringTest extends ToStringVerifier {
|
||||||
|
|
||||||
|
@Parameterized.Parameters(name = "{0}")
|
||||||
|
public static Collection<Class<?>> data() {
|
||||||
|
return Arrays.asList(new Class<?>[]{
|
||||||
|
CcmObject.class,
|
||||||
|
EmailAddress.class,
|
||||||
|
GroupMembership.class,
|
||||||
|
Party.class,
|
||||||
|
Permission.class,
|
||||||
|
PersonName.class,
|
||||||
|
Privilege.class,
|
||||||
|
Resource.class,
|
||||||
|
Role.class,
|
||||||
|
User.class,
|
||||||
|
UserGroup.class});
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToStringTest(final Class<?> entityClass) {
|
||||||
|
super(entityClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.jpautils;
|
||||||
|
|
||||||
|
import nl.jqno.equalsverifier.Warning;
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* 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):
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* @RunWith(Parameterized.class)
|
||||||
|
* @Category(UnitTest.class)
|
||||||
|
* public class FooBarTest extends EqualsVerifier {
|
||||||
|
*
|
||||||
|
* @Parameterized.Parameters(name = "{0}")
|
||||||
|
* public static Collection<Class<?>> data() {
|
||||||
|
* return Arrays.asList(new Class<?>[] {
|
||||||
|
* Foo.class,
|
||||||
|
* Bar.class
|
||||||
|
* });
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public FooBarTest(final Class<?> entityClass) {
|
||||||
|
* super(entityClass);
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class EqualsVerifier {
|
||||||
|
|
||||||
|
private final Class<?> entityClass;
|
||||||
|
|
||||||
|
public EqualsVerifier(final Class<?> entityClass) {
|
||||||
|
this.entityClass = entityClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyEqualsAndHashCode() {
|
||||||
|
nl.jqno.equalsverifier.EqualsVerifier
|
||||||
|
.forClass(entityClass)
|
||||||
|
.suppress(Warning.STRICT_INHERITANCE)
|
||||||
|
.suppress(Warning.NONFINAL_FIELDS)
|
||||||
|
.withRedefinedSuperclass()
|
||||||
|
.verify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.jpautils;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
|
||||||
|
import java.beans.IntrospectionException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A base class for verifying the implementation of the {@code toString()}
|
||||||
|
* method 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
|
||||||
|
* static method which provides the classes to be tested. Example for testing
|
||||||
|
* the classes {@code Foo} and {@code Bar} (imports have been omitted):
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* @RunWith(Parameterized.class)
|
||||||
|
* @Category(UnitTest.class)
|
||||||
|
* public class FooBarTest extends ToStringVerifier {
|
||||||
|
*
|
||||||
|
* @Parameterized.Parameters(name = "{0}")
|
||||||
|
* public static Collection<Class<?>> data() {
|
||||||
|
* return Arrays.asList(new Class<?>[] {
|
||||||
|
* Foo.class,
|
||||||
|
* Bar.class
|
||||||
|
* });
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public FooBarTest(final Class<?> entityClass) {
|
||||||
|
* super(entityClass);
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class ToStringVerifier {
|
||||||
|
|
||||||
|
private final Class<?> entityClass;
|
||||||
|
|
||||||
|
public ToStringVerifier(final Class<?> entityClass) {
|
||||||
|
this.entityClass = entityClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyToString() throws IntrospectionException,
|
||||||
|
InstantiationException,
|
||||||
|
IllegalAccessException,
|
||||||
|
IllegalArgumentException,
|
||||||
|
InvocationTargetException {
|
||||||
|
final Object obj = entityClass.newInstance();
|
||||||
|
|
||||||
|
final Field[] fields = entityClass.getDeclaredFields();
|
||||||
|
for (Field field : fields) {
|
||||||
|
if (!Modifier.isStatic(field.getModifiers())
|
||||||
|
&& !field.getType().isPrimitive()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(obj, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
obj.toString();
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
final StringWriter strWriter = new StringWriter();
|
||||||
|
final PrintWriter writer = new PrintWriter(strWriter);
|
||||||
|
ex.printStackTrace(writer);
|
||||||
|
Assert.fail(String.format(
|
||||||
|
"toString() implemention of class \"%s\" "
|
||||||
|
+ "is not null safe:\n %s",
|
||||||
|
entityClass.getName(),
|
||||||
|
strWriter.toString()));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue