2 ms·
Sometimes the value you pass to a setter can go through additional logic to determine the final value to be set e.g.: private int value1; private int
by noisy_boy 3y ago
Sometimes the value you pass to a setter can go through additional logic to determine the final value to be set e.g.:
private int value1;
private int value2;
public void setValue2(int value2) {
this.value2 = value2;
}
public void setValue1(int value1) {
if (this.value2 > 0) {
this.value1 = value1 + this.value2;
} else {
this.value1 = value1;
}
}
Obviously this is a contrived example but if you have logic other than a simple "this.value = value", then you might want to unit test that bit.
- tom_ 3y agoAlso useful if you want to add logging, or capture some metrics, or set a breakpoint.
- growse 3y agoAh, the sound of people not using their type system properly. Parse, don't validate.
- reactordev 3y agoBut also don’t create AggregateNonNegativeInteger type when generics will do.