samedi 2 décembre 2017

How to assure the object of a nested private class in my arrayList is the one I want?

This is my class, how I assure that the method insert() is working correctly?

public class HeapQueue<P extends Comparable<? super P>, V>
    implements PriorityQueue<P, V> {

private final ArrayList<Pair<P, V>> pairs = new ArrayList<>();

private static class Pair<P extends Comparable<? super P>, V>
        implements Comparable<Pair<P, V>> {

    private final P priority;
    private final V value;

    public Pair(P priority, V value) {
        this.priority = priority;
        this.value = value;
    }

    @Override
    public int compareTo(Pair<P, V> o) {
        return priority.compareTo(o.priority);
    }

}

I tried this test, but I can't assure the object Pair<> is correct.

    @Test
public void insertPrioritatAltaTest() {

    HeapQueue hq = new HeapQueue();
    Priority p1 = null;
    try {
        p1 = new Priority("Alta");
    } catch (InvalidInputError iie) {

    }
    int a = 1;

    hq.insert(p1, a);
    assertEquals(hq.size(),1);

}

I tried creating getters to extract the value of Pairs, but Netbeans warnered me that I was passing a private thing through a public API and moreover I wasn't obtaining it. I don't think declaring a public class Pair<> is the correct way to test this. Neither using the method extract() which I haven't tested it yet.

Aucun commentaire:

Enregistrer un commentaire