2121import org .junit .Test ;
2222
2323public class PluginArgumentParserTest {
24+
2425 @ Test
2526 public void parseJsonPath_onlyOnePresent () {
2627 String jsonPath = "/tmp/grpc_service_config.json" ;
27- assertEquals (jsonPath , PluginArgumentParser .parseJsonConfigPath (jsonPath ).get ());
28+ assertEquals (
29+ jsonPath ,
30+ PluginArgumentParser .parseJsonConfigPath (createGrpcServiceConfig (jsonPath )).get ());
31+ }
32+
33+ @ Test
34+ public void parseJsonPath_returnsFirstOneFound () {
35+ String jsonPathOne = "/tmp/foobar_grpc_service_config.json" ;
36+ String jsonPathTwo = "/tmp/some_other_grpc_service_config.json" ;
37+ assertEquals (
38+ jsonPathOne ,
39+ PluginArgumentParser .parseJsonConfigPath (
40+ String .join (
41+ "," ,
42+ Arrays .asList (
43+ createGrpcServiceConfig (jsonPathOne ),
44+ createGrpcServiceConfig (jsonPathTwo ))))
45+ .get ());
2846 }
2947
3048 @ Test
@@ -35,11 +53,11 @@ public void parseJsonPath_similarFileAppearsFirst() {
3553 String .join (
3654 "," ,
3755 Arrays .asList (
38- gapicPath ,
39- "/tmp/something.json" ,
40- "/tmp/some_grpc_service_configjson" ,
41- jsonPath ,
42- gapicPath ));
56+ createGapicConfig ( gapicPath ) ,
57+ createGrpcServiceConfig ( "/tmp/something.json" ) ,
58+ createGrpcServiceConfig ( "/tmp/some_grpc_service_configjson" ) ,
59+ createGrpcServiceConfig ( jsonPath ) ,
60+ createGapicConfig ( gapicPath ) ));
4361 assertEquals (jsonPath , PluginArgumentParser .parseJsonConfigPath (rawArgument ).get ());
4462 }
4563
@@ -51,19 +69,20 @@ public void parseJsonPath_argumentHasSpaces() {
5169 String .join (
5270 " , " ,
5371 Arrays .asList (
54- gapicPath ,
55- "/tmp/something.json" ,
56- "/tmp/some_grpc_service_configjson" ,
57- jsonPath ,
58- gapicPath ));
72+ createGapicConfig ( gapicPath ) ,
73+ createGrpcServiceConfig ( "/tmp/something.json" ) ,
74+ createGrpcServiceConfig ( "/tmp/some_grpc_service_configjson" ) ,
75+ createGrpcServiceConfig ( jsonPath ) ,
76+ createGapicConfig ( gapicPath ) ));
5977 assertEquals (jsonPath , PluginArgumentParser .parseJsonConfigPath (rawArgument ).get ());
6078 }
6179
6280 @ Test
6381 public void parseJsonPath_restAreEmpty () {
6482 String jsonPath = "/tmp/foobar_grpc_service_config.json" ;
6583 String gapicPath = "" ;
66- String rawArgument = String .join ("," , Arrays .asList (gapicPath , jsonPath , gapicPath ));
84+ String rawArgument =
85+ String .join ("," , Arrays .asList (gapicPath , createGrpcServiceConfig (jsonPath ), gapicPath ));
6786 assertEquals (jsonPath , PluginArgumentParser .parseJsonConfigPath (rawArgument ).get ());
6887 }
6988
@@ -77,7 +96,23 @@ public void parseJsonPath_noneFound() {
7796 @ Test
7897 public void parseGapicYamlPath_onlyOnePresent () {
7998 String gapicPath = "/tmp/something_gapic.yaml" ;
80- assertEquals (gapicPath , PluginArgumentParser .parseGapicYamlConfigPath (gapicPath ).get ());
99+ assertEquals (
100+ gapicPath ,
101+ PluginArgumentParser .parseGapicYamlConfigPath (createGapicConfig (gapicPath )).get ());
102+ }
103+
104+ @ Test
105+ public void parseGapicYamlPath_returnsFirstOneFound () {
106+ String gapicPathOne = "/tmp/something_gapic.yaml" ;
107+ String gapicPathTwo = "/tmp/other_gapic.yaml" ;
108+ assertEquals (
109+ gapicPathOne ,
110+ PluginArgumentParser .parseGapicYamlConfigPath (
111+ String .join (
112+ "," ,
113+ Arrays .asList (
114+ createGapicConfig (gapicPathOne ), createGapicConfig (gapicPathTwo ))))
115+ .get ());
81116 }
82117
83118 @ Test
@@ -86,23 +121,38 @@ public void parseGapicYamlPath_similarFileAppearsFirst() {
86121 String gapicPath = "/tmp/something_gapic.yaml" ;
87122 String rawArgument =
88123 String .join (
89- "," , Arrays .asList (jsonPath , "/tmp/something.yaml" , "/tmp/some_gapicyaml" , gapicPath ));
124+ "," ,
125+ Arrays .asList (
126+ createGrpcServiceConfig (jsonPath ),
127+ createGapicConfig ("/tmp/something.yaml" ),
128+ createGapicConfig ("/tmp/some_gapicyaml" ),
129+ createGapicConfig (gapicPath )));
90130 assertEquals (gapicPath , PluginArgumentParser .parseGapicYamlConfigPath (rawArgument ).get ());
91131 }
92132
93133 @ Test
94134 public void parseGapicYamlPath_restAreEmpty () {
95135 String jsonPath = "" ;
96136 String gapicPath = "/tmp/something_gapic.yaml" ;
97- String rawArgument = String .join ("," , Arrays .asList (jsonPath , gapicPath , jsonPath ));
137+ String rawArgument =
138+ String .join ("," , Arrays .asList (jsonPath , createGapicConfig (gapicPath ), jsonPath ));
98139 assertEquals (gapicPath , PluginArgumentParser .parseGapicYamlConfigPath (rawArgument ).get ());
99140 }
100141
101142 @ Test
102143 public void parseGapicYamlPath_noneFound () {
103144 String jsonPath = "/tmp/foo_grpc_service_config.json" ;
104145 String gapicPath = "" ;
105- String rawArgument = String .join ("," , Arrays .asList (jsonPath , gapicPath ));
146+ String rawArgument =
147+ String .join ("," , Arrays .asList (createGrpcServiceConfig (jsonPath ), gapicPath ));
106148 assertFalse (PluginArgumentParser .parseGapicYamlConfigPath (rawArgument ).isPresent ());
107149 }
150+
151+ private static String createGrpcServiceConfig (String path ) {
152+ return String .format ("%s=%s" , PluginArgumentParser .KEY_GRPC_SERVICE_CONFIG , path );
153+ }
154+
155+ private static String createGapicConfig (String path ) {
156+ return String .format ("%s=%s" , PluginArgumentParser .KEY_GAPIC_CONFIG , path );
157+ }
108158}
0 commit comments