### Question:
BaseDataSource implements DataSource { @Override public final void addTransferListener(TransferListener transferListener) { if (!listeners.contains(transferListener)) { listeners.add(transferListener); listenerCount++; } } protected  BaseDataSource(boolean isNetwork); @Override final void addTransferListener(TransferListener transferListener);  }### Answer:
@Test public void dataTransfer_withLocalSource_isReported() throws IOException { TestSource testSource = new TestSource( false); TestTransferListener transferListener = new TestTransferListener(); testSource.addTransferListener(transferListener); DataSpec dataSpec = new DataSpec(Uri.EMPTY); testSource.open(dataSpec); testSource.read( null, 0, 100); testSource.close(); assertThat(transferListener.lastTransferInitializingSource).isSameAs(testSource); assertThat(transferListener.lastTransferStartSource).isSameAs(testSource); assertThat(transferListener.lastBytesTransferredSource).isSameAs(testSource); assertThat(transferListener.lastTransferEndSource).isSameAs(testSource); assertThat(transferListener.lastTransferInitializingDataSpec).isEqualTo(dataSpec); assertThat(transferListener.lastTransferStartDataSpec).isEqualTo(dataSpec); assertThat(transferListener.lastBytesTransferredDataSpec).isEqualTo(dataSpec); assertThat(transferListener.lastTransferEndDataSpec).isEqualTo(dataSpec); assertThat(transferListener.lastTransferInitializingIsNetwork).isEqualTo(false); assertThat(transferListener.lastTransferStartIsNetwork).isEqualTo(false); assertThat(transferListener.lastBytesTransferredIsNetwork).isEqualTo(false); assertThat(transferListener.lastTransferEndIsNetwork).isEqualTo(false); assertThat(transferListener.lastBytesTransferred).isEqualTo(100); }
@Test public void dataTransfer_withRemoteSource_isReported() throws IOException { TestSource testSource = new TestSource( true); TestTransferListener transferListener = new TestTransferListener(); testSource.addTransferListener(transferListener); DataSpec dataSpec = new DataSpec(Uri.EMPTY); testSource.open(dataSpec); testSource.read( null, 0, 100); testSource.close(); assertThat(transferListener.lastTransferInitializingSource).isSameAs(testSource); assertThat(transferListener.lastTransferStartSource).isSameAs(testSource); assertThat(transferListener.lastBytesTransferredSource).isSameAs(testSource); assertThat(transferListener.lastTransferEndSource).isSameAs(testSource); assertThat(transferListener.lastTransferInitializingDataSpec).isEqualTo(dataSpec); assertThat(transferListener.lastTransferStartDataSpec).isEqualTo(dataSpec); assertThat(transferListener.lastBytesTransferredDataSpec).isEqualTo(dataSpec); assertThat(transferListener.lastTransferEndDataSpec).isEqualTo(dataSpec); assertThat(transferListener.lastTransferInitializingIsNetwork).isEqualTo(true); assertThat(transferListener.lastTransferStartIsNetwork).isEqualTo(true); assertThat(transferListener.lastBytesTransferredIsNetwork).isEqualTo(true); assertThat(transferListener.lastTransferEndIsNetwork).isEqualTo(true); assertThat(transferListener.lastBytesTransferred).isEqualTo(100); }