/* * Copyright (C) 2015 higherfrequencytrading.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ package net.openhft.chronicle.map; import org.junit.Test; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static org.junit.Assert.assertEquals; public class DefaultValueTest { @Test public void test() throws IllegalAccessException, InstantiationException, IOException { File file = Builder.getPersistenceFile(); try { ArrayList defaultValue = new ArrayList(); defaultValue.add(42); try (ChronicleMap> map = ChronicleMapBuilder .of(String.class, (Class>) ((Class) List.class)) .defaultValue(defaultValue).createPersistedTo(file)) { ArrayList using = new ArrayList(); assertEquals(defaultValue, map.acquireUsing("a", using)); assertEquals(1, map.size()); map.put("b", Arrays.asList(1, 2)); assertEquals(Arrays.asList(1, 2), map.acquireUsing("b", using)); } ArrayList using = new ArrayList(); try (ChronicleMap> map = ChronicleMapBuilder .of(String.class, (Class>) ((Class) List.class)) .createPersistedTo(file)) { assertEquals(defaultValue, map.acquireUsing("c", using)); } } finally { file.delete(); } } }