Отладить частичный макет в JMockit

Можно ли с помощью JMockit 0.999.4 и JDK6 выполнить отладку в частично имитируемый класс?

Рассмотрим следующий тест:

@Test
public void testClass() {
    SampleClass cls = new SampleClass();

    System.out.println(cls.getStaticInt());
    cls.setVal(25);
    System.out.println(cls.getVal());
}

static class SampleClass {
    static int staticInt = 5;
    private int val;

    {
        staticInt = 10;
    }

    public int getStaticInt() {
        System.out.println("Returning static int and adding a line for debugging");
        return staticInt; 
    }

    public void setVal(int num) {
        System.out.println("Setting val and adding a line for debugging");
        this.val = num;
    }

    public int getVal() {
        System.out.println("Returning val and adding a line for debugging");
        return this.val;
    }
}

Размещение точки останова на каждой из строк sysout в SampleClass и отладка " Step Over "в Eclipse будет вводить методы SampleClass.

Примите во внимание следующее, что предотвратит установку статическим инициализатором staticInt значения 10.

@Test
public void testClass(@Mocked(methods = "$clinit") SampleClass cls) {       

    System.out.println(cls.getStaticInt());
    cls.setVal(25);
    System.out.println(cls.getVal());
}

static class SampleClass {
    static int staticInt = 5;
    private int val;

    {
        staticInt = 10;
    }

    public int getStaticInt() {
        System.out.println("Returning static int and adding a line for debugging");
        return staticInt; 
    }

    public void setVal(int num) {
        System.out.println("Setting val and adding a line for debugging");
        this.val = num;
    }

    public int getVal() {
        System.out.println("Returning val and adding a line for debugging");
        return this.val;
    }
}

Однако этот код не будет отлаживать методы в SampleClass.

] Да, я пробовал свойство -javaagent.

5
задан ctran 27 January 2011 в 16:48
поделиться