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