### Question:
BufferedBulkOperations implements BatchOperations<Bulk> { @Override public Object createBatchItem(String indexName, Object source) { throw new UnsupportedOperationException("Use ItemSource based API instead"); } BufferedBulkOperations(PooledItemSourceFactory pooledItemSourceFactory);  BufferedBulkOperations(PooledItemSourceFactory pooledItemSourceFactory, JacksonMixIn[] mixIns, String mappingType); @Override Object createBatchItem(String indexName, Object source); @Override Object createBatchItem(String indexName, ItemSource source); @Override BatchBuilder<Bulk> createBatchBuilder(); static final String DEFAULT_MAPPING_TYPE; }### Answer:
@Test public void throwsOnStringSource() { PooledItemSourceFactory bufferedSourceFactory = PooledItemSourceFactoryTest.createDefaultTestSourceFactoryConfig().build(); BufferedBulkOperations bufferedBulkOperations = new BufferedBulkOperations(bufferedSourceFactory); String indexName = UUID.randomUUID().toString(); String source = UUID.randomUUID().toString(); expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("Use ItemSource based API instead"); bufferedBulkOperations.createBatchItem(indexName, source); }
@Test public void defaultBufferedBulkOperationsSetsDefaultMappingType() { PooledItemSourceFactory bufferedSourceFactory = PooledItemSourceFactoryTest.createDefaultTestSourceFactoryConfig().build(); BufferedBulkOperations bulkOperations = new BufferedBulkOperations(bufferedSourceFactory); ItemSource itemSource = mock(ItemSource.class); BufferedIndex item = (BufferedIndex) bulkOperations.createBatchItem("testIndex", itemSource); String type = item.getType(); Assert.assertEquals(DEFAULT_MAPPING_TYPE, type); }
@Test public void mappingTypeCanBeSet() { String expectedMappingType = UUID.randomUUID().toString(); PooledItemSourceFactory bufferedSourceFactory = PooledItemSourceFactoryTest.createDefaultTestSourceFactoryConfig().build(); BufferedBulkOperations bulkOperations = new BufferedBulkOperations(bufferedSourceFactory, new JacksonMixIn[]{}, expectedMappingType); ItemSource itemSource = mock(ItemSource.class); BufferedIndex item = (BufferedIndex) bulkOperations.createBatchItem("testIndex", itemSource); String type = item.getType(); Assert.assertEquals(expectedMappingType, type); }