*/
package org.sonar.server.dismissmessage.ws;
-import java.util.Arrays;
-import java.util.Collection;
-import javax.annotation.Nullable;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import java.util.stream.Stream;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
-import org.sonar.db.dismissmessage.MessageType;
import org.sonar.db.component.ProjectData;
+import org.sonar.db.dismissmessage.MessageType;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.tester.UserSessionRule;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-@RunWith(Parameterized.class)
-public class DismissActionParameterizedIT {
-
- @Rule
- public UserSessionRule userSession = UserSessionRule.standalone();
+class DismissActionParameterizedIT {
- @Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ @RegisterExtension
+ private final UserSessionRule userSession = UserSessionRule.standalone();
- @Nullable
- private final boolean isProjectKeyNull;
+ @RegisterExtension
+ private final DbTester db = DbTester.create(System2.INSTANCE);
- private final MessageType messageType;
-
- private final Class<? extends Throwable> expectedException;
private final WsActionTester underTest = new WsActionTester(new DismissAction(userSession, db.getDbClient(), TestComponentFinder.from(db)));
- public DismissActionParameterizedIT(boolean isProjectKeyNull, MessageType messageType, Class<? extends Throwable> expectedException) {
- this.isProjectKeyNull = isProjectKeyNull;
- this.messageType = messageType;
- this.expectedException = expectedException;
- }
-
- @Test
- public void test_verifyProjectKeyAndMessageType() {
+ @ParameterizedTest
+ @MethodSource("combinations")
+ void execute(boolean isProjectKeyNull, MessageType messageType, Class<? extends Throwable> expectedException) {
UserDto user = db.users().insertUser();
userSession.logIn(user);
if(expectedException != null) {
assertThatThrownBy(request::execute)
.isInstanceOf(expectedException);
- } else {
+ } else {
TestResponse response = request.execute();
assertThat(response.getStatus()).isEqualTo(204);
}
}
- @Parameterized.Parameters
- public static Collection<Object[]> parameterCombination() {
- return Arrays.asList(new Object[][]{
- {true, MessageType.INFO, IllegalArgumentException.class},
- {true, MessageType.GENERIC, IllegalArgumentException.class},
- {true, MessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE, IllegalArgumentException.class},
- {false, MessageType.GLOBAL_NCD_90, IllegalArgumentException.class},
- {false, MessageType.GLOBAL_NCD_PAGE_90, IllegalArgumentException.class},
- {true, MessageType.PROJECT_NCD_90, IllegalArgumentException.class},
- {true, MessageType.PROJECT_NCD_PAGE_90, IllegalArgumentException.class},
- {true, MessageType.BRANCH_NCD_90, IllegalArgumentException.class},
- {true, MessageType.GLOBAL_NCD_90, null},
- {true, MessageType.GLOBAL_NCD_PAGE_90, null},
- {false, MessageType.PROJECT_NCD_90, null},
- {false, MessageType.PROJECT_NCD_PAGE_90, null},
- {false, MessageType.BRANCH_NCD_90, null},
- });
+ private static Stream<Arguments> combinations() {
+ return Stream.of(
+ Arguments.of(true, MessageType.INFO, IllegalArgumentException.class),
+ Arguments.of(true, MessageType.GENERIC, IllegalArgumentException.class),
+ Arguments.of(true, MessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE, IllegalArgumentException.class),
+ Arguments.of(false, MessageType.GLOBAL_NCD_90, IllegalArgumentException.class),
+ Arguments.of(false, MessageType.GLOBAL_NCD_PAGE_90, IllegalArgumentException.class),
+ Arguments.of(true, MessageType.PROJECT_NCD_90, IllegalArgumentException.class),
+ Arguments.of(true, MessageType.PROJECT_NCD_PAGE_90, IllegalArgumentException.class),
+ Arguments.of(true, MessageType.BRANCH_NCD_90, IllegalArgumentException.class),
+ Arguments.of(true, MessageType.GLOBAL_NCD_90, null),
+ Arguments.of(true, MessageType.GLOBAL_NCD_PAGE_90, null),
+ Arguments.of(false, MessageType.PROJECT_NCD_90, null),
+ Arguments.of(false, MessageType.PROJECT_NCD_PAGE_90, null),
+ Arguments.of(false, MessageType.BRANCH_NCD_90, null),
+ Arguments.of(false, MessageType.UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE, null),
+ Arguments.of(true, MessageType.UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE, IllegalArgumentException.class)
+ );
}
}