super.setUp(); manager = new InMemoryUserManager(null); profile1 = new UserProfile(); profile1.setUsername("myuser1"); profile1.setPassword("mypassword"); manager.addUser(profile1); profile2 = new UserProfile(); profile2.setUsername("myuser2"); profile2.setPassword("zigzag"); profile2.setUserType(UserProfile.USER); manager.addUser(profile2);
super.tearDown();
assertEquals( "verify authentication succeeds", profile1, manager.authenticate("myuser1", "mypassword")); assertNull( "verify authentication fails", manager.authenticate("myuser1", "mypassword_shouldfail"));
ByteArrayOutputStream out = new ByteArrayOutputStream(); manager.save(out); System.out.println("Saved to: " + new String(out.toByteArray())); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); InMemoryUserManager newManager = new InMemoryUserManager(null); newManager.load(in); UserProfile profile3 = new UserProfile(); profile3.setUserType(UserProfile.GUEST); profile3.setUsername("user3"); profile3.setPassword("whatever"); assertTrue( manager.getUsers().contains(profile1 ) ); assertTrue( manager.getUsers().contains(profile2 ) ); assertFalse( manager.getUsers().contains(profile3 ) ); assertTrue( newManager.getUsers().contains(profile1 ) ); assertTrue( newManager.getUsers().contains(profile2 ) ); assertFalse( newManager.getUsers().contains(profile3 ) );