meanbean

Mean Bean is an open source Java test library that tests equals and hashCode contract compliance, as well as JavaBean/POJO getter and setter methods.

License

License

GroupId

GroupId

com.github.meanbeanlib
ArtifactId

ArtifactId

meanbean
Last Version

Last Version

3.0.0-M9
Release Date

Release Date

Type

Type

jar
Description

Description

meanbean
Mean Bean is an open source Java test library that tests equals and hashCode contract compliance, as well as JavaBean/POJO getter and setter methods.
Project URL

Project URL

http://github.com/meanbeanlib/meanbean/
Project Organization

Project Organization

meanbean
Source Code Management

Source Code Management

http://github.com/meanbeanlib/meanbean/tree/master

Download meanbean

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.meanbeanlib/meanbean/ -->
<dependency>
    <groupId>com.github.meanbeanlib</groupId>
    <artifactId>meanbean</artifactId>
    <version>3.0.0-M9</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.meanbeanlib/meanbean/
implementation 'com.github.meanbeanlib:meanbean:3.0.0-M9'
// https://jarcasting.com/artifacts/com.github.meanbeanlib/meanbean/
implementation ("com.github.meanbeanlib:meanbean:3.0.0-M9")
'com.github.meanbeanlib:meanbean:jar:3.0.0-M9'
<dependency org="com.github.meanbeanlib" name="meanbean" rev="3.0.0-M9">
  <artifact name="meanbean" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.meanbeanlib', module='meanbean', version='3.0.0-M9')
)
libraryDependencies += "com.github.meanbeanlib" % "meanbean" % "3.0.0-M9"
[com.github.meanbeanlib/meanbean "3.0.0-M9"]

Dependencies

compile (1)

Group / Artifact Type Version
com.github.meanbeanlib : meanmirror jar 1.0.0

provided (3)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.25
org.apache.logging.log4j : log4j-slf4j-impl jar 2.13.3
org.kohsuke.metainf-services : metainf-services jar 1.8

test (5)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-all jar 1.3
org.mockito : mockito-all jar 1.8.5
org.assertj : assertj-core jar 3.16.1
org.apache.commons : commons-lang3 jar 3.10

Project Modules

There are no modules declared in this project.

MeanBean

Automated JavaBean Testing

Maven Central Javadoc Gitter chat

Welcome

What is it?

Mean Bean is an open source Java test library that helps you rapidly and reliably test fundamental objects within your
software system, namely your domain and data objects. Mean Bean:

  • Tests that the getter and setter method pairs of a JavaBean/POJO function correctly.
  • Verifies that the equals and hashCode methods of a class comply with the Equals Contract and HashCode Contract respectively.
  • Verifies property significance in object equality.

Why should I use it?

Mean Bean helps you rapidly and reliably test fundamental objects within your project, namely your domain and data objects. With just a single line of code, you can be confident that your beans are well behaved…

// verify bean getters/setters, equals, hashCode and toString for a single bean type
BeanVerifier.verifyBean(Company.class);

// verify multiple beans
BeanVerifier.verifyBeans(Company.class, Employee.class);

// verify beans in the same package
BeanVerifier.verifyBeansIn(Company.class.getPackage())

// configure settings
BeanVerifier.forClass(Company.class)
	// override default setting which tests the bean with random values 100 times
	.withSettings(settings -> settings.setDefaultIterations(12))
	// exclude name property in bean getter/setter test
	.withSettings(settings -> settings.addIgnoredProperty(Company::getName))
	.verifyGettersAndSetters()

Where do I get it?

Mean Bean can be acquired from the Maven Central:

<dependency>
    <groupId>com.github.meanbeanlib</groupId>
    <artifactId>meanbean</artifactId>
    <version>3.0.0-M9</version>
</dependency>

More info?

See User Guide in wiki

The following shows more usage examples:

// alternative way to configure settings
BeanVerifier.forClass(Company.class)
		.editSettings()
		.setDefaultIterations(12)
		.addIgnoredProperty(Company::getId)
		.edited()
		.verifyGettersAndSetters()
		.verifyEqualsAndHashCode();

// ignore Company's Id property from equals and hashCode test
BeanVerifier.forClass(Company.class)
		.withSettings(settings -> settings.addEqualsInsignificantProperty(Company::getId))
		.verifyEqualsAndHashCode();

// ignore Company's Address property from getter/setter test
BeanVerifier.forClass(Company.class)
		.withSettings(settings -> settings.addIgnoredProperty(Company::getAddress))
		.verifyEqualsAndHashCode();

// ignore Company's Id property from equals and hashCode test
BeanVerifier.forClass(Company.class)
		.withSettings(settings -> settings.addEqualsInsignificantProperty(Company::getId))
		.verifyEqualsAndHashCode();
		
// how to register factory for a non-bean type (e.g. one without zero-arg constructor) 
BeanVerifier.forClass(Company.class)
		.withSettings(settings -> settings.registerFactory(NonBean.class, nonBeanFactory))
		.verifyGettersAndSetters();

// how to re-use the same settings across your team
BeanVerifier.forClass(Company.class)
		.withSettings(myTeamsSharedSettings()) // use the team's shared settings
		.verify();

Users familiar with meanbean v2 may continue using that api:

// meanbean v2 api to verify bean getters/setters
new BeanTester().testBean(User.class);

License

MeanBean is released under the Apache 2.0 license.

Copyright 2010-2020.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
3.0.0-M9
3.0.0-M8
3.0.0-M7
3.0.0-M6
3.0.0-M5
3.0.0-M4
3.0.0-M3
3.0.0-M2
3.0.0-M1