[BAEL-2959] A Guide to MapDB code (#7042)
* [BAEL-2959] A Guide to MapDB code * [BAEL-2959] fixes * [BAEL-2959] made VOLUME_LOCATION static in SortedTableMapUnitTest * moved mapdb files from libraries to libraries-2 * [BAEL-2959] formatting fixes * updated pom.xml
This commit is contained in:
committed by
ashleyfrieze
parent
e82221416d
commit
7c4019e384
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.mapdb;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
import org.mapdb.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
public class HTreeMapUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenValidDB_whenHTreeMapAddedToAndRetrieved_CheckedRetrievalCorrect() {
|
||||
|
||||
DB db = DBMaker.memoryDB().make();
|
||||
|
||||
HTreeMap<String, String> hTreeMap = db
|
||||
.hashMap("myTreMap")
|
||||
.keySerializer(Serializer.STRING)
|
||||
.valueSerializer(Serializer.STRING)
|
||||
.create();
|
||||
|
||||
hTreeMap.put("key1", "value1");
|
||||
hTreeMap.put("key2", "value2");
|
||||
|
||||
assertEquals(2, hTreeMap.size());
|
||||
|
||||
//add another value with the same key
|
||||
|
||||
hTreeMap.put("key1", "value3");
|
||||
|
||||
assertEquals(2, hTreeMap.size());
|
||||
assertEquals("value3", hTreeMap.get("key1"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user