Lets say I have an entity named Foo
with an id
and a name
(simplified the class):
public class Foo {
private long id;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getId() {
return id;
}
}
In my application I don't want that the id
is set anywhere manually. Because foo
will only come from DB. So I don't created a setter for it.
Now I want JUnit test some method where I want instantiate foo
. Is there a possibility to set the id
just for the JUnit Test?
P.S.: A possible solution is to receive foo
from the DB first and make the test. But want to avoid the DB call. And I am using Spring
and jpa
if its necessary to know.