diff --git a/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/ChainTest.java b/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/ChainTest.java index 0d66333..953cb19 100644 --- a/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/ChainTest.java +++ b/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/ChainTest.java @@ -15,19 +15,23 @@ */ public class ChainTest { + private OwnNode ownNode; + private Node node; private Chain chain; - private LocalStore localstoreMock; + + private LocalStore localStore; /** * Setup method. */ @Before public void setUp() { + this.ownNode = new OwnNode(0); + this.localStore = new LocalStore(this.ownNode, null, null, false); this.node = mock(Node.class); - this.localstoreMock = mock(LocalStore.class); - this.chain = new Chain(node); + this.chain = new Chain(this.node); } /** @@ -36,7 +40,7 @@ public void setUp() { @Test public void testUpdate_EmptyUpdate() { List updateList = new ArrayList<>(); - this.chain.update(updateList, localstoreMock); + this.chain.update(updateList, localStore); assertTrue(this.chain.getBlocks().isEmpty()); } @@ -47,23 +51,23 @@ public void testUpdate_EmptyUpdate() { @Test public void testUpdate_EmptyChain() { List updateList = new ArrayList<>(); - updateList.add(new Block(1, this.node, new ArrayList<>())); - this.chain.update(updateList, localstoreMock); + updateList.add(new Block(0, this.node, new ArrayList<>())); + this.chain.update(updateList, localStore); assertEquals(updateList, this.chain.getBlocks()); } - + /** * Test for {@link Chainw#update()}. */ @Test public void testUpdate_NotEmptyChain() { List updateList = new ArrayList<>(); + updateList.add(new Block(0, this.node, new ArrayList<>())); + this.chain.update(updateList, localStore); updateList.add(new Block(1, this.node, new ArrayList<>())); - this.chain.update(updateList, localstoreMock); updateList.add(new Block(2, this.node, new ArrayList<>())); - updateList.add(new Block(3, this.node, new ArrayList<>())); - this.chain.update(updateList, localstoreMock); + this.chain.update(updateList, localStore); assertEquals(updateList, this.chain.getBlocks()); } diff --git a/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/ChainViewTest.java b/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/ChainViewTest.java index 03042e2..e1e270f 100644 --- a/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/ChainViewTest.java +++ b/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/ChainViewTest.java @@ -197,18 +197,15 @@ public void testGetBlock_UpdatePart() { /** * Test for {@link ChainView#getBlock(int)}. */ - @Test + @Test(expected = IllegalStateException.class) public void testGetBlock_Exception() { addBlock(0, true); addBlock(1, true); addBlock(2, false); addBlock(4, false); - try { - this.chainview.getBlock(4); - fail(); - } catch (IllegalStateException ex) { - // Good - } + chainview.isValid(); + + this.chainview.getBlock(4); } /** @@ -328,6 +325,7 @@ public void testListIteratorHasNext() { addBlock(0, true); addBlock(1, false); addBlock(2, false); + chainview.isValid(); ListIterator it = chainview.listIterator(0); assertTrue(it.hasNext()); @@ -344,6 +342,7 @@ public void testListIteratorHasNext_FromChainToUpdate() { addBlock(0, true); addBlock(1, false); addBlock(2, false); + chainview.isValid(); ListIterator it = chainview.listIterator(1); it.next(); // Get 1 @@ -357,6 +356,7 @@ public void testListIteratorHasNext_FromChainToUpdate() { public void testListIteratorHasPrevious() { addBlock(0, true); addBlock(1, false); + chainview.isValid(); ListIterator it = chainview.listIterator(0); assertFalse(it.hasPrevious()); @@ -372,6 +372,7 @@ public void testListIteratorHasPrevious() { @Test public void testListIteratorOneBlock() { addBlock(0, false); + chainview.isValid(); ListIterator it = chainview.listIterator(1); assertFalse(it.hasNext()); @@ -385,6 +386,7 @@ public void testResetValidation() { addBlock(0, true); addBlock(1, true); addBlock(2, false); + chainview.isValid(); // Is valid assertTrue(this.chainview.isValid()); @@ -405,7 +407,7 @@ public void testResetValidation() { public void testResetIsRedundant_Valid() { addBlock(0, true); addBlock(1, true); - addBlock(1, false); + chainview.isValid(); assertTrue(this.chainview.isRedundant()); } diff --git a/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/NodeTest.java b/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/NodeTest.java index 0bb7e58..c63dcdb 100644 --- a/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/NodeTest.java +++ b/src/test/java/nl/tudelft/blockchain/scaleoutdistributedledger/model/NodeTest.java @@ -23,7 +23,7 @@ public void testUpdateMetaKnowledge() { proof.addBlock(new Block(3, otherNode, new ArrayList<>())); node.updateMetaKnowledge(proof); - assertEquals(3, node.getMetaKnowledge().get(otherNode).intValue()); + assertEquals(3, node.getMetaKnowledge().get(otherNode.getId()).intValue()); } }