Skip to content

Commit f5ad9bf

Browse files
author
Daan Hoogland
committed
sonar
1 parent da8b2f4 commit f5ad9bf

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapManagerImplTest.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.junit.Test;
3333
import org.junit.runner.RunWith;
3434
import org.mockito.Mock;
35-
import org.mockito.Mockito;
3635
import org.mockito.junit.MockitoJUnitRunner;
3736
import org.springframework.test.util.ReflectionTestUtils;
3837

@@ -43,6 +42,7 @@
4342
import static org.junit.Assert.assertEquals;
4443
import static org.junit.Assert.assertThrows;
4544
import static org.mockito.ArgumentMatchers.any;
45+
import static org.mockito.Mockito.doThrow;
4646
import static org.mockito.Mockito.never;
4747
import static org.mockito.Mockito.times;
4848
import static org.mockito.Mockito.verify;
@@ -121,7 +121,8 @@ public void linkingDomainRefusesGroupClaimedByLiveAccount() {
121121
AccountVO liveAccount = new AccountVO();
122122
when(accountDaoMock.findByIdIncludingRemoved(liveAccountId)).thenReturn(liveAccount);
123123

124-
assertThrows(CloudRuntimeException.class, () -> ldapManager.linkDomainToLdap(buildCmd("cn=claimed,dc=my,dc=domain,dc=com")));
124+
LinkDomainToLdapCmd cmd = buildCmd("cn=claimed,dc=my,dc=domain,dc=com");
125+
assertThrows(CloudRuntimeException.class, () -> ldapManager.linkDomainToLdap(cmd));
125126

126127
verify(ldapTrustMapDaoMock, never()).persist(any());
127128
}
@@ -146,9 +147,10 @@ public void linkingDomainDoesNotPersistWhenClearingOldMappingFails() {
146147
LdapTrustMapVO oldMapping = new LdapTrustMapVO(DOMAIN_ID, LdapManager.LinkType.GROUP, "cn=old,dc=my,dc=domain,dc=com", Account.Type.NORMAL, 0);
147148
ReflectionTestUtils.setField(oldMapping, "id", OLD_MAPPING_ID);
148149
when(ldapTrustMapDaoMock.findByDomainId(DOMAIN_ID)).thenReturn(oldMapping);
149-
Mockito.doThrow(new CloudRuntimeException("db blip")).when(ldapTrustMapDaoMock).expunge(Long.valueOf(OLD_MAPPING_ID));
150+
doThrow(new CloudRuntimeException("db blip")).when(ldapTrustMapDaoMock).expunge(Long.valueOf(OLD_MAPPING_ID));
150151

151-
assertThrows(CloudRuntimeException.class, () -> ldapManager.linkDomainToLdap(buildCmd("cn=new,dc=my,dc=domain,dc=com")));
152+
LinkDomainToLdapCmd cmd = buildCmd("cn=new,dc=my,dc=domain,dc=com");
153+
assertThrows(CloudRuntimeException.class, () -> ldapManager.linkDomainToLdap(cmd));
152154

153155
verify(ldapTrustMapDaoMock, never()).persist(any());
154156
}
@@ -167,7 +169,8 @@ public void relinkingDomainRefusesWhenLdapAccountDependsOnOldMapping() {
167169
ReflectionTestUtils.setField(ldapUser, "source", User.Source.LDAP);
168170
when(userDaoMock.listByAccount(99L)).thenReturn(List.of(ldapUser));
169171

170-
assertThrows(CloudRuntimeException.class, () -> ldapManager.linkDomainToLdap(buildCmd("cn=new,dc=my,dc=domain,dc=com")));
172+
LinkDomainToLdapCmd cmd = buildCmd("cn=new,dc=my,dc=domain,dc=com");
173+
assertThrows(CloudRuntimeException.class, () -> ldapManager.linkDomainToLdap(cmd));
171174

172175
verify(ldapTrustMapDaoMock, never()).expunge(any(Long.class));
173176
verify(ldapTrustMapDaoMock, never()).persist(any());

0 commit comments

Comments
 (0)