### Question:
BinaryObject extends RepositoryObject { @Override public BinaryObject validateType() throws FedoraException { if (!isType(Fcrepo4Repository.Binary.getURI())) { throw new ObjectTypeMismatchException("Object " + pid + " is not a binary."); } return this; } protected  BinaryObject(PID pid, RepositoryObjectDriver driver,
            RepositoryObjectFactory repoObjFactory); protected  BinaryObject(PID pid, URI contentUri, RepositoryObjectDriver driver,
            RepositoryObjectFactory repoObjFactory); @Override BinaryObject validateType(); @Override RepositoryObject getParent(); InputStream getBinaryStream(); URI getContentUri(); @Override URI getMetadataUri(); String getFilename(); void setFilename(String filename); String getMimetype(); void setMimetype(String mimetype); String getSha1Checksum(); String getMd5Checksum(); void setSha1Checksum(String sha1); void setMd5Checksum(String md5); Long getFilesize(); void setFilesize(Long filesize);  }### Answer:
@Test public void testValidateType() { List<String> types = Arrays.asList(Fcrepo4Repository.Binary.toString()); when(driver.loadTypes(eq(binObj))).thenAnswer(new Answer<RepositoryObjectDriver>() { @Override public RepositoryObjectDriver answer(InvocationOnMock invocation) throws Throwable { binObj.setTypes(types); return driver; } }); binObj.validateType(); }
@Test(expected = ObjectTypeMismatchException.class) public void invalidTypeTest() { when(driver.loadTypes(eq(binObj))).thenAnswer(new Answer<RepositoryObjectDriver>() { @Override public RepositoryObjectDriver answer(InvocationOnMock invocation) throws Throwable { binObj.setTypes(Arrays.asList()); return driver; } }); binObj.validateType(); }