### Question:
ClassFileDetectorStream extends InputStream { public boolean isClass() { return isClass; } ClassFileDetectorStream(String name, InputStream input); boolean isClass(); @Override int read(byte[] bytes); @Override int read(byte[] bytes, int offset, int length); @Override int read();  }### Answer:
@Test public void nonClassFileIsDetectedAsNotClass() throws IOException { byte[] dataArray = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; ByteArrayInputStream data = new ByteArrayInputStream(dataArray); ClassFileDetectorStream detector = new ClassFileDetectorStream("Foo.class", data); byte[] read = readAll(detector); assertThat(detector.isClass()).isFalse(); assertThat(read).isEqualTo(dataArray); }
@Test public void classFileIsDetectedAsClass() throws IOException { ByteArrayInputStream data = new ByteArrayInputStream(VALID_CLASS); ClassFileDetectorStream detector = new ClassFileDetectorStream("Foo.class", data); byte[] read = readAll(detector); assertThat(detector.isClass()).isTrue(); assertThat(read).isEqualTo(VALID_CLASS); }
@Test public void classFileInNonClassFileIsNotDetectedAsClass() throws IOException { ByteArrayInputStream data = new ByteArrayInputStream(VALID_CLASS); ClassFileDetectorStream detector = new ClassFileDetectorStream("Foo.clazz", data); byte[] read = readAll(detector); assertThat(detector.isClass()).isFalse(); assertThat(read).isEqualTo(VALID_CLASS); }