wujun / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

RunWith(PowerMockRunner.class) does not work with package annotation #410

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.package-info.java // this is for the package annotation
@TestAnnotation(version="1.0")
package com.smin.dummy;

TestAnnotation.java
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PACKAGE)
public @interface TestAnnotation {
  String version();
}

A.java
public class A {
    private static Package myPackage;
    private static TestAnnotation version;

    static {
      myPackage = TestAnnotation.class.getPackage();
      version = myPackage.getAnnotation(TestAnnotation.class);
     }

    public static String getVersion() {
        return version.version();
    }
}
2.
MockA.java

@RunWith(PowerMockRunner.class) //comment out this line to see the difference
@PrepareForTest(A.class)
public class MockA {
@Test
public void test_mocked() throws Throwable {
    String thisVersion = A.getVersion();
}
}

What is the expected output? What do you see instead?
in test_mocked(), thisVersion should be not null, but with 
@RunWith(PowerMockRunner.class), it's null.

What version of the product are you using? On what operating system?
powermock 1.4.12 mockito 1.9.0 junit 4.8.2

Please provide any additional information below.

Original issue reported on code.google.com by kelvin....@gmail.com on 14 Nov 2012 at 10:23

GoogleCodeExporter commented 9 years ago
I also has this problem! :-/

Original comment by ronny.na...@gmail.com on 20 Nov 2014 at 1:53

GoogleCodeExporter commented 9 years ago
The same issue. It happens when I try to use PowerMock to mock some stuff in 
HBase.

Original comment by Ror...@gmail.com on 3 Mar 2015 at 9:30