PrefixedChecksummedBytes: remove Cloneable

* Remove the `implements Cloneable` marker
* Remove the `@Override` of `clone()`
* Remove tests of `clone()` for the implementing classes
This commit is contained in:
Sean Gilligan 2022-06-07 17:03:38 -07:00 committed by Andreas Schildbach
parent 6d70c60bca
commit f6b3d82e8d
5 changed files with 1 additions and 74 deletions

View file

@ -40,7 +40,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* keys exported using Bitcoin Core's dumpprivkey command.
* </p>
*/
public abstract class PrefixedChecksummedBytes implements Serializable, Cloneable {
public abstract class PrefixedChecksummedBytes implements Serializable {
protected final transient NetworkParameters params;
protected final byte[] bytes;
@ -69,16 +69,6 @@ public abstract class PrefixedChecksummedBytes implements Serializable, Cloneabl
return this.params.equals(other.params) && Arrays.equals(this.bytes, other.bytes);
}
/**
* This implementation narrows the return type to {@link PrefixedChecksummedBytes}
* and allows subclasses to throw {@link CloneNotSupportedException} even though it
* is never thrown by this implementation.
*/
@Override
public PrefixedChecksummedBytes clone() throws CloneNotSupportedException {
return (PrefixedChecksummedBytes) super.clone();
}
// Java serialization
private void writeObject(ObjectOutputStream out) throws IOException {

View file

@ -56,16 +56,6 @@ public class DumpedPrivateKeyTest {
assertEquals(key, keyCopy);
}
@Test
public void cloning() throws Exception {
DumpedPrivateKey a = new DumpedPrivateKey(MAINNET, new ECKey().getPrivKeyBytes(), true);
// TODO: Consider overriding clone() in DumpedPrivateKey to narrow the type
DumpedPrivateKey b = (DumpedPrivateKey) a.clone();
assertEquals(a, b);
assertNotSame(a, b);
}
@Test
public void roundtripBase58() {
String base58 = "5HtUCLMFWNueqN9unpgX2DzjMg6SDNZyKRb8s3LJgpFg5ubuMrk"; // 32-bytes key

View file

@ -208,30 +208,12 @@ public class LegacyAddressTest {
assertEquals("3N25saC4dT24RphDAwLtD8LUN4E2gZPJke", address.toString());
}
@Test
public void cloning() throws Exception {
LegacyAddress a = LegacyAddress.fromPubKeyHash(TESTNET, HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc"));
LegacyAddress b = a.clone();
assertEquals(a, b);
assertNotSame(a, b);
}
@Test
public void roundtripBase58() {
String base58 = "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL";
assertEquals(base58, LegacyAddress.fromBase58(null, base58).toBase58());
}
@Test
public void comparisonCloneEqualTo() throws Exception {
LegacyAddress a = LegacyAddress.fromBase58(MAINNET, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX");
LegacyAddress b = a.clone();
int result = a.compareTo(b);
assertEquals(0, result);
}
@Test
public void comparisonLessThan() {
LegacyAddress a = LegacyAddress.fromBase58(MAINNET, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX");

View file

@ -71,29 +71,4 @@ public class PrefixedChecksummedBytesTest {
PrefixedChecksummedBytes b = new PrefixedChecksummedBytesToTest(params, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
assertEquals("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL", b.toString());
}
@Test
public void cloning() throws Exception {
expect(params.getAddressHeader()).andReturn(111);
replay(params);
PrefixedChecksummedBytes a = new PrefixedChecksummedBytesToTest(params, HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc"));
PrefixedChecksummedBytes b = a.clone();
assertEquals(a, b);
assertNotSame(a, b);
}
@Test
public void comparisonCloneEqualTo() throws Exception {
expect(params.getAddressHeader()).andReturn(111);
expect(params.getId()).andReturn("org.bitcoin.test").times(2);
replay(params);
PrefixedChecksummedBytes a = new PrefixedChecksummedBytesToTest(params, HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc"));
PrefixedChecksummedBytes b = a.clone();
assertNotSame(a, b);
assertEquals(a, b);
}
}

View file

@ -176,16 +176,6 @@ public class BIP38PrivateKeyTest {
assertEquals(mainKey, mainKeyCopy);
}
@Test
public void cloning() throws Exception {
BIP38PrivateKey a = BIP38PrivateKey.fromBase58(TESTNET, "6PfMmVHn153N3x83Yiy4Nf76dHUkXufe2Adr9Fw5bewrunGNeaw2QCpifb");
// TODO: Consider overriding clone() in BIP38PrivateKey to narrow the type
BIP38PrivateKey b = (BIP38PrivateKey) a.clone();
assertEquals(a, b);
assertNotSame(a, b);
}
@Test
public void roundtripBase58() {
String base58 = "6PfMmVHn153N3x83Yiy4Nf76dHUkXufe2Adr9Fw5bewrunGNeaw2QCpifb";