Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java spring set private field in test

Field reader = MyClass.class.getDeclaredField("reader");
reader.setAccessible(true);
MyClass mc = new MyClass();
StringReader stringReader = new StringReader("some string");
BufferedReader readerToSet = new BufferedReader(stringReader);
reader.set(mc, readerToSet);
mc.methodToTest();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #spring #set #private #field #test
ADD COMMENT
Topic
Name
1+6 =