@@ -966,6 +966,36 @@ public void setsAndRetrievesDispositionAt() throws ParseException {
966966 }
967967 }
968968
969+ @ Test
970+ public void uploadAndDownloadEmptyFileSucceeds () throws IOException {
971+ BoxAPIConnection api = jwtApiForServiceAccount ();
972+ BoxFolder folder = getUniqueFolder (api );
973+ String fileName = "empty_file" ;
974+ URL fileURL = this .getClass ().getResource ("/sample-files/" + fileName );
975+ String filePath = URLDecoder .decode (fileURL .getFile (), "utf-8" );
976+ long fileSize = new File (filePath ).length ();
977+ byte [] fileContent = readAllBytes (filePath );
978+ BoxFile uploadedFile = null ;
979+ try {
980+ InputStream uploadStream = Files .newInputStream (Paths .get (filePath ));
981+ ProgressListener mockUploadListener = mock (ProgressListener .class );
982+ BoxFile .Info uploadedFileInfo = folder .uploadFile (
983+ uploadStream , BoxFileIT .generateString (), fileSize , mockUploadListener
984+ );
985+ uploadedFile = uploadedFileInfo .getResource ();
986+
987+ ByteArrayOutputStream downloadStream = new ByteArrayOutputStream ();
988+ uploadedFile .download (downloadStream );
989+ byte [] downloadedFileContent = downloadStream .toByteArray ();
990+
991+ assertThat (downloadedFileContent , is (equalTo (fileContent )));
992+ assertThat (folder , hasItem (Matchers .<BoxItem .Info >hasProperty ("ID" , equalTo (uploadedFile .getID ()))));
993+ } finally {
994+ deleteFile (uploadedFile );
995+ }
996+
997+ }
998+
969999 private byte [] readFileContent (String fileName ) throws IOException {
9701000 URL fileURL = this .getClass ().getResource ("/sample-files/" + fileName );
9711001 String filePath = URLDecoder .decode (fileURL .getFile (), "utf-8" );
0 commit comments