mardi 26 décembre 2017

Java testing if two void methods do the same

I have a class of paired void methods: each method has an equivalent one that should perform the same operation but in a different way. For example:

public void example1_1(){
    Integer i = new Integer(1);
}

public void example1_2(){
    Integer i = Integer.valueOf(11);
}

or

public void example2_1(){
    String result = "hello";
    for (int i = 0; i < 10; i++) {
        result += result;
    }
}

public void example2_2(){
    StringBuffer result = new StringBuffer("hello");
    for(int i = 0; i < 10; i++) {
        result += result;
    }
}

How can I test that the methods actually perform the same operations in pair?

Aucun commentaire:

Enregistrer un commentaire