Hi,
I have an old project and I tried to make some tests (see below).
@Component(DataAccessLayerBean.NAME)
public class DataAccessLayerBean {
public static final String NAME = "myapp_DataAccessLayerBean";
@Inject
private Persistence persistence;
public Transaction createNewTransaction() {
return persistence.createTransaction();
}
private static void WithContext(final Consumer<Context> contextConsumer){
final Context context = new Context();
context.dataAccessLayerBean = AppBeans.get(DataAccessLayerBean.class);
try (Transaction tx = context.dataAccessLayerBean.createNewTransaction()) {
context.metadata = AppBeans.get(Metadata.class);
context.tran = context.metadata.create(com.company.myapp.entity.Transaction.class);
context.tran.setName("John");
context.dataAccessLayerBean.persist(context.tran);
tx.commit();
@Test
public void myOject(){
WithContext(ctx-> {
assertEquals(ctx.tran.getName(), "Jo");
});
}
Unfortunately the Test pass. The program never reach assertEquals. If I move assertEquals under tx.commit
, it works but I want to separate things because I have to perform more Tests. Any suggestion?