Java IntelliJ 中的 Junit 测试 |您如何编写专门测试 set/get 方法的测试?

问题描述

所以我有这个类和那两个方法

public class RiddleNode {
    public final RiddleType type;
    public final int value; // Zahlenwert,falls Knotentyp == VAL
    public final boolean result; // Endknoten?
    private final RiddleNode[] neighbours = new RiddleNode[4]; // direkte Nachbarknoten
    boolean visited = false;

    public RiddleNode(RiddleType type,int value,boolean result) {
        this.type = type;
        this.value = value;
        this.result = result;
    }

设置方法

   public void setNeighbours(RiddleNode... neighbours) {
            if (neighbours == null) {
                throw new IllegalArgumentException("neighbours must not be null!");
            }
            if (neighbours.length > 4) {
                throw new IllegalArgumentException("Each node must have 2,3 or 4 non-null neighbours - not more!");
            }
            int count = 0;
            for (int i = 0; i < neighbours.length; i++) {
                if (neighbours[i] != null) {
                    count++;
                }
                this.neighbours[i] = neighbours[i];
            }
            if (count < 2) {
                throw new IllegalArgumentException("Each node must have 2,3 or 4 non-null neighbours - not less!");
            }
        }

获取方法

   public RiddleNode[] getNeighbours() {
        return java.util.Arrays.copyOf(neighbours,neighbours.length);
    }

我现在只是想知道如何在另一个类(在我的例子中称为“RiddleTest”)中编写测试这两种方法的测试。因为我什至无法获得 setNeighbours 方法在我的另一个类中具有的参数,或者是否可以在我的另一个类中使用相同的参数?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)