### Question:
XMLUserDatabase extends AbstractUserDatabase { @Override public synchronized void rename( final String loginName, final String newName) throws NoSuchPrincipalException, DuplicateUserException, WikiSecurityException { if( c_dom == null ) { log.fatal( "Could not rename profile '" + loginName + "'; database does not exist" ); throw new IllegalStateException( "FATAL: database does not exist" ); } checkForRefresh(); final UserProfile profile = findByLoginName( loginName ); try { final UserProfile otherProfile = findByLoginName( newName ); if( otherProfile != null ) { throw new DuplicateUserException( "security.error.cannot.rename", newName ); } } catch( final NoSuchPrincipalException e ) { } final NodeList users = c_dom.getElementsByTagName( USER_TAG ); for( int i = 0; i < users.getLength(); i++ ) { final Element user = ( Element )users.item( i ); if( user.getAttribute( LOGIN_NAME ).equals( loginName ) ) { final DateFormat c_format = new SimpleDateFormat( DATE_FORMAT ); final Date modDate = new Date( System.currentTimeMillis() ); setAttribute( user, LOGIN_NAME, newName ); setAttribute( user, LAST_MODIFIED, c_format.format( modDate ) ); profile.setLoginName( newName ); profile.setLastModified( modDate ); break; } } saveDOM(); }  @Override synchronized void deleteByLoginName( final String loginName ); @Override UserProfile findByEmail( final String index ); @Override UserProfile findByFullName( final String index ); @Override UserProfile findByLoginName( final String index ); @Override UserProfile findByUid( final String uid ); @Override UserProfile findByWikiName( final String index ); UserProfile findBy( final String attr, final String value ); @Override Principal[] getWikiNames(); @Override void initialize( final Engine engine, final Properties props ); @Override synchronized void rename( final String loginName, final String newName); @Override synchronized void save( final UserProfile profile ); static final String PROP_USERDATABASE; }### Answer:
@Test public void testRename() throws Exception { try { m_db.rename( "nonexistentname", "renameduser" ); Assertions.fail( "Should not have allowed rename..." ); } catch( NoSuchPrincipalException e ) { } UserProfile profile = m_db.newProfile(); profile.setEmail( "renamed@mailinator.com" ); profile.setFullname( "Renamed User" ); profile.setLoginName( "olduser" ); profile.setPassword( "password" ); m_db.save( profile ); profile = m_db.findByLoginName( "olduser" ); Assertions.assertNotNull( profile ); try { m_db.rename( "olduser", "janne" ); Assertions.fail( "Should not have allowed rename..." ); } catch( DuplicateUserException e ) { } m_db.rename( "olduser", "renameduser" ); try { profile = m_db.findByLoginName( "olduser" ); Assertions.fail( "Old user was found, but it shouldn't have been." ); } catch( NoSuchPrincipalException e ) { } profile = m_db.findByLoginName( "renameduser" ); Assertions.assertEquals( "renamed@mailinator.com", profile.getEmail() ); Assertions.assertEquals( "Renamed User", profile.getFullname() ); Assertions.assertEquals( "renameduser", profile.getLoginName() ); Assertions.assertTrue( CryptoUtil.verifySaltedPassword( "password".getBytes(), profile.getPassword() ) ); m_db.deleteByLoginName( "renameduser" ); }