here I am going to set value for "android.os.Build.VERSION.RELEASE", where VERSION is the class name and RELEASE is the final static string value.
If the underlying field is final, the method throws an
IllegalAccessException unless setAccessible(true) has succeeded for
this field and this field is non-static, NoSuchFieldException needs to be added when you use field.set() method
@RunWith(PowerMockRunner.class)
@PrepareForTest({Build.VERSION.class})
public class RuntimePermissionUtilsTest {
@Test
public void hasStoragePermissions() throws IllegalAccessException, NoSuchFieldException {
Field field = Build.VERSION.class.getField("RELEASE");
field.setAccessible(true);
field.set(null,"Marshmallow");
}
}
now the value of String RELEASE will return "Marshmallow".