@Test
public void copyBufferToStorage() throws IOException, SerializationException, BusinessException {
storageData = new StorageData();
storageData.setName("Test");
DefaultData defaultData = mock(DefaultData.class);
Timestamp timestamp = mock(Timestamp.class);
when(defaultData.getTimeStamp()).thenReturn(timestamp);
when(buffer.getOldestElement()).thenReturn(defaultData);
List<DefaultData> data = Collections.singletonList(mock(DefaultData.class));
Collection<AbstractDataProcessor> processors = Collections.singleton(mock(AbstractDataProcessor.class));
Long platformId = 10L;
List<Long> platformIdents = Collections.singletonList(platformId);
storageManager = spy(storageManager);
when(storageDataDao.getAllDefaultDataForAgent(eq(platformId), Matchers.<Date> any(), Matchers.<Date> any())).thenReturn(data);
storageManager.copyBufferToStorage(storageData, platformIdents, processors, false);
verify(storageDataDao, times(1)).getAllDefaultDataForAgent(eq(platformId), Matchers.<Date> any(), Matchers.<Date> any());
verify(storageManager, times(1)).writeToStorage(storageData, data, processors, true);
storageManager.copyBufferToStorage(storageData, platformIdents, processors, true);
verify(storageDataDao, times(2)).getAllDefaultDataForAgent(eq(platformId), Matchers.<Date> any(), Matchers.<Date> any());
verify(storageManager, times(2)).writeToStorage(storageData, data, processors, true);
assertThat(storageManager.isStorageClosed(storageData), is(true));
}