### Question:
DaoFactory { @SuppressWarnings("WeakerAccess") public <T extends Entity> Dao<T> daoFor(final Class<T> entityType, final Options options) throws IOException { Objects.requireNonNull(entityType); final EntityConfiguration<T> entityConfiguration = EntityRegistry.getConfigurationForType(entityType); return daoFor(entityConfiguration, options); } DaoFactory(final String projectId, final String instanceId); @SuppressWarnings("WeakerAccess") // Public API  DaoFactory(final Connection connection); @SuppressWarnings("WeakerAccess") // Public API Dao<T> daoFor(final Class<T> entityType, final Options options); @SuppressWarnings("WeakerAccess") // Public API Dao<T> daoFor(final Class<T> entityType); @SuppressWarnings("WeakerAccess") // Public API Dao<T> daoFor(final EntityConfiguration<T> entityConfiguration, final Options options); @SuppressWarnings("WeakerAccess") // Public API static OptionsBuilder optionsBuilder();  }### Answer:
@Test(expected = NullPointerException.class) public void testDaoForNullEntityTypeThrowsNullPointerException() throws IOException { daoFactory.daoFor(null); }
@Test(expected = IllegalStateException.class) public void testDaoForUnregisteredEntityTypeThrowsIllegalStateException() throws IOException { daoFactory.daoFor(UnregisteredEntity.class); }
@Test public void testDaoForRegisteredEntityTypeReturnsDaoForEntity() throws IOException { final Table table = mock(Table.class); when(connection.getTable(TableName.valueOf(TABLE_NAME))).thenReturn(table); final Dao<RegisteredEntity> registeredEntityDao = daoFactory.daoFor(RegisteredEntity.class); assertNotNull(registeredEntityDao); verify(connection).getTable(eq(TableName.valueOf(TABLE_NAME))); }
@Test public void testDaoForRegisteredEntityTypeWithNullOptionsReturnsDaoForEntityUsingDefaultTableName() throws IOException { final DaoFactory.Options options = null; final Table table = mock(Table.class); when(connection.getTable(TableName.valueOf(TABLE_NAME))).thenReturn(table); final Dao<RegisteredEntity> registeredEntityDao = daoFactory.daoFor(RegisteredEntity.class, options); assertNotNull(registeredEntityDao); verify(connection).getTable(eq(TableName.valueOf(TABLE_NAME))); }
@Test public void testDaoForUnRegisteredEntityTypeReturnsDaoForEntityConfiguration() throws IOException { final Table table = mock(Table.class); when(connection.getTable(TableName.valueOf(TABLE_NAME))).thenReturn(table); final Dao<UnregisteredEntity> unregisteredEntityDao = daoFactory.daoFor(UnregisteredEntity.TestConfiguration.INSTANCE, null); assertNotNull(unregisteredEntityDao); verify(connection).getTable(eq(TableName.valueOf(TABLE_NAME))); }