28
28
29
29
import java .io .IOException ;
30
30
31
- import junit .framework .Assert ;
32
31
import junit .framework .TestCase ;
33
32
34
33
/**
@@ -69,10 +68,48 @@ public void testJsonHttpClientBuilder() {
69
68
.setJsonHttpRequestInitializer (jsonHttpRequestInitializer )
70
69
.setApplicationName (applicationName ).build ();
71
70
72
- Assert .assertEquals (baseUrl .build (), client .getBaseUrl ());
73
- Assert .assertEquals (applicationName , client .getApplicationName ());
74
- Assert .assertEquals (jsonFactory , client .getJsonFactory ());
75
- Assert .assertEquals (jsonHttpRequestInitializer , client .getJsonHttpRequestInitializer ());
71
+ assertEquals (baseUrl .build (), client .getBaseUrl ());
72
+ assertEquals (applicationName , client .getApplicationName ());
73
+ assertEquals (jsonFactory , client .getJsonFactory ());
74
+ assertEquals (jsonHttpRequestInitializer , client .getJsonHttpRequestInitializer ());
75
+ }
76
+
77
+ public void testBaseServerAndBasePathBuilder () {
78
+ JsonHttpClient client =
79
+ JsonHttpClient
80
+ .builder (new NetHttpTransport (), new JacksonFactory (),
81
+ new GenericUrl ("http://www.testgoogleapis.com/test/path/v1/" ))
82
+ .setBaseHost ("www.googleapis.com" )
83
+ .setBasePath ("/test/path/v2/" )
84
+ .build ();
85
+
86
+ assertEquals ("http://www.googleapis.com/test/path/v2/" , client .getBaseUrl ());
87
+ }
88
+
89
+ public void testInvalidBasePath () {
90
+ JsonHttpClient .Builder builder =
91
+ JsonHttpClient .builder (new NetHttpTransport (), new JacksonFactory (), new GenericUrl (
92
+ "http://www.testgoogleapis.com/test/path/v1/" ));
93
+ try {
94
+ builder .setBasePath (null );
95
+ fail ("Expected exception not thrown!" );
96
+ } catch (NullPointerException e ) {
97
+ // Expected because base path cannot be null.
98
+ }
99
+
100
+ try {
101
+ builder .setBasePath ("test/path/v2/" );
102
+ fail ("Expected exception not thrown!" );
103
+ } catch (IllegalArgumentException e ) {
104
+ // Expected because base path did not start with "/".
105
+ }
106
+
107
+ try {
108
+ builder .setBasePath ("/test/path/v2" );
109
+ fail ("Expected exception not thrown!" );
110
+ } catch (IllegalArgumentException e ) {
111
+ // Expected because base path did not end with "/".
112
+ }
76
113
}
77
114
78
115
public void testInitialize () throws IOException {
@@ -83,7 +120,7 @@ public void testInitialize() throws IOException {
83
120
.setJsonHttpRequestInitializer (remoteRequestInitializer )
84
121
.setApplicationName ("Test Application" ).build ();
85
122
client .initialize (null );
86
- Assert . assertTrue (remoteRequestInitializer .isCalled );
123
+ assertTrue (remoteRequestInitializer .isCalled );
87
124
}
88
125
89
126
public void testExecute () throws IOException {
@@ -97,7 +134,7 @@ public LowLevelHttpRequest buildGetRequest(final String url) {
97
134
public LowLevelHttpResponse execute () {
98
135
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse ();
99
136
// Assert the requested URL is the expected one.
100
- Assert . assertEquals (testBaseUrl + testUriTemplate , url );
137
+ assertEquals (testBaseUrl + testUriTemplate , url );
101
138
return response ;
102
139
}
103
140
};
0 commit comments