Answering the previous comment at @me here because of my reputation:
Vlookward, not writing getters/setters makes no sense at all. The only options for setting private fields is to have explicit setters, to set them in your constructor, or to set the indirectly via other methods (functionally deferring the setter to another place). Why not use setters?
Well, sometimes, there is no need to the field be private (Sorry if my English is not very good). Often, we write our software as it was a library and we encapsulate our fields (our business logic fields) with unnecessary getters/setters.
Other times, that methods are actually necessary. Then, there are two possibilities:
1. There is business logic inside them. Then they sould be tested, but they aren't real getters/setters. I always write that logic in other classes. And the tests test that other classes, not the POJO.
2. There is not. Then, do not write them by hand, if you can. For example, an implementation for the next interface may be fully autogenerated (and also in runtime!) :
interface NamedAndObservable {
String getName();
void setName(String name);
void addPropertyChangeListener(PropertyChangeListener listener);
void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener);
}
So test only what is written by hand. No matter if it is a getter/setter.
nl.jqno.equalsverifier.EqualsVerifier
and javacodegeeks.com/2014/09/tips-for-unit-testing-javabeans.html – Simmon