Searched on google about, how to mock a variable in unit testing and seen some suggestions, for my case its not working. my scenario is,
class Keys {
private static Keys sKeys;
private String enKey = null;
static synchronized sKeys getInstance() {
if(sKeys == null) {
sKeys = new Keys();
}
return sKeys;
}
Boolean isLocked() {
if(enKey == null ) {
return true;
}
return false;
}
}
This is the class, i have written. Unit test of the class is below,
@RunWith(MockitoJUnitRunner.class)
public class KeysTest {
@Test
public void isLocked_Test() {
Keys key = Keys.getInstance();
Key.isLocked();
// Here in isLocked function I want to mock the enKey value to other than null
}
}
Here, i want to call isLocked function, and i want to set or mock the enKey variable value to other than null.
How i can do that? Could anyone help me on that?