破坏的枚举平等(与powermock)

时间:2016-03-23 20:17:06

标签: java testing enums mockito powermock

有了这个枚举:

public enum Testnum {
    A("a"), B("b");

    String x;

    private Testnum(String x) {
        this.x = x;
    }
}

此测试中的assertFalse失败:

import static org.junit.Assert.assertFalse;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor("Testnum")
public class EnumTest {

    @Test
    public void mainSuccess() {
        PowerMockito.mockStatic(Testnum.class);

        assertFalse(Testnum.A == Testnum.B);
    }
}

我知道为什么/如何解决这个问题?

0 个答案:

没有答案