File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
main/java/com/orgsync/api
test/java/com/orgsync/api Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
15- */
15+ */
1616package com .orgsync .api ;
1717
1818import java .io .IOException ;
7070
7171 @ Override
7272 public void destroy () {
73- getHttpClient ().close ();
73+ closeHttpClient ();
74+ }
75+
76+ private void closeHttpClient () {
77+ if (getHttpClient () != null ) {
78+ getHttpClient ().close ();
79+ }
80+
7481 }
7582
7683 @ Override
@@ -85,6 +92,10 @@ public AsyncHttpClient getHttpClient() {
8592
8693 @ Override
8794 public ApiClientImpl setHttpClient (final AsyncHttpClient client ) {
95+ Util .checkNotNull (client );
96+
97+ closeHttpClient ();
98+
8899 this .client = client ;
89100 return this ;
90101 }
Original file line number Diff line number Diff line change 1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
15- */
15+ */
1616package com .orgsync .api ;
1717
1818import static org .junit .Assert .assertEquals ;
19+ import static org .junit .Assert .assertSame ;
1920import static org .mockito .Matchers .any ;
2021import static org .mockito .Mockito .mock ;
2122import static org .mockito .Mockito .verify ;
@@ -72,6 +73,20 @@ public void testDestroy() {
7273 verify (http ).close ();
7374 }
7475
76+ @ Test
77+ public void testSetHttpClient () throws Exception {
78+ AsyncHttpClient newClient = mock (AsyncHttpClient .class );
79+
80+ client .setHttpClient (newClient );
81+
82+ assertSame (newClient , client .getHttpClient ());
83+
84+ client .destroy ();
85+
86+ verify (http ).close ();
87+ verify (newClient ).close ();
88+ }
89+
7590 @ Test
7691 @ SuppressWarnings ({ "rawtypes" , "unchecked" })
7792 public void testGetResource () throws Exception {
You can’t perform that action at this time.
0 commit comments