### Question:
MmdIngestionTool extends BasicTool { static void storeDataFile(DataFile dataFile, Storage storage) { final DataFile persistedDatafile = storage.getDatafile(dataFile.getPath()); if (persistedDatafile == null) { storage.store(dataFile); } else { throw new IllegalStateException("Trying to ingest duplicate datafile."); } } private  MmdIngestionTool(); static void main(String[] args);  }### Answer:
@Test public void testStoreDataFile() { final String path = "/path/to/wherever"; final DataFile dataFile = new DataFile(path, new SensorBuilder().name("Firlefanz").build()); when(mockStorage.getDatafile(path)).thenReturn(null); MmdIngestionTool.storeDataFile(dataFile, mockStorage); verify(mockStorage, times(1)).getDatafile(path); verify(mockStorage, times(1)).store(dataFile); verifyNoMoreInteractions(mockStorage); }
@Test public void testStoreDataFile_alreadyInDb() { final String path = "/path/to/wherever"; final DataFile dataFile = new DataFile(path, new SensorBuilder().name("Firlefanz").build()); when(mockStorage.getDatafile(path)).thenReturn(dataFile); try { MmdIngestionTool.storeDataFile(dataFile, mockStorage); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { } verify(mockStorage, times(1)).getDatafile(path); verifyNoMoreInteractions(mockStorage); }