DownloadRequest { public Intent createIntent(Context context) { if (torrentFile == null) { throw new IllegalStateException("torrentFile must not be null"); } if (destinationDirectory == null) { throw new IllegalStateException("destinationDirectory must not be null"); } Intent intent = new Intent(context, BitTorrentDownloadService.class); intent.setAction(BitTorrentIntentConstants.ACTION_START_DOWNLOAD); intent.putExtra(BitTorrentIntentConstants.EXTRA_TORRENT_FILE, torrentFile.getPath()); intent.putExtra(BitTorrentIntentConstants.EXTRA_DESTINATION_DIRECTORY, destinationDirectory.getPath()); return intent; } DownloadRequest(); DownloadRequest setTorrentFile(Uri torrentFile); DownloadRequest setDestinationDirectory(Uri destinationDirectory); Intent createIntent(Context context);  }
@Test public void testEmptyRequest() { DownloadRequest downloadRequest = new DownloadRequest(); try { downloadRequest.createIntent(RuntimeEnvironment.application); failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException expectedException) { } }
@Test public void testCreateIntent() { String torrentFile = "file"; String destinationDirectory = "dir"; DownloadRequest downloadRequest = new DownloadRequest(); downloadRequest.setTorrentFile(Uri.parse(torrentFile)); downloadRequest.setDestinationDirectory(Uri.parse(destinationDirectory)); Intent intent = downloadRequest.createIntent(RuntimeEnvironment.application); assertThat(intent.getAction()).isEqualTo(BitTorrentIntentConstants.ACTION_START_DOWNLOAD); assertThat(intent.getStringExtra(BitTorrentIntentConstants.EXTRA_TORRENT_FILE)) .isEqualToIgnoringCase(torrentFile); assertThat(intent.getStringExtra(BitTorrentIntentConstants.EXTRA_DESTINATION_DIRECTORY)) .isEqualToIgnoringCase(destinationDirectory); }