1
+ package edu .harvard .dbmi .avillach .dictionary ;
2
+
3
+ import edu .harvard .dbmi .avillach .dictionary .concept .ConceptService ;
4
+ import edu .harvard .dbmi .avillach .dictionary .concept .model .CategoricalConcept ;
5
+ import edu .harvard .dbmi .avillach .dictionary .concept .model .Concept ;
6
+ import org .junit .jupiter .api .Assertions ;
7
+ import org .junit .jupiter .api .Test ;
8
+ import org .mockito .Mockito ;
9
+ import org .springframework .beans .factory .annotation .Autowired ;
10
+ import org .springframework .boot .test .context .SpringBootTest ;
11
+ import org .springframework .boot .test .mock .mockito .MockBean ;
12
+
13
+ import java .util .Optional ;
14
+
15
+
16
+ @ SpringBootTest
17
+ class ConceptDecoratorServiceTest {
18
+
19
+ @ MockBean
20
+ ConceptService conceptService ;
21
+
22
+ @ Autowired
23
+ ConceptDecoratorService subject ;
24
+
25
+ @ Test
26
+ void shouldPopulateCompliantStudy () {
27
+ CategoricalConcept concept = new CategoricalConcept ("\\ study\\ table\\ idk\\ concept\\ " , "dataset" );
28
+ CategoricalConcept table = new CategoricalConcept ("\\ study\\ table\\ " , "dataset" );
29
+ CategoricalConcept study = new CategoricalConcept ("\\ study\\ " , "dataset" );
30
+
31
+ Mockito .when (conceptService .conceptDetail ("dataset" , table .dataset ()))
32
+ .thenReturn (Optional .of (table ));
33
+ Mockito .when (conceptService .conceptDetail ("dataset" , study .dataset ()))
34
+ .thenReturn (Optional .of (study ));
35
+
36
+ Concept actual = subject .populateParentConcepts (concept );
37
+ Concept expected = concept .withStudy (study ).withTable (table );
38
+
39
+ Assertions .assertEquals (expected , actual );
40
+ }
41
+
42
+ @ Test
43
+ void shouldPopulateNonCompliantTabledStudy () {
44
+ CategoricalConcept concept = new CategoricalConcept ("\\ study\\ table\\ concept\\ " , "dataset" );
45
+ CategoricalConcept table = new CategoricalConcept ("\\ study\\ table\\ " , "dataset" );
46
+ CategoricalConcept study = new CategoricalConcept ("\\ study\\ " , "dataset" );
47
+
48
+ Mockito .when (conceptService .conceptDetail ("dataset" , table .dataset ()))
49
+ .thenReturn (Optional .of (table ));
50
+ Mockito .when (conceptService .conceptDetail ("dataset" , study .dataset ()))
51
+ .thenReturn (Optional .of (study ));
52
+
53
+ Concept actual = subject .populateParentConcepts (concept );
54
+ Concept expected = concept .withStudy (study ).withTable (table );
55
+
56
+ Assertions .assertEquals (expected , actual );
57
+ }
58
+
59
+ @ Test
60
+ void shouldPopulateNonCompliantUnTabledStudy () {
61
+ CategoricalConcept concept = new CategoricalConcept ("\\ study\\ concept\\ " , "dataset" );
62
+ CategoricalConcept study = new CategoricalConcept ("\\ study\\ " , "dataset" );
63
+
64
+ Mockito .when (conceptService .conceptDetail ("dataset" , study .dataset ()))
65
+ .thenReturn (Optional .of (study ));
66
+
67
+ Concept actual = subject .populateParentConcepts (concept );
68
+ Concept expected = concept .withStudy (study );
69
+
70
+ Assertions .assertEquals (expected , actual );
71
+ }
72
+ }
0 commit comments