Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alxhotel committed Feb 2, 2018
1 parent 492ee88 commit 773799c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -36,7 +40,7 @@ public void setUp() {
@Test
public void testUpdate_EmptyUpdate() {
List<Block> updateList = new ArrayList<>();
this.chain.update(updateList, localstoreMock);
this.chain.update(updateList, localStore);

assertTrue(this.chain.getBlocks().isEmpty());
}
Expand All @@ -47,23 +51,23 @@ public void testUpdate_EmptyUpdate() {
@Test
public void testUpdate_EmptyChain() {
List<Block> 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<Block> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -328,6 +325,7 @@ public void testListIteratorHasNext() {
addBlock(0, true);
addBlock(1, false);
addBlock(2, false);
chainview.isValid();

ListIterator<Block> it = chainview.listIterator(0);
assertTrue(it.hasNext());
Expand All @@ -344,6 +342,7 @@ public void testListIteratorHasNext_FromChainToUpdate() {
addBlock(0, true);
addBlock(1, false);
addBlock(2, false);
chainview.isValid();

ListIterator<Block> it = chainview.listIterator(1);
it.next(); // Get 1
Expand All @@ -357,6 +356,7 @@ public void testListIteratorHasNext_FromChainToUpdate() {
public void testListIteratorHasPrevious() {
addBlock(0, true);
addBlock(1, false);
chainview.isValid();

ListIterator<Block> it = chainview.listIterator(0);
assertFalse(it.hasPrevious());
Expand All @@ -372,6 +372,7 @@ public void testListIteratorHasPrevious() {
@Test
public void testListIteratorOneBlock() {
addBlock(0, false);
chainview.isValid();

ListIterator<Block> it = chainview.listIterator(1);
assertFalse(it.hasNext());
Expand All @@ -385,6 +386,7 @@ public void testResetValidation() {
addBlock(0, true);
addBlock(1, true);
addBlock(2, false);
chainview.isValid();

// Is valid
assertTrue(this.chainview.isValid());
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

0 comments on commit 773799c

Please sign in to comment.