public final class NodeFake extends java.lang.Object implements Node
try (MemoryDb db = MemoryDb.newInstance();
Cleaner cleaner = new Cleaner()) {
// Setup database to include some test data
Fork fork = db.createFork(cleaner);
MapIndex balance = MapIndexProxy.newInstance("balance", fork, stringSerializer,
stringSerializer);
balance.put("John Doe", "$1000.00");
db.merge(fork);
// Create a node fake from the database
NodeFake node = new NodeFake(db);
WalletController controller = new WalletController(node);
assertThat(controller.getBalance("John Doe"), equalTo("$1000.00"));
}
| Constructor and Description |
|---|
NodeFake(MemoryDb database)
Creates a new node fake with the given database and an empty public key.
|
NodeFake(MemoryDb database,
byte[] publicKey)
Creates a new node fake with the given database.
|
| Modifier and Type | Method and Description |
|---|---|
MemoryDb |
getDatabase()
Returns the underlying database.
|
byte[] |
getPublicKey()
Returns the public key of this node.
|
void |
submitTransaction(Transaction transaction)
A no-op.
|
<ResultT> ResultT |
withSnapshot(java.util.function.Function<Snapshot,ResultT> snapshotFunction)
Performs a given function with a snapshot of the current database state.
|
public NodeFake(MemoryDb database)
database - a database to provide snapshots ofpublic NodeFake(MemoryDb database, byte[] publicKey)
database - a database to provide snapshots ofpublicKey - a public key of the nodepublic void submitTransaction(Transaction transaction)
submitTransaction in interface Nodetransaction - a transaction to sendjava.lang.NullPointerException - if the transaction is nullpublic <ResultT> ResultT withSnapshot(java.util.function.Function<Snapshot,ResultT> snapshotFunction)
NodewithSnapshot in interface NodeResultT - a type the function returnssnapshotFunction - a function to executepublic byte[] getPublicKey()
NodegetPublicKey in interface Nodepublic MemoryDb getDatabase()
Copyright © 2018 Exonum. All rights reserved.