remove use of Guava @VisibleForTesting on all package-private members

From now on we will only use this annotation on `public` or `protected` members.
This commit is contained in:
Sean Gilligan 2023-09-15 15:39:21 -07:00 committed by Andreas Schildbach
parent 57b3649e55
commit daa4da8d9f
6 changed files with 21 additions and 25 deletions

View file

@ -128,7 +128,7 @@ public class Block extends BaseMessage {
private long nonce; private long nonce;
// If null, it means this object holds only the headers. // If null, it means this object holds only the headers.
@VisibleForTesting // For testing only
@Nullable List<Transaction> transactions; @Nullable List<Transaction> transactions;
/** Stores the hash of the block. If null, getHash() will recalculate it. */ /** Stores the hash of the block. If null, getHash() will recalculate it. */
@ -180,7 +180,7 @@ public class Block extends BaseMessage {
} }
/** Special case constructor, used for unit tests. */ /** Special case constructor, used for unit tests. */
@VisibleForTesting // For testing only
Block(long setVersion) { Block(long setVersion) {
// Set up a few basic things. We are not complete after this though. // Set up a few basic things. We are not complete after this though.
this(setVersion, this(setVersion,
@ -191,7 +191,7 @@ public class Block extends BaseMessage {
} }
// For unit-test genesis blocks // For unit-test genesis blocks
@VisibleForTesting // For testing only
Block(long setVersion, Instant time, long difficultyTarget, List<Transaction> transactions) { Block(long setVersion, Instant time, long difficultyTarget, List<Transaction> transactions) {
this(setVersion, time, difficultyTarget, 0, transactions); this(setVersion, time, difficultyTarget, 0, transactions);
// Solve for nonce? // Solve for nonce?
@ -522,7 +522,7 @@ public class Block extends BaseMessage {
} }
} }
@VisibleForTesting // For testing only
void checkWitnessRoot() throws VerificationException { void checkWitnessRoot() throws VerificationException {
Transaction coinbase = transactions.get(0); Transaction coinbase = transactions.get(0);
checkState(coinbase.isCoinBase()); checkState(coinbase.isCoinBase());
@ -666,7 +666,7 @@ public class Block extends BaseMessage {
} }
/** Exists only for unit testing. */ /** Exists only for unit testing. */
@VisibleForTesting // For testing only
void setMerkleRoot(Sha256Hash value) { void setMerkleRoot(Sha256Hash value) {
unCacheHeader(); unCacheHeader();
merkleRoot = value; merkleRoot = value;
@ -715,7 +715,7 @@ public class Block extends BaseMessage {
return prevBlockHash; return prevBlockHash;
} }
@VisibleForTesting // For testing only
void setPrevBlockHash(Sha256Hash prevBlockHash) { void setPrevBlockHash(Sha256Hash prevBlockHash) {
unCacheHeader(); unCacheHeader();
this.prevBlockHash = prevBlockHash; this.prevBlockHash = prevBlockHash;
@ -748,7 +748,7 @@ public class Block extends BaseMessage {
return Date.from(time()); return Date.from(time());
} }
@VisibleForTesting // For testing only
void setTime(Instant time) { void setTime(Instant time) {
unCacheHeader(); unCacheHeader();
this.time = time.truncatedTo(ChronoUnit.SECONDS); // convert to Bitcoin time this.time = time.truncatedTo(ChronoUnit.SECONDS); // convert to Bitcoin time
@ -769,7 +769,7 @@ public class Block extends BaseMessage {
} }
/** Sets the difficulty target in compact form. */ /** Sets the difficulty target in compact form. */
@VisibleForTesting // For testing only
void setDifficultyTarget(long compactForm) { void setDifficultyTarget(long compactForm) {
unCacheHeader(); unCacheHeader();
this.difficultyTarget = compactForm; this.difficultyTarget = compactForm;
@ -785,7 +785,7 @@ public class Block extends BaseMessage {
} }
/** Sets the nonce and clears any cached data. */ /** Sets the nonce and clears any cached data. */
@VisibleForTesting // For testing only
void setNonce(long nonce) { void setNonce(long nonce) {
unCacheHeader(); unCacheHeader();
this.nonce = nonce; this.nonce = nonce;
@ -808,7 +808,7 @@ public class Block extends BaseMessage {
* *
* @param height block height, if known, or -1 otherwise. * @param height block height, if known, or -1 otherwise.
*/ */
@VisibleForTesting // For testing only
void addCoinbaseTransaction(byte[] pubKeyTo, Coin value, final int height) { void addCoinbaseTransaction(byte[] pubKeyTo, Coin value, final int height) {
unCacheTransactions(); unCacheTransactions();
transactions = new ArrayList<>(); transactions = new ArrayList<>();
@ -864,7 +864,7 @@ public class Block extends BaseMessage {
* @param height block height if known, or -1 otherwise * @param height block height if known, or -1 otherwise
* @return created block * @return created block
*/ */
@VisibleForTesting // For testing only
Block createNextBlock(@Nullable Address to, long version, @Nullable TransactionOutPoint prevOut, Instant time, Block createNextBlock(@Nullable Address to, long version, @Nullable TransactionOutPoint prevOut, Instant time,
byte[] pubKey, Coin coinbaseValue, int height) { byte[] pubKey, Coin coinbaseValue, int height) {
Block b = new Block(version); Block b = new Block(version);
@ -974,7 +974,7 @@ public class Block extends BaseMessage {
* @param height block height if known, or -1 otherwise * @param height block height if known, or -1 otherwise
* @return created block * @return created block
*/ */
@VisibleForTesting // For testing only
Block createNextBlockWithCoinbase(long version, byte[] pubKey, int height) { Block createNextBlockWithCoinbase(long version, byte[] pubKey, int height) {
return createNextBlock(null, version, (TransactionOutPoint) null, TimeUtils.currentTime(), pubKey, return createNextBlock(null, version, (TransactionOutPoint) null, TimeUtils.currentTime(), pubKey,
FIFTY_COINS, height); FIFTY_COINS, height);

View file

@ -17,7 +17,6 @@
package org.bitcoinj.core; package org.bitcoinj.core;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
@ -427,7 +426,7 @@ public class PeerGroup implements TransactionBroadcaster {
* @param chain used to process blocks * @param chain used to process blocks
* @param connectionManager used to create new connections and keep track of existing ones. * @param connectionManager used to create new connections and keep track of existing ones.
*/ */
@VisibleForTesting // For testing only
protected PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) { protected PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
Objects.requireNonNull(params); Objects.requireNonNull(params);
Context.getOrCreate(); // create a context for convenience Context.getOrCreate(); // create a context for convenience
@ -1109,7 +1108,7 @@ public class PeerGroup implements TransactionBroadcaster {
return addressList.size(); return addressList.size();
} }
@VisibleForTesting // For testing only
void waitForJobQueue() { void waitForJobQueue() {
Futures.getUnchecked(executor.submit(Runnables.doNothing())); Futures.getUnchecked(executor.submit(Runnables.doNothing()));
} }
@ -2013,7 +2012,7 @@ public class PeerGroup implements TransactionBroadcaster {
} }
@Nullable private ChainDownloadSpeedCalculator chainDownloadSpeedCalculator; @Nullable private ChainDownloadSpeedCalculator chainDownloadSpeedCalculator;
@VisibleForTesting // For testing only
void startBlockChainDownloadFromPeer(Peer peer) { void startBlockChainDownloadFromPeer(Peer peer) {
lock.lock(); lock.lock();
try { try {

View file

@ -17,7 +17,6 @@
package org.bitcoinj.core; package org.bitcoinj.core;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import org.bitcoinj.base.Sha256Hash; import org.bitcoinj.base.Sha256Hash;
import org.bitcoinj.base.internal.TimeUtils; import org.bitcoinj.base.internal.TimeUtils;
@ -72,7 +71,7 @@ import static org.bitcoinj.base.internal.Preconditions.checkState;
* To make a copy that won't be changed, use {@link TransactionConfidence#duplicate()}. * To make a copy that won't be changed, use {@link TransactionConfidence#duplicate()}.
*/ */
public class TransactionConfidence { public class TransactionConfidence {
@VisibleForTesting // For testing only
interface Factory { interface Factory {
TransactionConfidence createConfidence(Sha256Hash hash); TransactionConfidence createConfidence(Sha256Hash hash);
} }

View file

@ -17,7 +17,6 @@
package org.bitcoinj.crypto; package org.bitcoinj.crypto;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import org.bitcoinj.base.Network; import org.bitcoinj.base.Network;
import org.bitcoinj.base.ScriptType; import org.bitcoinj.base.ScriptType;
@ -483,7 +482,7 @@ public class DeterministicKey extends ECKey {
return key; return key;
} }
@VisibleForTesting // For testing only
byte[] serialize(Network network, boolean pub) { byte[] serialize(Network network, boolean pub) {
return serialize(network, pub, ScriptType.P2PKH); return serialize(network, pub, ScriptType.P2PKH);
} }
@ -491,7 +490,6 @@ public class DeterministicKey extends ECKey {
/** /**
* @deprecated Use {@link #serialize(Network, boolean)} * @deprecated Use {@link #serialize(Network, boolean)}
*/ */
@VisibleForTesting
@Deprecated @Deprecated
byte[] serialize(NetworkParameters params, boolean pub) { byte[] serialize(NetworkParameters params, boolean pub) {
return serialize(params.network(), pub); return serialize(params.network(), pub);

View file

@ -16,7 +16,6 @@
package org.bitcoinj.net; package org.bitcoinj.net;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.util.concurrent.AbstractExecutionThreadService; import com.google.common.util.concurrent.AbstractExecutionThreadService;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -41,7 +40,8 @@ public class NioServer extends AbstractExecutionThreadService {
private final StreamConnectionFactory connectionFactory; private final StreamConnectionFactory connectionFactory;
private final ServerSocketChannel sc; private final ServerSocketChannel sc;
@VisibleForTesting final Selector selector; // For testing only
final Selector selector;
// Handle a SelectionKey which was selected // Handle a SelectionKey which was selected
private void handleKey(Selector selector, SelectionKey key) throws IOException { private void handleKey(Selector selector, SelectionKey key) throws IOException {

View file

@ -2020,7 +2020,7 @@ public class Wallet extends BaseTaggableObject
* If isSpent - check that all my outputs spent, otherwise check that there at least * If isSpent - check that all my outputs spent, otherwise check that there at least
* one unspent. * one unspent.
*/ */
@VisibleForTesting // For testing only
boolean isTxConsistent(final Transaction tx, final boolean isSpent) { boolean isTxConsistent(final Transaction tx, final boolean isSpent) {
boolean isActuallySpent = true; boolean isActuallySpent = true;
for (TransactionOutput o : tx.getOutputs()) { for (TransactionOutput o : tx.getOutputs()) {
@ -4694,7 +4694,7 @@ public class Wallet extends BaseTaggableObject
* @param inputs a list of possibly unconnected/unvalued inputs (e.g. from a spend request) * @param inputs a list of possibly unconnected/unvalued inputs (e.g. from a spend request)
* @return a list of the same inputs, but connected/valued if not previously valued and found in wallet * @return a list of the same inputs, but connected/valued if not previously valued and found in wallet
*/ */
@VisibleForTesting // For testing only
static List<TransactionInput> connectInputs(List<TransactionOutput> candidates, List<TransactionInput> inputs) { static List<TransactionInput> connectInputs(List<TransactionOutput> candidates, List<TransactionInput> inputs) {
return inputs.stream() return inputs.stream()
.map(in -> candidates.stream() .map(in -> candidates.stream()