forked from I2P_Developers/i2p.i2p
fix junit deprecations, issue #339
This commit is contained in:
@@ -10,9 +10,7 @@ package net.i2p.data.i2np;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataFormatException;
|
||||
@@ -30,9 +28,6 @@ import net.i2p.util.Clock;
|
||||
*/
|
||||
public class DatabaseStoreMessageTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
DSMStructure msg = new DSMStructure(I2PAppContext.getGlobalContext());
|
||||
RouterInfo info = (RouterInfo)new RouterInfoTest().createDataStructure();
|
||||
@@ -41,16 +36,18 @@ public class DatabaseStoreMessageTest extends StructureTest {
|
||||
msg.setEntry(info);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public DataStructure createStructureToRead() {
|
||||
return new DSMStructure(I2PAppContext.getGlobalContext());
|
||||
|
||||
public DataStructure createStructureToRead() {
|
||||
return new DSMStructure(I2PAppContext.getGlobalContext());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testStructure() throws Exception {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
super.testStructure();
|
||||
try {
|
||||
super.testStructure();
|
||||
fail("no exception thrown");
|
||||
} catch (UnsupportedOperationException expected) {}
|
||||
}
|
||||
|
||||
private static class DSMStructure extends DatabaseStoreMessage implements DataStructure {
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
package net.i2p.data.router;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataStructure;
|
||||
@@ -29,16 +27,13 @@ import net.i2p.util.OrderedProperties;
|
||||
*/
|
||||
public class RouterAddressTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
|
||||
OrderedProperties options = new OrderedProperties();
|
||||
options.setProperty("hostname", "localhost");
|
||||
options.setProperty("portnum", "1234");
|
||||
RouterAddress addr = new RouterAddress("Blah", options, 42);
|
||||
return addr;
|
||||
return addr;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new RouterAddress(); }
|
||||
|
||||
@@ -47,8 +42,10 @@ public class RouterAddressTest extends StructureTest {
|
||||
public void testSetNullOptions(){
|
||||
RouterAddress addr = new RouterAddress();
|
||||
|
||||
exception.expect(NullPointerException.class);
|
||||
addr.setOptions(null);
|
||||
try {
|
||||
addr.setOptions(null);
|
||||
fail("no exception thrown");
|
||||
} catch (NullPointerException expected) {}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -60,17 +57,22 @@ public class RouterAddressTest extends StructureTest {
|
||||
RouterAddress addr = new RouterAddress("Blah", options, 42);
|
||||
options.setProperty("portnum", "2345");
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
addr.setOptions(options);
|
||||
try {
|
||||
addr.setOptions(options);
|
||||
fail("no exception thrown");
|
||||
} catch (IllegalStateException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadWrite() throws Exception{
|
||||
RouterAddress addr = new RouterAddress();
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("uninitialized");
|
||||
addr.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
addr.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("uninitialized", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.i2p.data.router;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
@@ -12,9 +12,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import net.i2p.data.Certificate;
|
||||
import net.i2p.data.CertificateTest;
|
||||
@@ -33,9 +31,6 @@ import net.i2p.data.StructureTest;
|
||||
*/
|
||||
public class RouterIdentityTest extends StructureTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
RouterIdentity ident = new RouterIdentity();
|
||||
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
|
||||
@@ -57,9 +52,12 @@ public class RouterIdentityTest extends StructureTest {
|
||||
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
|
||||
ident.setSigningPublicKey(k);
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Not enough data to format the router identity");
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Not enough data to format the router identity", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,9 +69,12 @@ public class RouterIdentityTest extends StructureTest {
|
||||
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
|
||||
ident.setSigningPublicKey(k);
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Not enough data to format the router identity");
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Not enough data to format the router identity", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,9 +86,12 @@ public class RouterIdentityTest extends StructureTest {
|
||||
ident.setPublicKey(pk);
|
||||
ident.setSigningPublicKey(null);
|
||||
|
||||
exception.expect(DataFormatException.class);
|
||||
exception.expectMessage("Not enough data to format the router identity");
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
try {
|
||||
ident.writeBytes(new ByteArrayOutputStream());
|
||||
fail("no exception thrown");
|
||||
} catch (DataFormatException expected) {
|
||||
assertEquals("Not enough data to format the router identity", expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,8 +121,11 @@ public class RouterIdentityTest extends StructureTest {
|
||||
public void testBadHash() throws Exception {
|
||||
RouterIdentity ident = new RouterIdentity();
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectMessage("KAC hash error");
|
||||
ident.getHash();
|
||||
try {
|
||||
ident.getHash();
|
||||
fail("no exception thrown");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertEquals("KAC hash error", expected.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user