@@ -480,7 +480,7 @@ private BatchRequest getBatchPopulatedWithRequests(boolean testServerError,
480480 boolean returnSuccessAuthenticatedContent ,
481481 boolean testRedirect ,
482482 boolean testBinary ,
483- boolean testMissingLength ) throws Exception {
483+ boolean testMissingLength ) throws IOException {
484484 transport = new MockTransport (testServerError ,
485485 testAuthenticationError ,
486486 testRedirect ,
@@ -540,7 +540,7 @@ public void testQueueDatastructures() throws Exception {
540540 assertEquals (METHOD2 , requestInfos .get (1 ).request .getRequestMethod ());
541541 }
542542
543- public void testExecute () throws Exception {
543+ public void testExecute () throws IOException {
544544 BatchRequest batchRequest =
545545 getBatchPopulatedWithRequests (false , false , false , false , false , false );
546546 batchRequest .execute ();
@@ -552,7 +552,7 @@ public void testExecute() throws Exception {
552552 assertTrue (batchRequest .requestInfos .isEmpty ());
553553 }
554554
555- public void testExecuteWithError () throws Exception {
555+ public void testExecuteWithError () throws IOException {
556556 BatchRequest batchRequest =
557557 getBatchPopulatedWithRequests (true , false , false , false , false , false );
558558 batchRequest .execute ();
@@ -582,7 +582,7 @@ public void testExecuteWithVoidCallbackError() throws Exception {
582582 assertEquals (1 , callback3 .failureCalls );
583583 }
584584
585- public void subTestExecuteWithVoidCallback (boolean testServerError ) throws Exception {
585+ public void subTestExecuteWithVoidCallback (boolean testServerError ) throws IOException {
586586 MockTransport transport = new MockTransport (testServerError , false ,false , false , false );
587587 MockGoogleClient client = new MockGoogleClient .Builder (
588588 transport , ROOT_URL , SERVICE_PATH , null , null ).setApplicationName ("Test Application" )
@@ -661,29 +661,34 @@ public void testExecute_checkWriteTo() throws Exception {
661661
662662 String request2Method = HttpMethods .GET ;
663663 String request2Url = "http://test/dummy/url2" ;
664-
665- final StringBuilder expectedOutput = new StringBuilder ();
666- expectedOutput .append ("--__END_OF_PART__\r \n " );
667- expectedOutput .append ("Content-Length: 118\r \n " );
668- expectedOutput .append ("Content-Type: application/http\r \n " );
669- expectedOutput .append ("content-id: 1\r \n " );
670- expectedOutput .append ("content-transfer-encoding: binary\r \n " );
671- expectedOutput .append ("\r \n " );
672- expectedOutput .append ("POST http://test/dummy/url1 HTTP/1.1\r \n " );
673- expectedOutput .append ("Content-Length: 26\r \n " );
674- expectedOutput .append ("Content-Type: " + request1ContentType + "\r \n " );
675- expectedOutput .append ("\r \n " );
676- expectedOutput .append (request1Content + "\r \n " );
677- expectedOutput .append ("--__END_OF_PART__\r \n " );
678- expectedOutput .append ("Content-Length: 39\r \n " );
679- expectedOutput .append ("Content-Type: application/http\r \n " );
680- expectedOutput .append ("content-id: 2\r \n " );
681- expectedOutput .append ("content-transfer-encoding: binary\r \n " );
682- expectedOutput .append ("\r \n " );
683- expectedOutput .append ("GET http://test/dummy/url2 HTTP/1.1\r \n " );
684- expectedOutput .append ("\r \n " );
685- expectedOutput .append ("\r \n " );
686- expectedOutput .append ("--__END_OF_PART__--\r \n " );
664+
665+ // MIME content boundaries are not reproducible.
666+ StringBuilder part1 = new StringBuilder ();
667+ part1 .append ("Content-Length: 118\r \n " );
668+ part1 .append ("Content-Type: application/http\r \n " );
669+ part1 .append ("content-id: 1\r \n " );
670+ part1 .append ("content-transfer-encoding: binary\r \n " );
671+ part1 .append ("\r \n " );
672+ part1 .append ("POST http://test/dummy/url1 HTTP/1.1\r \n " );
673+ part1 .append ("Content-Length: 26\r \n " );
674+ part1 .append ("Content-Type: " + request1ContentType + "\r \n " );
675+ part1 .append ("\r \n " );
676+ part1 .append (request1Content + "\r \n " );
677+ part1 .append ("--__END_OF_PART__" );
678+ String expected1 = part1 .toString ();
679+
680+ StringBuilder part2 = new StringBuilder ();
681+ part2 .append ("Content-Length: 39\r \n " );
682+ part2 .append ("Content-Type: application/http\r \n " );
683+ part2 .append ("content-id: 2\r \n " );
684+ part2 .append ("content-transfer-encoding: binary\r \n " );
685+ part2 .append ("\r \n " );
686+ part2 .append ("GET http://test/dummy/url2 HTTP/1.1\r \n " );
687+ part2 .append ("\r \n " );
688+ part2 .append ("\r \n " );
689+ part2 .append ("--__END_OF_PART__" );
690+ String expected2 = part2 .toString ();
691+
687692 MockHttpTransport transport = new MockHttpTransport ();
688693 HttpRequest request1 =
689694 transport
@@ -694,11 +699,11 @@ public void testExecute_checkWriteTo() throws Exception {
694699 new ByteArrayContent (request1ContentType , request1Content .getBytes (UTF_8 )));
695700 HttpRequest request2 = transport .createRequestFactory ()
696701 .buildRequest (request2Method , new GenericUrl (request2Url ), null );
697- subtestExecute_checkWriteTo (expectedOutput . toString () , request1 , request2 );
702+ subtestExecute_checkWriteTo (expected1 , expected2 , request1 , request2 );
698703 }
699704
700- private void subtestExecute_checkWriteTo (final String expectedOutput , HttpRequest ... requests )
701- throws IOException {
705+ private void subtestExecute_checkWriteTo (
706+ final String part1 , final String part2 , HttpRequest ... requests ) throws IOException {
702707
703708 MockHttpTransport transport = new MockHttpTransport () {
704709
@@ -708,10 +713,12 @@ public LowLevelHttpRequest buildRequest(String method, String url) {
708713
709714 @ Override
710715 public LowLevelHttpResponse execute () throws IOException {
711- assertEquals ( "multipart/mixed; boundary=__END_OF_PART__" , getContentType ( ));
716+ assertTrue ( getContentType (). startsWith ( "multipart/mixed; boundary=__END_OF_PART__" ));
712717 ByteArrayOutputStream out = new ByteArrayOutputStream ();
713718 getStreamingContent ().writeTo (out );
714- assertEquals (expectedOutput , out .toString ("UTF-8" ));
719+ String actual = out .toString ("UTF-8" );
720+ assertTrue (actual + "\n does not contain \n " + part1 , actual .contains (part1 ));
721+ assertTrue (actual .contains (part2 ));
715722 MockLowLevelHttpResponse response = new MockLowLevelHttpResponse ();
716723 response .setStatusCode (200 );
717724 response .addHeader ("Content-Type" , "multipart/mixed; boundary=" + RESPONSE_BOUNDARY );
@@ -748,9 +755,9 @@ public void onFailure(Void e, HttpHeaders responseHeaders) {
748755 batchRequest .execute ();
749756 }
750757
751- public void testExecute_checkWriteToNoHeaders () throws Exception {
758+ public void testExecute_checkWriteToNoHeaders () throws IOException {
752759 MockHttpTransport transport = new MockHttpTransport ();
753- HttpRequest request1 = transport .createRequestFactory ()
760+ HttpRequest request = transport .createRequestFactory ()
754761 .buildPostRequest (HttpTesting .SIMPLE_GENERIC_URL , new HttpContent () {
755762
756763 @ Override
@@ -772,14 +779,15 @@ public boolean retrySupported() {
772779 return true ;
773780 }
774781 });
775- subtestExecute_checkWriteTo (new StringBuilder ().append ("--__END_OF_PART__\r \n " )
776- .append ("Content-Length: 36\r \n " ).append ("Content-Type: application/http\r \n " )
777- .append ("content-id: 1\r \n " ).append ("content-transfer-encoding: binary\r \n " ).append ("\r \n " )
778- .append ("POST http://google.com/ HTTP/1.1\r \n " ).append ("\r \n " ).append ("\r \n " )
779- .append ("--__END_OF_PART__--\r \n " ).toString (), request1 );
782+ String expected = new StringBuilder ()
783+ .append ("Content-Length: 36\r \n " ).append ("Content-Type: application/http\r \n " )
784+ .append ("content-id: 1\r \n " ).append ("content-transfer-encoding: binary\r \n " ).append ("\r \n " )
785+ .append ("POST http://google.com/ HTTP/1.1\r \n " ).append ("\r \n " ).append ("\r \n " )
786+ .append ("--__END_OF_PART__" ).toString ();
787+ subtestExecute_checkWriteTo (expected , expected , request );
780788 }
781789
782- public void testProtoExecute () throws Exception {
790+ public void testProtoExecute () throws IOException {
783791 BatchRequest batchRequest =
784792 getBatchPopulatedWithRequests (false , false , false , false , true , false );
785793 batchRequest .execute ();
@@ -791,7 +799,7 @@ public void testProtoExecute() throws Exception {
791799 assertTrue (batchRequest .requestInfos .isEmpty ());
792800 }
793801
794- public void testProtoExecuteWithError () throws Exception {
802+ public void testProtoExecuteWithError () throws IOException {
795803 BatchRequest batchRequest =
796804 getBatchPopulatedWithRequests (true , false , false , false , true , false );
797805 batchRequest .execute ();
@@ -805,7 +813,7 @@ public void testProtoExecuteWithError() throws Exception {
805813 assertEquals (1 , transport .actualCalls );
806814 }
807815
808- public void testProtoExecuteWithoutLength () throws Exception {
816+ public void testProtoExecuteWithoutLength () throws IOException {
809817 BatchRequest batchRequest =
810818 getBatchPopulatedWithRequests (false , false , false , false , true , true );
811819 batchRequest .execute ();
0 commit comments