DownloadProgressBroadcast { public Intent createIntent() { if (torrentFile == null) { throw new IllegalStateException("torrentFile must not be null"); } if (progress < 0 || progress > 100) { throw new IllegalStateException("progress out of range"); } Intent intent = new Intent(BitTorrentIntentConstants.ACTION_BROADCAST_PROGRESS); intent.putExtra(BitTorrentIntentConstants.EXTRA_TORRENT_FILE, torrentFile); intent.putExtra(BitTorrentIntentConstants.EXTRA_DOWNLOAD_PROGRESS, progress); return intent; } DownloadProgressBroadcast(); static Intent createProgressIntent(String torrentFile, int progress); DownloadProgressBroadcast setTorrentFile(String torrentFile); DownloadProgressBroadcast setProgress(int progress); Intent createIntent();  }
@Test public void testCreateIntent() { final String torrentFile = "file"; final int progress = 42; DownloadProgressBroadcast broadcast = new DownloadProgressBroadcast(); broadcast.setTorrentFile(torrentFile); broadcast.setProgress(progress); Intent intent = broadcast.createIntent(); assertThat(intent.getAction()).isEqualTo(BitTorrentIntentConstants.ACTION_BROADCAST_PROGRESS); assertThat(intent.getStringExtra(BitTorrentIntentConstants.EXTRA_TORRENT_FILE)) .isEqualToIgnoringCase(torrentFile); assertThat(intent.getIntExtra(BitTorrentIntentConstants.EXTRA_DOWNLOAD_PROGRESS, -1)) .isEqualTo(progress); }
@Test public void testBroadcastWithOutData() { DownloadProgressBroadcast broadcast = new DownloadProgressBroadcast(); try { broadcast.createIntent(); failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException expectedException) { } }