### Question:
ReflectionHelper { @SuppressWarnings("unchecked") public static void setStateFactory(Component component, String stateName, StateFactory stateFactory) { try { Set<Field> fields = getAllFields(component.getClass(), withState(stateName)); if (fields != null && !fields.isEmpty()) { Field field = fields.iterator().next(); writeField(field, component, stateFactory, true); } } catch (Exception e) { throw new IllegalArgumentException("Unable to set StateFactory for " + stateName, e); } }  @SuppressWarnings("unchecked") static Map<String, Stream> getOutputStreams(Component component); @SuppressWarnings("unchecked") static Stream getOutputStream(Object obj, String name); @SuppressWarnings("unchecked") static List<String> getInputStreamNames(Class<? extends Component> componentClazz); static void setProperties(Object obj, List<PropertyConfiguration> properties); static void setInputStreams(Component component, Map<String, Stream> inputStreams); @SuppressWarnings("unchecked") static void setTopology(Component component, TridentTopology topology); @SuppressWarnings("unchecked") static void setConfiguration(Component component, Config config); @SuppressWarnings("unchecked") static void setFeaturesMapper(Component component, String streamName, NamedFeaturesMapper mapper); @SuppressWarnings("unchecked") static void setFeaturesMapper(Component component, String streamName, ListedFeaturesMapper mapper); @SuppressWarnings("unchecked") static void setStateFactory(Component component, String stateName, StateFactory stateFactory); @SuppressWarnings("unchecked") static void setInputStream(Component component, String name, Stream stream); @SuppressWarnings("unchecked") static NameMapper getNameMapper(Class<?> clazz, String stream); @SuppressWarnings("unchecked") static ListMapper getListMapper(Class<?> clazz, String stream); @SuppressWarnings({ "unchecked", "rawtypes" }) static Object getEnumValue(Class<?> clazz, String name);  }### Answer:
@Test public void should_set_state_factory() { class TestComponent implements Component { @State(name = "Word count") private StateFactory stateFactory; @Override public void init() { } } TestComponent component = new TestComponent(); StateFactory stateFactory = mock(StateFactory.class); ReflectionHelper.setStateFactory(component, "Word count", stateFactory); assertThat(component.stateFactory).isEqualTo(stateFactory); }