@Test public void testRemoveCalledForCorrectExistentKey() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); test.put(correctKey1, testStoreableValue); assertEquals(testStoreableValue, test.remove(correctKey1)); }
@Test public void testSizeMethod() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); test.put(correctKey1, testStoreableValue); assertEquals(test.size(), 1); test.remove(correctKey1); assertEquals(test.size(), 0); }
@Test public void testSavingEmptyDataFileToDisk() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); test.put(correctKey1, testStoreableValue); test.remove(correctKey1); test.commit(); test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); assertTrue(test.list().isEmpty()); }
@Test public void testWritingNewFileToDiskAndThenReadingIt() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); String[] keyList = {correctKey1, correctKey2}; test.put(keyList[0], testStoreableValue); test.put(keyList[1], testStoreableValue); test.commit(); assertArrayEquals(keyList, test.list().toArray()); }
@Test public void testPutKeysAndThenCallList() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); test.put(correctKey1, testStoreableValue); test.put(correctKey2, testStoreableValue); Set<String> expectedKeySet = new HashSet<>(); expectedKeySet.add(correctKey1); expectedKeySet.add(correctKey2); Set<String> actualKeySet = new HashSet<>(); actualKeySet.addAll(test.list()); assertEquals(expectedKeySet, actualKeySet); }
@Test public void testPutCalledTwiceForSameKey() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); assertEquals(null, test.put(correctKey1, testStoreableValue)); assertEquals(testStoreableValue, test.put(correctKey1, testStoreableValue)); }
@Test(expected = IllegalArgumentException.class) public void testPutThrowsExceptionForCorrectKeyAndNullValue() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); test.put(correctKey1, null); }
@Test(expected = IllegalArgumentException.class) public void testPutThrowsExceptionForKeyNotFromThisDataFile() throws IOException, DatabaseCorruptedException { DataFile test = new DataFile(testDir, new Coordinates(folderIndex, fileIndex), table, provider); test.put(wrongKey, testStoreableValue); }