Buggy code:
} } assertTrue ( MMX . getMMXClient ( ) . isConnected ( ) ) ; MMX . start ( ) ; final AtomicLong attachmentSize = new AtomicLong ( ) ; final AtomicReference < Attachment > attachmentRef = new AtomicReference < > ( ) ; final ExecMonitor < HashMap < String , Object > , Void > receivedResult = new ExecMonitor < HashMap < String , Object > , Void > ( ) ; final StringBuffer senderBuffer = new StringBuffer ( ) ; final ExecMonitor < String , Void > acknowledgeResult = new ExecMonitor < String , Void > ( ) ; MMX . EventListener messageListener = new MMX . EventListener ( ) { public boolean onMessageReceived ( MMXMessage message ) { Log . d ( MMXMessageTest . TAG , ( "onMessageReceived():<seq2seq4repair_space>" + ( message . getId ( ) ) ) ) ; senderBuffer . append ( message . getSender ( ) . getFirstName ( ) ) ; HashMap < String , Object > receivedContent = new HashMap < String , Object > ( ) ; for ( Map . Entry < String , String > entry : message . getContent ( ) . entrySet ( ) ) { receivedContent . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } assertNotNull ( message . getAttachments ( ) ) ; assertEquals ( 1 , message . getAttachments ( ) . size ( ) ) ; Attachment attachmentReceived = message . getAttachments ( ) . get ( 0 ) ; assertEquals ( "image//jpeg" , attachmentReceived . getMimeType ( ) ) ; assertEquals ( INIT , attachmentReceived . getStatus ( ) ) ; assertNotNull ( attachmentReceived . getDownloadUrl ( ) ) ; attachmentRef . set ( attachmentReceived ) ; receivedResult . invoked ( receivedContent ) ; message . acknowledge ( null ) ; return false ; } public boolean onMessageAcknowledgementReceived ( User from , String messageId ) { acknowledgeResult . invoked ( messageId ) ; return false ; } } ; MMX . registerListener ( messageListener ) ; HashSet < User > recipients = new HashSet < User > ( ) ; recipients . add ( MMX . getCurrentUser ( ) ) ; HashMap < String , String > content = new HashMap < String , String > ( ) ; content . put ( "foo" , "bar" ) ; final Attachment attachment1 = new Attachment ( getContext ( ) . getResources ( ) . openRawResource ( test_image ) , "image//jpeg" ) ; MMXMessage message = new MMXMessage . Builder ( ) . recipients ( recipients ) . content ( content ) . attachments ( attachment1 ) . build ( ) ; final ExecMonitor < String , Boolean > sendResult = new ExecMonitor < String , Boolean > ( ) ; final String messageId = message . send ( new MMXMessage . OnFinishedListener < String > ( ) { public void onSuccess ( String result ) { Log . e ( MMXMessageTest . TAG , ( "testSendMessage():<seq2seq4repair_space>onSuccess()<seq2seq4repair_space>msgId=" + result ) ) ; assertTrue ( ( ( attachment1 . getLength ( ) ) > 0 ) ) ; attachmentSize . set ( attachment1 . getLength ( ) ) ; sendResult . invoked ( result ) ; } public void onFailure ( MMXMessage . FailureCode code , Throwable ex ) { Log . e ( MMXMessageTest . TAG , ( "testSendMessage():<seq2seq4repair_space>failureCode=" + code ) , ex ) ; sendResult . failed ( Boolean . TRUE ) ; } } ) ; ExecMonitor . Status status = sendResult . waitFor ( MMXMessageTest . TIMEOUT ) ; assertEquals ( INVOKED , status ) ; assertEquals ( messageId , sendResult . getReturnValue ( ) ) ; status = receivedResult . waitFor ( MMXMessageTest . TIMEOUT ) ; if ( status == ( Status . WAITING ) ) { fail ( "testSendMessage()<seq2seq4repair_space>receive<seq2seq4repair_space>msg<seq2seq4repair_space>timed<seq2seq4repair_space>out" ) ; } assertEquals ( "bar" , receivedResult . getReturnValue ( ) . get ( "foo" ) ) ; assertEquals ( MMX . getCurrentUser ( ) . getFirstName ( ) , senderBuffer . toString ( ) ) ; status = acknowledgeResult . waitFor ( MMXMessageTest . TIMEOUT ) ; if ( status == ( Status . WAITING ) ) { fail ( "testSenddMessage()<seq2seq4repair_space>receive<seq2seq4repair_space>acknowledgement<seq2seq4repair_space>timed<seq2seq4repair_space>out" ) ; } assertEquals ( messageId , acknowledgeResult . getReturnValue ( ) ) ; assertNotNull ( attachmentRef . get ( ) ) ; Log . d ( MMXMessageTest . TAG , "-----------attachment<seq2seq4repair_space>received" ) ; final CountDownLatch downLatch = new CountDownLatch ( 1 ) ; Attachment attachmentReceived = attachmentRef . get ( ) ; <START_BUG> attachmentReceived . download ( new Attachment . DownloadToBytesListener ( ) { <END_BUG> @ Override public void onComplete ( byte [ ] bytes ) { assertNotNull ( bytes ) ; assertTrue ( ( ( bytes . length ) > 0 ) ) ; downLatch . countDown ( ) ; } @ Override public void onError ( Throwable throwable ) { fail ( throwable . getMessage ( ) ) ; } } ) ; try { downLatch . await ( MMXMessageTest . TIMEOUT , TimeUnit . MILLISECONDS ) ; } catch ( InterruptedException e ) { fail ( e . getMessage ( ) ) ; } assertEquals ( 0 , downLatch . getCount ( ) ) ; assertEquals ( COMPLETE , attachmentReceived . getStatus ( ) ) ; assertNotNull ( attachmentReceived . getAsBytes ( ) ) ; assertEquals ( attachmentReceived . getLength ( ) , attachmentReceived . getAsBytes ( ) . length ) ; MMX . unregisterListener ( messageListener ) ; logoutMMX ( ) ; ApiCallback < Boolean > logoutListener = getLogoutListener ( ) ; User . logout ( logoutListener ) ; synchronized ( logoutListener ) { try { logoutListener . wait ( MMXMessageTest . TIMEOUT ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } } public void testSendBeforeLogin ( ) { } public void testSendUCastMessageError ( ) { } public void testSendMCastMessageError ( ) { } }

Fix:
attachmentReceived . download ( new Attachment . DownloadAsBytesListener ( ) {