@Test public void testEncodesWithFileDescriptorEncoderIfFileDescriptorIsNotNullAndStreamIs() throws IOException { ParcelFileDescriptor expected = ParcelFileDescriptor.dup(FileDescriptor.err); ImageVideoWrapper data = mock(ImageVideoWrapper.class); when(data.getStream()).thenReturn(null); when(data.getFileDescriptor()).thenReturn(expected); OutputStream os = new ByteArrayOutputStream(); when(fileDescriptorEncoder.encode(eq(expected), eq(os))).thenReturn(true); assertTrue(encoder.encode(data, os)); verify(fileDescriptorEncoder).encode(eq(expected), eq(os)); }