org.powermock.reflect.exceptions.FieldNotFoundException: No instance field named XXX could be found in the class hierarchy #773

Closed
hazems opened this Issue Apr 4, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@hazems

hazems commented Apr 4, 2017

After upgrading to powerMock Version 1.7.0RC2 in order to work with mockito 2.1, some of the old tests which were using org.powermock.reflect.Whitebox's getInternalState() API failed because the API fails to find a private final String in the object.

Sample code

@RunWith(PowerMockRunner.class)
public class SampleTest {
    private MainObject testSubject;
    private String myPreferences;

    @Before
    public void setUp() {
        myPreferences = Whitebox.getInternalState(testSubject, "myPreferences").toString();
    }
	
    // test methods here ...
 }
@thekingnothing

This comment has been minimized.

Show comment
Hide comment
@thekingnothing

thekingnothing Apr 14, 2017

Member

@hazems,

As I understand MainObject has structure like this:


public class MainObject {
// some fields ... 

private final String myPreferences = "bla bla";
 
// some fields ... and methods ... 
}

Am I right?

Member

thekingnothing commented Apr 14, 2017

@hazems,

As I understand MainObject has structure like this:


public class MainObject {
// some fields ... 

private final String myPreferences = "bla bla";
 
// some fields ... and methods ... 
}

Am I right?

@hazems

This comment has been minimized.

Show comment
Hide comment
@hazems

hazems Apr 21, 2017

@thekingnothing I figured out how to make it work, when I just used Whitebox.getInternalState(MainObject.class, "myPreferences"), it works fine, since it was a static final variable.

Thanks a lot for your support, I'm closing this issue now.

hazems commented Apr 21, 2017

@thekingnothing I figured out how to make it work, when I just used Whitebox.getInternalState(MainObject.class, "myPreferences"), it works fine, since it was a static final variable.

Thanks a lot for your support, I'm closing this issue now.

@hazems hazems closed this Apr 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment