Fix sonar findings (#2742)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-10-10 14:32:09 +03:00
committed by GitHub
parent ebc3755469
commit b390a0f8ef
3 changed files with 14 additions and 12 deletions

View File

@@ -96,7 +96,8 @@ class DistributionSetTypeManagementTest extends AbstractAccessControllerManageme
final DistributionSetType dsType2 = testdataFactory.findOrCreateDistributionSetType(
"DsType2_override", "DistributionSetType-2-override", List.of(smType2), List.of(smType1));
runAs(withAuthorities(READ_PREFIX + DISTRIBUTION_SET_TYPE, UPDATE_PREFIX + DISTRIBUTION_SET_TYPE + "/id==" + dsType1.getId()), () -> {
final List<Long> osAndAppTypeIds = List.of(osType.getId(), appType.getId());
final Long osTypeId = osType.getId();
final List<Long> osAndAppTypeIds = List.of(osTypeId, appType.getId());
// verify distributionSetTypeManagement#assignCompatibleDistributionSetTypes
DistributionSetType dsType1Up = distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType1.getId(), osAndAppTypeIds);
assertThat(dsType1Up).satisfies(
@@ -108,10 +109,10 @@ class DistributionSetTypeManagementTest extends AbstractAccessControllerManageme
.isInstanceOf(InsufficientPermissionException.class);
assertThat(distributionSetTypeManagement
.unassignSoftwareModuleType(dsType1.getId(), osType.getId()))
.unassignSoftwareModuleType(dsType1.getId(), osTypeId))
.satisfies(updatedType -> assertThat(updatedType.containsModuleType(osType)).isFalse());
assertThatThrownBy(
() -> distributionSetTypeManagement.unassignSoftwareModuleType(dsType2Id, osType.getId()))
() -> distributionSetTypeManagement.unassignSoftwareModuleType(dsType2Id, osTypeId))
.isInstanceOf(InsufficientPermissionException.class);
});
}

View File

@@ -52,7 +52,7 @@ class TargetManagementTest extends AbstractAccessControllerManagementTest {
});
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({ "rawtypes", "unchecked", "java:S5961" }) // better to keep together
@Test
void verifyRead() {
assertThat(assignDistributionSet(ds2Type2, List.of(target1Type1, target2Type2, target3Type2)).getAssigned()).isEqualTo(3);
@@ -128,7 +128,6 @@ class TargetManagementTest extends AbstractAccessControllerManagementTest {
@Test
void verifyReadCompatibleRelated() {
// assertThat(assignDistributionSet(ds2Type2, List.of(target1Type1, target2Type2, target3Type2)).getAssigned()).isEqualTo(3);
prepareFinishedUpdates(ds2Type2, target1Type1, target2Type2);
final Target target1Type1 = targetManagement.get(super.target1Type1.getId());
runAs(withAuthorities(
@@ -250,9 +249,9 @@ class TargetManagementTest extends AbstractAccessControllerManagementTest {
assertThatThrownBy(() -> targetManagement.unassignType(noPermissionsTestDataControllerId))
.isInstanceOf(InsufficientPermissionException.class);
assertThat(assignDistributionSet(ds2Type2.getId(), target1Type1.getControllerId()).getAssigned()).isEqualTo(1);
assertThatThrownBy(() -> assignDistributionSet(ds2Type2.getId(), target2Type2ControllerId)).isInstanceOf(
AssertionError.class);
final Long ds2Type2Id = ds2Type2.getId();
assertThat(assignDistributionSet(ds2Type2Id, target1Type1.getControllerId()).getAssigned()).isEqualTo(1);
assertThatThrownBy(() -> assignDistributionSet(ds2Type2Id, target2Type2ControllerId)).isInstanceOf(AssertionError.class);
// bunch assignment skips denied since at least one target without update permissions is present
assertThat(assignDistributionSet(
ds3Type2.getId(), List.of(target1Type1.getControllerId(), target2Type2ControllerId), Action.ActionType.FORCED)

View File

@@ -76,14 +76,16 @@ class TargetTypeManagementTest extends AbstractAccessControllerManagementTest {
final Update targetTypeUpdate = Update.builder().id(targetType2.getId()).description("anotherDesc").build();
assertThatThrownBy(() -> targetTypeManagement.update(targetTypeUpdate)).isInstanceOf(InsufficientPermissionException.class);
targetTypeManagement.assignCompatibleDistributionSetTypes(targetType1.getId(), List.of(dsType2.getId()));
final Long dsType2Id = dsType2.getId();
final List<Long> dsType2IdList = List.of(dsType2Id);
targetTypeManagement.assignCompatibleDistributionSetTypes(targetType1.getId(), dsType2IdList);
final Long targetType2Id = targetType2.getId();
assertThatThrownBy(
() -> targetTypeManagement.assignCompatibleDistributionSetTypes(targetType2Id, List.of(dsType2.getId())))
() -> targetTypeManagement.assignCompatibleDistributionSetTypes(targetType2Id, dsType2IdList))
.isInstanceOf(InsufficientPermissionException.class);
targetTypeManagement.unassignDistributionSetType(targetType1.getId(), dsType2.getId());
assertThatThrownBy(() -> targetTypeManagement.unassignDistributionSetType(targetType2Id, dsType2.getId()))
targetTypeManagement.unassignDistributionSetType(targetType1.getId(), dsType2Id);
assertThatThrownBy(() -> targetTypeManagement.unassignDistributionSetType(targetType2Id, dsType2Id))
.isInstanceOf(InsufficientPermissionException.class);
});
}