]> git.somenet.org - pub/jan/dst18.git/blob - ass1-jpa/src/test/java/dst/ass1/jpa/tests/Ass1_TestBase.java
Add template for assignment 1
[pub/jan/dst18.git] / ass1-jpa / src / test / java / dst / ass1 / jpa / tests / Ass1_TestBase.java
1 package dst.ass1.jpa.tests;
2
3 import java.util.Collection;
4 import java.util.List;
5 import java.util.function.Function;
6 import java.util.stream.Collectors;
7
8 import javax.persistence.EntityManager;
9
10 import org.junit.Before;
11 import org.junit.Rule;
12 import org.junit.rules.ErrorCollector;
13 import org.junit.rules.ExpectedException;
14
15 import dst.ass1.jpa.DatabaseGateway;
16 import dst.ass1.jpa.ORMService;
17 import dst.ass1.jpa.dao.IDAOFactory;
18 import dst.ass1.jpa.model.IModelFactory;
19
20 public class Ass1_TestBase {
21
22     protected final TestData testData = new TestData();
23
24     @Rule
25     public ORMService orm = new ORMService(testData);
26
27     @Rule
28     public ExpectedException expectedException = ExpectedException.none();
29
30     @Rule
31     public ErrorCollector err = new ErrorCollector();
32
33     // commonly used classes unwrapped from ORMService
34     protected EntityManager em;
35     protected IModelFactory modelFactory;
36     protected IDAOFactory daoFactory;
37     protected DatabaseGateway db;
38
39     public static <T, R> List<R> map(Collection<T> collection, Function<T, R> fn) {
40         return collection.stream().map(fn).collect(Collectors.toList());
41     }
42
43     @Before
44     public void setUpBase() throws Exception {
45         em = orm.getEntityManager();
46         modelFactory = orm.getModelFactory();
47         daoFactory = orm.getDaoFactory();
48         db = orm.getDatabaseGateway();
49     }
50
51 }