Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
[PAN-2822] AllNodesVisitorTest (#1831)
Browse files Browse the repository at this point in the history
* AllNodesVisitorTest
  • Loading branch information
RatanRSur authored Aug 7, 2019
1 parent 6ef349c commit b93f0fe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public void visit(final ExtensionNode<V> extensionNode) {
@Override
public void visit(final BranchNode<V> branchNode) {
handler.accept(branchNode);
for (byte i = 0; i < BranchNode.RADIX; i++) {
acceptAndUnload(branchNode.child(i));
}
branchNode.getChildren().forEach(this::acceptAndUnload);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.ethereum.trie;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Collections;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class AllNodesVisitorTest {

@Mock private StoredNode<String> storedNode;
@Mock private ExtensionNode<String> extensionNode;
@Mock private BranchNode<String> branchNode;

@Test
public void visitExtension() {
when(extensionNode.getChild()).thenReturn(storedNode);
new AllNodesVisitor<String>(x -> {}).visit(extensionNode);
verify(storedNode).unload();
}

@Test
public void visitBranch() {
when(branchNode.getChildren()).thenReturn(Collections.singletonList(storedNode));
new AllNodesVisitor<String>(x -> {}).visit(branchNode);
verify(storedNode).unload();
}
}

0 comments on commit b93f0fe

Please sign in to comment.