### Question:
FlagManager { public Result flipFlagForUser(String userName, String flagName) { setThreadUserName(userName); Map<FeatureFlags, FlagState> userFlagsState = getOrCreateUser(userName); FeatureFlags flag = getFlag(flagName); FlagState newFlagState = flag.isUp() ? FlagState.DOWN : FlagState.UP; resetThreadUserName(); return setFlagStateToAndPersist(userFlagsState, userName, flag, newFlagState); } private  FlagManager(Class<?> featureFlagsClass); void init(); static FlagManager get(Class<?> featureFlagsClass); static FlagManager get(String className); static FlagManager get(); void initFlags(); FeatureFlags[] getFlags(); Result flipFlag(String flagName); Result flipFlag(FeatureFlags flag); Result setFlagStateTo(String flagName, FlagState newFlagState); Result setFlagStateToAndPersist(String flagName, FlagState newFlagState); Result setFlagStateToAndPersist(FeatureFlags flag, FlagState newFlagState); Result setFlagStateTo(FeatureFlags flag, FlagState newFlagState); boolean isUp(FeatureFlags flag); FeatureFlags getFlag(String flagName); Result flipFlagForUser(String userName, String flagName); Result setFlagStateForUserToAndPersist(String userName, String flagName, FlagState newFlagState); Result setFlagStateForUser(String userName, String flagName, FlagState newFlagState); void resetThreadUserName(); void setThreadUserName(String userName); String getThreadUserName(); String[] getUsersForFlag(FeatureFlags flag); String getFeatureFlagClassName(); String getFlagsStatesAsString(); String getFlagsUsersAsString();  }### Answer:
@Test public void testFlipFlagForUser() { String[] testUsers = new String[] { "bob", "john", "foo", "bar", "bob2", "john2", "foo2", "bar2" }; String[] flagState = new String[] { "UP", "UP", "DOWN", "UP", "UP", "UP", "DOWN", "UP" }; FlagThread[] flagThreads = new FlagThread[8]; for (int i = 0; i < testUsers.length; i++) { flagThreads[i] = new FlagThread(testUsers[i]); manager.setFlagStateForUserToAndPersist(testUsers[i], Flags.ONE.toString(), FlagState.valueOf(flagState[i])); } for (int i = 0; i < testUsers.length; i++) { Thread thread = new Thread(flagThreads[i]); thread.start(); } try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } assertEquals(true, flagThreads[0].isUp()); assertEquals(true, flagThreads[1].isUp()); assertEquals(false, flagThreads[2].isUp()); assertEquals(true, flagThreads[3].isUp()); assertEquals(true, flagThreads[4].isUp()); assertEquals(true, flagThreads[5].isUp()); assertEquals(false, flagThreads[6].isUp()); assertEquals(true, flagThreads[7].isUp()); assertEquals(false, Flags.ONE.isUp()); assertEquals(true, Flags.TWO.isUp()); manager.setFlagStateForUserToAndPersist("other", Flags.TWO.toString(), FlagState.DOWN); assertEquals(true, Flags.TWO.isUp()); manager.setThreadUserName("other"); assertEquals(false, Flags.ONE.isUp()); assertEquals(false, Flags.TWO.isUp()); }