I have a private static final int LIMIT = 1000
in my Spring Service.
I am trying to override the value of LIMIT in my test case using reflection and all but its not working. I am doing integration test so can't use Mockito or Mock.
Field maxFetchAllowed Manager.getClass().getDeclaredField("LIMIT");
maxFetchAllowed.setAccessible(true);
int modifiers = maxFetchAllowed.getModifiers();
Field modifierField = maxFetchAllowed.getClass().getDeclaredField("modifiers");
modifiers = modifiers & ~Modifier.FINAL;
modifierField.setAccessible(true);
modifierField.setInt(maxFetchAllowed, modifiers);
maxFetchAllowed.set(null, 100); //set the value correctly
System.out.println(maxFetchAllowed.get(null)); // shows 100
but when I call the create method to test, it still has 1000 in it
manager.create() // still has 1000