Changeset 10d5a17


Ignore:
Timestamp:
Dec 2, 2017 8:08:44 PM (3 years ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
a65a498
Parents:
b6298dc
Message:

Migrate net.i2p.data tests in the router to JUnit 4

Location:
router/java/test/junit/net/i2p/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • router/java/test/junit/net/i2p/data/i2np/DatabaseStoreMessageTest.java

    rb6298dc r10d5a17  
    99 */
    1010
     11import static org.junit.Assert.*;
     12
     13import org.junit.Rule;
    1114import org.junit.Test;
     15import org.junit.rules.ExpectedException;
    1216
    1317import net.i2p.I2PAppContext;
     
    2529 */
    2630public class DatabaseStoreMessageTest extends StructureTest {
     31
     32    @Rule
     33    public ExpectedException exception = ExpectedException.none();
     34
    2735    public DataStructure createDataStructure() throws DataFormatException {
    2836        DatabaseStoreMessage msg = new DatabaseStoreMessage(I2PAppContext.getGlobalContext());
     
    4149    @Test
    4250    public void testStructure() throws Exception {
    43         try {
    44             super.testStructure();
    45             fail("should not be supported");
    46         } catch (UnsupportedOperationException expected){}
     51        exception.expect(UnsupportedOperationException.class);
     52        super.testStructure();
    4753    }
    4854}
  • router/java/test/junit/net/i2p/data/router/RouterAddressTest.java

    rb6298dc r10d5a17  
    99 */
    1010 
     11import static org.junit.Assert.*;
     12
    1113import java.io.ByteArrayOutputStream;
    1214import java.util.Properties;
     15
     16import org.junit.Rule;
     17import org.junit.Test;
     18import org.junit.rules.ExpectedException;
    1319
    1420import net.i2p.data.DataFormatException;
     
    2329 */
    2430public class RouterAddressTest extends StructureTest {
     31
     32    @Rule
     33    public ExpectedException exception = ExpectedException.none();
     34
    2535    public DataStructure createDataStructure() throws DataFormatException {
    2636        //addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
     
    3444
    3545    @SuppressWarnings("deprecation")
     46    @Test
    3647    public void testSetNullOptions(){
    3748        RouterAddress addr = new RouterAddress();
    38         boolean error = false;
    39         try{
    40             addr.setOptions(null);
    41         }catch(NullPointerException dfe){
    42             error = true;
    43         }
    44         assertTrue(error);
     49
     50        exception.expect(NullPointerException.class);
     51        addr.setOptions(null);
    4552    }
    4653
    4754    @SuppressWarnings("deprecation")
     55    @Test
    4856    public void testSetOptionsAgain(){
    4957        OrderedProperties options = new OrderedProperties();
     
    5260        RouterAddress addr = new RouterAddress("Blah", options, 42);
    5361        options.setProperty("portnum", "2345");
    54         boolean error = false;
    55         try{
    56             addr.setOptions(options);
    57         }catch(IllegalStateException dfe){
    58             error = true;
    59         }
    60         assertTrue(error);
     62
     63        exception.expect(IllegalStateException.class);
     64        addr.setOptions(options);
    6165    }
    6266
     67    @Test
    6368    public void testBadWrite() throws Exception{
    6469        RouterAddress addr = new RouterAddress();
    65         boolean error = false;
    66         try{
    67             addr.writeBytes(new ByteArrayOutputStream());
    68         }catch(DataFormatException dfe){
    69             error = true;
    70         }
    71         assertTrue(error);
     70
     71        exception.expect(DataFormatException.class);
     72        exception.expectMessage("uninitialized");
     73        addr.writeBytes(new ByteArrayOutputStream());
    7274    }
    7375
     76    @Test
    7477    public void testNullEquals(){
    7578        //addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
     
    8285    }
    8386
     87    @Test
    8488    public void testToString(){
    8589        //addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
  • router/java/test/junit/net/i2p/data/router/RouterIdentityTest.java

    rb6298dc r10d5a17  
    99 */
    1010
     11import static org.junit.Assert.*;
     12
    1113import java.io.ByteArrayOutputStream;
     14
     15import org.junit.Rule;
     16import org.junit.Test;
     17import org.junit.rules.ExpectedException;
    1218
    1319import net.i2p.data.Certificate;
     
    2733 */
    2834public class RouterIdentityTest extends StructureTest {
     35
     36    @Rule
     37    public ExpectedException exception = ExpectedException.none();
     38
    2939    public DataStructure createDataStructure() throws DataFormatException {
    3040        RouterIdentity ident = new RouterIdentity();
     
    3848    }
    3949    public DataStructure createStructureToRead() { return new RouterIdentity(); }
    40    
     50
     51    @Test
    4152    public void testNullCert() throws Exception{
    4253        RouterIdentity ident = new RouterIdentity();
     
    4657        SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
    4758        ident.setSigningPublicKey(k);
    48        
    49         boolean error = false;
    50         try{
    51             ident.writeBytes(new ByteArrayOutputStream());
    52         }catch(DataFormatException dfe){
    53             error = true;
    54         }
    55         assertTrue(error);
     59
     60        exception.expect(DataFormatException.class);
     61        exception.expectMessage("Not enough data to format the router identity");
     62        ident.writeBytes(new ByteArrayOutputStream());
    5663    }
    57    
     64
     65    @Test
    5866    public void testNullPublicKey() throws Exception{
    5967        RouterIdentity ident = new RouterIdentity();
     
    6371        SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
    6472        ident.setSigningPublicKey(k);
    65        
    66         boolean error = false;
    67         try{
    68             ident.writeBytes(new ByteArrayOutputStream());
    69         }catch(DataFormatException dfe){
    70             error = true;
    71         }
    72         assertTrue(error);
    73        
     73
     74        exception.expect(DataFormatException.class);
     75        exception.expectMessage("Not enough data to format the router identity");
     76        ident.writeBytes(new ByteArrayOutputStream());
    7477    }
    75    
     78
     79    @Test
    7680    public void testNullSigningKey() throws Exception{
    7781        RouterIdentity ident = new RouterIdentity();
     
    8185        ident.setPublicKey(pk);
    8286        ident.setSigningPublicKey(null);
    83        
    84         boolean error = false;
    85         try{
    86             ident.writeBytes(new ByteArrayOutputStream());
    87         }catch(DataFormatException dfe){
    88             error = true;
    89         }
    90         assertTrue(error);
     87
     88        exception.expect(DataFormatException.class);
     89        exception.expectMessage("Not enough data to format the router identity");
     90        ident.writeBytes(new ByteArrayOutputStream());
    9191    }
    92    
     92
     93    @Test
    9394    public void testNullEquals() throws Exception{
    9495        RouterIdentity ident = new RouterIdentity();
    9596        assertFalse(ident.equals(null));
    9697    }
    97    
     98
     99    @Test
    98100    public void testCalculatedHash() throws Exception{
    99101        RouterIdentity ident = new RouterIdentity();
     
    104106        SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
    105107        ident.setSigningPublicKey(k);
    106        
     108
    107109        ident.calculateHash();
    108110        ident.calculateHash();
     
    111113        ident.calculateHash();
    112114    }
    113    
     115
     116    @Test
    114117    public void testBadHash() throws Exception {
    115118        RouterIdentity ident = new RouterIdentity();
    116         boolean error = false;
    117         try {
    118             ident.getHash();
    119         } catch (IllegalStateException ise) {
    120             error = true;
    121         }
    122         assertTrue(error);
     119
     120        exception.expect(IllegalStateException.class);
     121        exception.expectMessage("KAC hash error");
     122        ident.getHash();
    123123    }
    124    
    125    
    126124}
Note: See TracChangeset for help on using the changeset viewer.