*/
package org.sonar.server.user;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.sonar.db.component.ComponentDto;
}
};
- try {
- DoPrivileged.execute(catcher);
- fail("An exception should have been raised!");
- } catch (Throwable ignored) {
- // verify session in place after task is done
- assertThat(threadLocalUserSession.get()).isSameAs(session);
+ Assert.assertThrows(Exception.class, () -> DoPrivileged.execute(catcher));
- // verify the session used inside Privileged task
- assertThat(catcher.userSession.isLoggedIn()).isFalse();
- assertThat(catcher.userSession.hasComponentPermission("any permission", new ComponentDto())).isTrue();
- }
+ // verify session in place after task is done
+ assertThat(threadLocalUserSession.get()).isSameAs(session);
+
+ // verify the session used inside Privileged task
+ assertThat(catcher.userSession.isLoggedIn()).isFalse();
+ assertThat(catcher.userSession.hasComponentPermission("any permission", new ComponentDto())).isTrue();
}
private class UserSessionCatcherTask extends DoPrivileged.Task {