This the way how JUnit works. Each test is invoked on the new instance of test class, therefore field is every time initialized as empty ArrayList. And when it's static... well you know for sure
Here's plain JUnit example to prove it:
import static org.junit.Assert.*;
public class CurrencyCodeTest
private List<String> currencyCodes = new ArrayList<String>();
public void should_store_currency_code() throws Exception
public void should_have_new_list_created() throws Exception
On the other hand I don't really see any value in this list. You already know what should be in the database so why store it in the list?
Hope that helps!
Oh yes I forgot this basic JUnit feature. The reason why I am want to store users in list is that I have the generated IDs in my user entity and I never know what id will be generated for the entity. I wants to have the test simple when I was asking the question.
I was already triyng to implement the persistence extension tutorial but the @PersistentContext is not injected from some reason.
Why the EntityManager is not injected when I add following to my test class. (Persisten unit is injected in to the UserDao class with no problem)
private EntityManager entityManager;
This is my configuration of persistent unit:
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/TrainingDS" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.password" value="password" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
Thanky you for your advices.