GithubHelp home page GithubHelp logo

sta-szek / pojo-tester Goto Github PK

View Code? Open in Web Editor NEW
52.0 15.0 26.0 11.94 MB

Java testing framework for testing pojo methods. It tests equals, hashCode, toString, getters, setters, constructors and whatever you report in issues ;)

Home Page: http://www.pojo.pl

License: GNU Lesser General Public License v3.0

Java 100.00%
pojo-testing pojo-tester java-framework testing test-automation test-coverage tests equality equals hashcode

pojo-tester's Introduction

POJO-TESTER - Java framework for pojo-testing

PROJECT IS ON HOLD

I have no time to invest more in this project. See #247

Thank you for using pojo-tester! It has 131 019 (05.06.2020) downloads total! I was not expecting such popularity 🚀


POJO-TESTER is a java testing library, which makes your pojo-tests much easier. You can test your pojo against equals, hashCode, toString, getters, setters and constructors.

Get more information at pojo-tester documentation site

If you have any questions, we can chat on Rocket.Chat

Build status is provided by

Current coverage is codecov

Project quality Codacy Badge

Download latest version Download

Get automatic notifications about new POJO-TESTER versions

pojo-tester's People

Contributors

36893488147419103231 avatar frecco75 avatar gitbook-bot avatar semionpar avatar sta-szek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pojo-tester's Issues

Find out the most user friendly pojo tester api for testing

What is the most user friendly / given-when-then convention compatible way to invoke pojo tests?

// given
PojoTester tester = new PojoTester();
PojoTester tester = new PojoTester(fieldValueChanger);
PojoTester tester = new PojoTester().using(fieldValueChanger);

Class coffee = Coffee.class;
Class cake = Cake.class;

Class[] classes = new Class[]{coffee, cake};

// when

// then
tester.test(coffee);
tester.testAll(coffee, cake,);
tester.testAll(classes);

OR


// given
Class coffee = Coffee.class;
Class cake = Cake.class;

Class[] classes = new Class[]{coffee, cake};

// when

// then
assertThat(class).using(fieldValueChanger).hasWellImplemented...();
assertThat(class1, class2).using(fieldValueChanger).haveWellImplemented...();

EXPLANATION

Currently test and testAll methods throw exception when pojo has invalid equals, hashcode or toString method implementation.

NESTED CLASSES

You can also define nested classes to change in your main class e.g.

A {
  B b;
  C c.
}
Class baseClass = A.class;
Class[] nestedClasses = new Class[]{B.class, C.class};

test(baseClass, nestedClasses )

KIND OF TESTS

There is no option to choose which tests should be run (equals, hashcode or toString).
How do you want to provide it? E.g.

new PojoTester(EQUALS | HASHCODE | TO_STRING)
or
new PojoTester().addTesters(new EqualsTester(), ...)
or
assertThat(class).using(new HashCodeTester()).hasWellImplemented...();

CHANGING FIELDS

At this moment you can provide you own fieldsValuesChanger that should change field of specific type e.g. Coffee.
In order to do this you have to extend AbstractFieldsValuesChanger class and implement some methods.

If you do not specify your own fields values changer and pojo tester could not change field value then it sets it either to null or class.instantiate()

Implement enums changing

Fields that are enums should be changes as follow:
Take next value, if there is only one, then set null

Refactor building messages

Messages are created by StringBuilder which makes hard to change formatting etc... Extract abstraction e.g. message container, which will display them in better way.

Generate different objects

EqualsTester class should test objects that have different fields values. It should test n! +2 objects where n is quantity of fields. +2 is additional cases with all fields changed and default values.
E.g.

class A {
   private int a;
   private int b;
}

Should be generated objects:
A(0, 0)
A(0,1)
A(1,0)
A(1,1)

0 - defaultowa value
1 - changed value

Testing toString()

Implement testing toString() method with possibility to choose fields like in EqualsTester

Consider creating api and internal package

Creating org.pojo.tester.api., org.pojo.tester.internal. package to indicate for end-users which classes they should use and which are internal ones.

Rename package org.pojo.* to pl.pojo.* - I own domain pojo.pl, so it will be easy to guess homepage for all pojo projects

Find out better way to get generic class

Currently casting to ParametrizedTypeImpl is kind of dangerous. That class is internal class of Java, which should not be used.
Warnings are reported whlie compiling code:
D:\workspaces\intellij\pojo-tester\src\main\java\org\pojo\tester\field\collections\map\AbstractMapFieldValueChanger.java:5: warning: ParameterizedTypeImpl is internal proprietary API and may be removed in a future release import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;

Refactoring ObjectGenerator

Method createInstanceWithDifferentFieldValues in ObjectGenerator class should take objects as parameter instead of class, that it can properly generate different object from taken one.
Currently creates two object and returns the second one, but what if someones has already that object?

Allow user to choose constructor and pass parameters

When creating objects via construcotrs, exception occurs if parameters don't pass validation.
User could have possibility to provide constructor and parameters (or just parameters and construcotr will chosen by java, based on parameters type).

Proposed API:

assert...(...).create(X.class, constructor, parameters)
or
make ClassAndFieldPredicate to contain construcor and parameters
assert...(ClassAndFieldPredicate)....

Create parameters validation

Create parameters validation in constructors, setters and other methods.

It could look like
Preconditions.notNull(...) throws NullPointerException

Apply to all neccessary classes

Implement changing fields recursively

Currently while creating new objects, only fields that are primitive are being changed.
Add changing fields recursively that are not primitive types e.g. Object or CustomClass

Getting more done in GitHub with ZenHub

Hola! @sta-szek has created a ZenHub account for the sta-szek organization. ZenHub is the only project management tool integrated natively in GitHub – created specifically for fast-moving, software-driven teams.


How do I use ZenHub?

To get set up with ZenHub, all you have to do is download the browser extension and log in with your GitHub account. Once you do, you’ll get access to ZenHub’s complete feature-set immediately.

What can ZenHub do?

ZenHub adds a series of enhancements directly inside the GitHub UI:

  • Real-time, customizable task boards for GitHub issues;
  • Multi-Repository burndown charts, estimates, and velocity tracking based on GitHub Milestones;
  • Personal to-do lists and task prioritization;
  • Time-saving shortcuts – like a quick repo switcher, a “Move issue” button, and much more.

Add ZenHub to GitHub

Still curious? See more ZenHub features or read user reviews. This issue was written by your friendly ZenHub bot, posted by request from @sta-szek.

ZenHub Board

Remove codacy coverage from CI

Codacy coverage requires sudo at travisCI.
This makes build slower than non-sudo builds.
Overmore codacy refused me to extend the license for private repos, so the system is useless

Tesst test same objects, which cause assertion exception

Tests test same objects, which makes e.g. NotEqualEqualsAssertionError and the message is:

pl.pojo.tester.internal.assertion.equals.NotEqualEqualsAssertionError: 


Class org.pojo.playground.GoodPojo has bad 'equals' method implementation.
The equals method should return false if objects should not be equal.
Current implementation returns true.
Object:
GoodPojo{byteField=0, shortType=0, intType=0, longType=0, doubleType=0.0, booleanType=false, floatType=0.0, charType= }
should not be equal to:
GoodPojo{byteField=0, shortType=0, intType=0, longType=0, doubleType=0.0, booleanType=false, floatType=0.0, charType= }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.