package org.multiverse.collections; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.multiverse.api.Stm; import org.multiverse.api.StmUtils; import org.multiverse.api.Txn; import org.multiverse.api.callables.TxnVoidCallable; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.multiverse.api.GlobalStmInstance.getGlobalStmInstance; import static org.multiverse.api.StmUtils.atomic; import static org.multiverse.api.TxnThreadLocal.clearThreadLocalTxn; public class NaiveTxnLinkedList_offerTest { private Stm stm; @Before public void setUp() { stm = getGlobalStmInstance(); clearThreadLocalTxn(); } @Test public void whenNullItem_thenNullPointerException() { final NaiveTxnLinkedList<String> list = new NaiveTxnLinkedList<String>(stm); atomic(new TxnVoidCallable() { @Override public void call(Txn tx) throws Exception { try { list.offer(null); fail(); } catch (NullPointerException expected) { } assertEquals("[]", list.toString()); assertEquals(0, list.size()); } }); } @Test public void whenEmpty() { final NaiveTxnLinkedList<String> list = new NaiveTxnLinkedList<String>(stm); atomic(new TxnVoidCallable() { @Override public void call(Txn tx) throws Exception { boolean result = list.offer("1"); assertTrue(result); assertEquals("[1]", list.toString()); assertEquals(1, list.size()); } }); } @Test public void whenNotEmpty() { final NaiveTxnLinkedList<String> list = new NaiveTxnLinkedList<String>(stm); StmUtils.atomic(new TxnVoidCallable() { @Override public void call(Txn tx) throws Exception { list.offer("1"); boolean result = list.offer("2"); assertTrue(result); assertEquals("[1, 2]", list.toString()); assertEquals(2, list.size()); } }); } @Test @Ignore public void whenFull() { } }