Search code examples
javaunit-testingjunitjunit5

Junit Test of Getters. How can I write it


I have a class:

public final class Core {
    private final Deque<Double> stack = new ArrayDeque<>();
    private final HashMap<String, Double> values = new HashMap<>();

    public Deque<Double> getStack() {
        return stack;
    }

    public HashMap<String, Double> getValues() {
        return values;
    }
}

I need a Junit test for this getters, but I don't know how to write it correctly


Solution

  • You get each property and add something to their collection

    Then get each property again and verify that what you added is still there