MeFactory { public User createMe() { final int code = createUniqueCode(); final String nickName = createNickName(code); final User me = new User(nickName, code); me.setMe(true); me.setLastIdle(System.currentTimeMillis()); me.setLogonTime(System.currentTimeMillis()); me.setOperatingSystem(System.getProperty("os.name")); return me; }  User createMe();  }
@Test public void createMeShouldSetUserAsMe() { final User me = meFactory.createMe(); assertTrue(me.isMe()); }
@Test public void createMeShouldSetOperatingSystemFromSystemProperty() { System.setProperty("os.name", "Wintendo"); final User me = meFactory.createMe(); assertEquals("Wintendo", me.getOperatingSystem()); }
@Test public void createMeShouldSetNickNameWithCapitalFirstLetterFromUserNameInSystemProperty() { System.setProperty("user.name", "superman"); final User me = meFactory.createMe(); assertEquals("Superman", me.getNick()); }
@Test public void createMeShouldSetNickNameToFirstTenLettersOfUserName() { System.setProperty("user.name", "theAmazingSpiderman"); final User me = meFactory.createMe(); assertEquals("TheAmazing", me.getNick()); }
@Test public void createMeShouldSetNickNameToFirstWordInUserName() { System.setProperty("user.name", "super kou"); final User me = meFactory.createMe(); assertEquals("Super", me.getNick()); }
@Test public void createMeShouldSetNickNameToFirstTenLettersOfFirstWordInUserName() { System.setProperty("user.name", "ultrasuperduper kou"); final User me = meFactory.createMe(); assertEquals("Ultrasuper", me.getNick()); }
@Test public void createMeShouldSetNickNameToCodeIfUserNameIsMissing() { System.clearProperty("user.name"); final User me = meFactory.createMe(); assertEquals(String.valueOf(me.getCode()), me.getNick()); }
@Test public void createMeShouldSetNickNameToCodeIfUserNameIsInvalid() { System.setProperty("user.name", "kou$"); final User me = meFactory.createMe(); assertEquals(String.valueOf(me.getCode()), me.getNick()); }
@Test public void createMeShouldUseUniqueCodes() { final List<Integer> uniqueCodes = new ArrayList<>(); for (int i = 0; i < 100; i++) { final User me = meFactory.createMe(); final int code = me.getCode(); assertFalse(uniqueCodes.contains(code)); assertTrue(code >= 10000000); assertTrue(code <= 20000000); uniqueCodes.add(code); } assertEquals(100, uniqueCodes.size()); }
@Test public void createMeShouldSetLogonTimeToNow() { final User me = meFactory.createMe(); final long timeSinceLogon = System.currentTimeMillis() - me.getLogonTime(); assertTrue(timeSinceLogon >= 0); assertTrue(timeSinceLogon < 1000); }
@Test public void createMeShouldSetLastIdleToNow() { final User me = meFactory.createMe(); final long timeSinceLastIdle = System.currentTimeMillis() - me.getLastIdle(); assertTrue(timeSinceLastIdle >= 0); assertTrue(timeSinceLastIdle < 1000); }