88import java .nio .file .Files ;
99import java .nio .file .Path ;
1010import java .nio .file .Paths ;
11- import java .util .ArrayList ;
1211import java .util .Arrays ;
1312import java .util .Collections ;
13+ import java .util .HashMap ;
1414import java .util .List ;
1515import java .util .Map ;
1616
@@ -33,16 +33,16 @@ public void testIfRelevantSwaggerDocumentationIsUnchanged() throws IOException {
3333 //load released and new swagger docu information
3434 Map <String , Object > releasedSwaggerDocuMap = loadJson ("./src/test/resources/swagger.json" );
3535
36- Map <String , Object > newSwaggerDocuMap = loadJson ("./target/test-classes/ swagger.json" );
36+ Map <String , Object > newSwaggerDocuMap = loadJson ("./target/swagger.json" );
3737
3838 // Check whether path information is equal in new and released swagger docu
39- ArrayList < Object > releasedControllerList = new ArrayList < >();
40- extractPathsOfController (releasedSwaggerDocuMap , "External Visits Controller" , releasedControllerList );
39+ Map < String , Object > releasedControllerMap = new HashMap < String , Object >();
40+ extractPathsOfController (releasedSwaggerDocuMap , "External Visits Controller" , releasedControllerMap );
4141
42- ArrayList < Object > newControllerList = new ArrayList < >();
43- extractPathsOfController (newSwaggerDocuMap , "External Visits Controller" , newControllerList );
42+ Map < String , Object > newControllerMap = new HashMap < String , Object >();
43+ extractPathsOfController (newSwaggerDocuMap , "External Visits Controller" , newControllerMap );
4444
45- assertEquals (releasedControllerList , newControllerList );
45+ assertEquals (releasedControllerMap , newControllerMap );
4646
4747 // Check whether related enum information is equal
4848 List <String > enumNames = Arrays .asList (
@@ -56,15 +56,14 @@ public void testIfRelevantSwaggerDocumentationIsUnchanged() throws IOException {
5656 "SymptomState" ,
5757 "YesNoUnknown" ,
5858 "TemperatureSource" );
59+ Map <String , Object > releasedDetailMap = new HashMap <String , Object >();
60+ Map <String , Object > newDetailMap = new HashMap <String , Object >();
5961
6062 for (String name : enumNames ) {
61- ArrayList <Object > releasedDetailList = new ArrayList <>();
62- ArrayList <Object > newDetailList = new ArrayList <>();
63- extractDetail (releasedSwaggerDocuMap , name , releasedDetailList );
64- extractDetail (newSwaggerDocuMap , name , newDetailList );
65-
66- assertEquals ("" , releasedDetailList , newDetailList );
63+ extractDetail (releasedSwaggerDocuMap , name , releasedDetailMap );
64+ extractDetail (newSwaggerDocuMap , name , newDetailMap );
6765 }
66+ assertEquals (releasedDetailMap , newDetailMap );
6867 }
6968
7069 /**
@@ -73,22 +72,19 @@ public void testIfRelevantSwaggerDocumentationIsUnchanged() throws IOException {
7372 * Nested Map from which to extract the information. It's supposed to be a mapped swagger.json
7473 * @param controller
7574 * The name of the controller, e.g. External Visits Controller
76- * @param list
77- * Extracted information is stored in this list
75+ * @param resultMap
76+ * Extracted information is stored in this map
7877 * @return Documentation about any path found for the specified controller (e.g. /visits-external/person/{personUuid} for the External
7978 * Visits Controller). This includes parameter names for that path, but not information about related enums.
8079 */
81- private static void extractPathsOfController (Map <String , Object > level1 , String controller , ArrayList <Object > list ) {
82- level1 .entrySet ().forEach (e1 -> {
83- String key1 = e1 .getKey ();
84- Object value1 = e1 .getValue ();
80+ private static void extractPathsOfController (Map <String , Object > level1 , String controller , Map resultMap ) {
81+ level1 .forEach ((key1 , value1 ) -> {
8582 if (isInnerNode (value1 )) {
8683 Map <String , Object > level2 = innerNode (value1 );
8784 if (hasTag (level2 , controller )) {
88- list .add (key1 );
89- list .add (value1 );
85+ resultMap .put (key1 , value1 );
9086 }
91- extractPathsOfController (level2 , controller , list );
87+ extractPathsOfController (level2 , controller , resultMap );
9288 }
9389 });
9490 }
@@ -100,9 +96,7 @@ private static boolean hasTag(Map<String, Object> level2, String controller) {
10096 .map (ExternalVisitsResourceTest ::innerNode )
10197 // tags are always represented in the third layer and as ArrayLists
10298 .map (ExternalVisitsResourceTest ::tags )
103- .filter (t -> t .contains (controller ))
104- .findFirst ()
105- .isPresent ();
99+ .anyMatch (t -> t .contains (controller ));
106100 }
107101
108102 @ SuppressWarnings ("unchecked" )
@@ -121,20 +115,18 @@ private static List<Object> tags(Map<String, Object> innerNode) {
121115 * Nested Map from which to extract the information. It's supposed to be a mapped swagger.json
122116 * @param detailName
123117 * The name of the detail, e.g. JournalPersonDto.
124- * @param list
125- * Extracted information is stored in this list
118+ * @param resultMap
119+ * Extracted information is stored in this map
126120 * @return
127121 * Documentation found about the detail. The Map is searched for a key equal to detailName, an it, plus the according value is
128122 * added to the list.
129123 */
130- private static void extractDetail (Map <String , Object > level1 , String detailName , ArrayList <Object > list ) {
131- level1 .entrySet ().stream ().forEach (e1 -> {
132- Object value1 = e1 .getValue ();
133- if (detailName .equals (e1 .getKey ())) {
134- list .add (detailName );
135- list .add (value1 );
124+ private static void extractDetail (Map <String , Object > level1 , String detailName , Map resultMap ) {
125+ level1 .forEach ((key , value1 ) -> {
126+ if (detailName .equals (key )) {
127+ resultMap .put (detailName , value1 );
136128 } else if (isInnerNode (value1 )) {
137- extractDetail (innerNode (value1 ), detailName , list );
129+ extractDetail (innerNode (value1 ), detailName , resultMap );
138130 }
139131 });
140132 }
0 commit comments