### Question:
ValidatingObjectInputStream extends ObjectInputStream { public ValidatingObjectInputStream reject(Class<?>... classes) { for (Class<?> c : classes) { rejectMatchers.add(new FullClassNameMatcher(c.getName())); } return this; } ValidatingObjectInputStream(InputStream input); ValidatingObjectInputStream accept(Class<?>... classes); ValidatingObjectInputStream reject(Class<?>... classes); ValidatingObjectInputStream accept(String... patterns); ValidatingObjectInputStream reject(String... patterns); ValidatingObjectInputStream accept(Pattern pattern); ValidatingObjectInputStream reject(Pattern pattern); ValidatingObjectInputStream accept(ClassNameMatcher m); ValidatingObjectInputStream reject(ClassNameMatcher m);  }### Answer:
@Test(expected = InvalidClassException.class) public void reject() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept(Long.class) .reject(MockSerializedClass.class, Integer.class) ); }
@Test(expected = InvalidClassException.class) public void rejectOnly() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .reject(Integer.class) ); }
@Test(expected = RuntimeException.class) public void customInvalidMethod() throws Exception { class CustomVOIS extends ValidatingObjectInputStream { CustomVOIS(InputStream is) throws IOException { super(is); } @Override protected void invalidClassNameFound(String className) throws InvalidClassException { throw new RuntimeException("Custom exception"); } }; assertSerialization( willClose(new CustomVOIS(testStream)) .reject(Integer.class) ); }