14
14
15
15
package com .google .api .generator .gapic .composer .rest ;
16
16
17
+ import com .google .api .generator .engine .ast .TypeNode ;
17
18
import com .google .api .generator .engine .writer .JavaWriterVisitor ;
19
+ import com .google .api .generator .gapic .model .Field ;
18
20
import com .google .api .generator .gapic .model .GapicClass ;
19
21
import com .google .api .generator .gapic .model .GapicContext ;
22
+ import com .google .api .generator .gapic .model .HttpBindings .HttpBinding ;
20
23
import com .google .api .generator .gapic .model .Service ;
21
24
import com .google .api .generator .test .framework .Assert ;
22
25
import com .google .api .generator .test .framework .Utils ;
26
+ import com .google .common .truth .Truth ;
23
27
import java .nio .file .Path ;
24
28
import java .nio .file .Paths ;
29
+ import org .junit .Before ;
25
30
import org .junit .Test ;
26
31
27
32
public class HttpJsonServiceStubClassComposerTest {
33
+
34
+ private HttpJsonServiceStubClassComposer composer ;
35
+
36
+ @ Before
37
+ public void setUp () throws Exception {
38
+ composer = HttpJsonServiceStubClassComposer .instance ();
39
+ }
40
+
28
41
@ Test
29
42
public void generateServiceClasses () {
30
43
GapicContext context = RestTestProtoLoader .instance ().parseCompliance ();
31
44
Service echoProtoService = context .services ().get (0 );
32
- GapicClass clazz =
33
- HttpJsonServiceStubClassComposer .instance ().generate (context , echoProtoService );
45
+ GapicClass clazz = composer .generate (context , echoProtoService );
34
46
35
47
JavaWriterVisitor visitor = new JavaWriterVisitor ();
36
48
clazz .classDefinition ().accept (visitor );
@@ -39,4 +51,49 @@ public void generateServiceClasses() {
39
51
Paths .get (Utils .getGoldenDir (this .getClass ()), "HttpJsonComplianceStub.golden" );
40
52
Assert .assertCodeEquals (goldenFilePath , visitor .write ());
41
53
}
54
+
55
+ @ Test
56
+ public void
57
+ getBindingFieldMethodName_shouldReturnGetFieldListIfTheFieldIsInLastPositionAndIsRepeated () {
58
+ Field field =
59
+ Field .builder ()
60
+ .setIsRepeated (true )
61
+ .setName ("doesNotMatter" )
62
+ .setType (TypeNode .OBJECT )
63
+ .build ();
64
+ HttpBinding httpBinding =
65
+ HttpBinding .builder ().setField (field ).setName ("doesNotMatter" ).build ();
66
+ String actual = composer .getBindingFieldMethodName (httpBinding , 4 , 3 , "Values" );
67
+ Truth .assertThat (actual ).isEqualTo ("getValuesList" );
68
+ }
69
+
70
+ @ Test
71
+ public void
72
+ getBindingFieldMethodName_shouldReturnGetFieldValueIfTheFieldIsInLastPositionAndIsEnum () {
73
+ Field field =
74
+ Field .builder ().setIsEnum (true ).setName ("doesNotMatter" ).setType (TypeNode .OBJECT ).build ();
75
+ HttpBinding httpBinding =
76
+ HttpBinding .builder ().setField (field ).setName ("doesNotMatter" ).build ();
77
+ String actual = composer .getBindingFieldMethodName (httpBinding , 4 , 3 , "Enums" );
78
+ Truth .assertThat (actual ).isEqualTo ("getEnumsValue" );
79
+ }
80
+
81
+ @ Test
82
+ public void
83
+ getBindingFieldMethodName_shouldReturnGetFieldIfTheFieldIsInLastPositionAndNotRepeatedOrEnum () {
84
+ Field field = Field .builder ().setName ("doesNotMatter" ).setType (TypeNode .OBJECT ).build ();
85
+ HttpBinding httpBinding =
86
+ HttpBinding .builder ().setField (field ).setName ("doesNotMatter" ).build ();
87
+ String actual = composer .getBindingFieldMethodName (httpBinding , 4 , 3 , "Value" );
88
+ Truth .assertThat (actual ).isEqualTo ("getValue" );
89
+ }
90
+
91
+ @ Test
92
+ public void getBindingFieldMethodName_shouldReturnGetFieldIfTheFieldIsNotInLastPosition () {
93
+ Field field = Field .builder ().setName ("doesNotMatter" ).setType (TypeNode .OBJECT ).build ();
94
+ HttpBinding httpBinding =
95
+ HttpBinding .builder ().setField (field ).setName ("doesNotMatter" ).build ();
96
+ String actual = composer .getBindingFieldMethodName (httpBinding , 4 , 1 , "Value" );
97
+ Truth .assertThat (actual ).isEqualTo ("getValue" );
98
+ }
42
99
}
0 commit comments