KON-13 KON-534 sonar work
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/constants/Constants.java b/src/main/java/org/eclipse/openk/contactbasedata/constants/Constants.java
index 02c7d4e..01ae819 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/constants/Constants.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/constants/Constants.java
@@ -21,6 +21,10 @@
     public static final String MODULE_ASSIGNMENT_UUID_NOT_EXISTING = "module.assignment.uuid.not.existing";
     public static final String ANONYMOUS_TAG = "***";
     public static final String ADDRESS_UUID_NOT_EXISTING = "address.uuid.not.existing";
+    public static final String COMMUNICATION_UUID_NOT_EXISTING = "communication.uuid.not.existing";
+    public static final String COMMUNICATION_TYPE_UUID_NOT_EXISTING = "communication.type.uuid.not.existing";
+    public static final String COMMUNICATION_TYPE_ALREADY_EXISTING_FOR_CONTACT = "communication.type.already.existing.for.contact";
+    public static final String SALUTATION_UUID_NOT_EXISTING = "salutation.uuid.not.existing";
 
     private Constants() {
         // empty Constructor for the sake of SONAR
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationController.java b/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationController.java
index 97d2568..f425049 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationController.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/controller/CommunicationController.java
@@ -19,9 +19,7 @@
 import io.swagger.annotations.ApiResponses;
 import lombok.extern.log4j.Log4j2;
 import org.eclipse.openk.contactbasedata.exceptions.BadRequestException;
-import org.eclipse.openk.contactbasedata.service.AddressService;
 import org.eclipse.openk.contactbasedata.service.CommunicationService;
-import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
 import org.eclipse.openk.contactbasedata.viewmodel.CommunicationDto;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationRepository.java
index a189d08..eedbfa5 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/CommunicationRepository.java
@@ -14,7 +14,6 @@
  */
 package org.eclipse.openk.contactbasedata.repository;
 
-import org.eclipse.openk.contactbasedata.model.TblAddress;
 import org.eclipse.openk.contactbasedata.model.TblCommunication;
 import org.eclipse.openk.contactbasedata.model.TblContact;
 import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java b/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java
index f63d8c1..97351ae 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/repository/ContactRepository.java
@@ -15,7 +15,6 @@
 package org.eclipse.openk.contactbasedata.repository;
 
 import org.eclipse.openk.contactbasedata.model.TblContact;
-import org.eclipse.openk.contactbasedata.model.VwDetailedContact;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationService.java
index 1b771ee..a824509 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/CommunicationService.java
@@ -15,18 +15,18 @@
 package org.eclipse.openk.contactbasedata.service;
 
 import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.constants.Constants;
 import org.eclipse.openk.contactbasedata.enums.OperationType;
 import org.eclipse.openk.contactbasedata.exceptions.BadRequestException;
 import org.eclipse.openk.contactbasedata.exceptions.NotFoundException;
 import org.eclipse.openk.contactbasedata.exceptions.OperationDeniedException;
-import org.eclipse.openk.contactbasedata.mapper.AddressMapper;
 import org.eclipse.openk.contactbasedata.mapper.CommunicationMapper;
 import org.eclipse.openk.contactbasedata.model.RefCommunicationType;
-import org.eclipse.openk.contactbasedata.model.TblAddress;
 import org.eclipse.openk.contactbasedata.model.TblCommunication;
 import org.eclipse.openk.contactbasedata.model.TblContact;
-import org.eclipse.openk.contactbasedata.repository.*;
-import org.eclipse.openk.contactbasedata.viewmodel.AddressDto;
+import org.eclipse.openk.contactbasedata.repository.CommunicationRepository;
+import org.eclipse.openk.contactbasedata.repository.CommunicationTypeRepository;
+import org.eclipse.openk.contactbasedata.repository.ContactRepository;
 import org.eclipse.openk.contactbasedata.viewmodel.CommunicationDto;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -62,7 +62,7 @@
 
     public CommunicationDto getCommunication(UUID contactUuid, UUID communicationUuid){
         TblCommunication tblCommunication = communicationRepository.findByUuid(communicationUuid)
-                .orElseThrow( () -> new NotFoundException("communication.uuid.not.existing"));
+                .orElseThrow( () -> new NotFoundException(Constants.COMMUNICATION_UUID_NOT_EXISTING));
         if(!tblCommunication.getTblContact().getUuid().equals(contactUuid)) {
             throw new BadRequestException("invalid.uuid.path.object");
         }
@@ -74,11 +74,11 @@
 
         TblContact tblContact = contactRepository
                                 .findByUuid(contactUuid)
-                                .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+                                .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
 
         RefCommunicationType refCommunicationType = communicationTypeRepository
                 .findByUuid(communicationDto.getCommunicationTypeUuid())
-                .orElseThrow(() -> new NotFoundException("communication.type.uuid.not.existing"));
+                .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_UUID_NOT_EXISTING));
 
 
         TblCommunication communicationToSave = communicationMapper.toTblCommunication(communicationDto);
@@ -87,7 +87,7 @@
         communicationToSave.setRefCommunicationType(refCommunicationType);
 
         if ( !checkUniqueCommunicationTypeForContactForInsert(tblContact.getId(), refCommunicationType.getId())) {
-            throw new OperationDeniedException(OperationType.INSERT, "communication.type.already.existing.for.contact");
+            throw new OperationDeniedException(OperationType.INSERT, Constants.COMMUNICATION_TYPE_ALREADY_EXISTING_FOR_CONTACT);
         }
 
         setFromCommunicationDto(communicationToSave, communicationDto);
@@ -100,14 +100,14 @@
     public CommunicationDto updateCommunication(UUID contactUuid, CommunicationDto communicationDto) {
 
         TblContact contact = contactRepository.findByUuid(contactUuid)
-                .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+                .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
 
         TblCommunication communication = communicationRepository.findByUuid(communicationDto.getUuid())
-                .orElseThrow(() -> new NotFoundException("communication.uuid.not.existing"));
+                .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_UUID_NOT_EXISTING));
 
         RefCommunicationType refCommunicationType = communicationTypeRepository
                 .findByUuid(communicationDto.getCommunicationTypeUuid())
-                .orElseThrow(() -> new NotFoundException("communication.type.uuid.not.existing"));
+                .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_TYPE_UUID_NOT_EXISTING));
 
         TblCommunication communicationToSave = communicationMapper.toTblCommunication(communicationDto);
         communicationToSave.setTblContact(contact);
@@ -115,7 +115,7 @@
         communicationToSave.setId(communication.getId());
 
         if ( !checkUniqueCommunicationTypeForContactForUpdate(contact.getId(), refCommunicationType.getId(), communication.getUuid())) {
-            throw new OperationDeniedException(OperationType.UPDATE, "communication.type.already.existing.for.contact");
+            throw new OperationDeniedException(OperationType.UPDATE, Constants.COMMUNICATION_TYPE_ALREADY_EXISTING_FOR_CONTACT);
         }
 
         setFromCommunicationDto(communicationToSave, communicationDto);
@@ -127,9 +127,9 @@
     @Transactional
     public void deleteCommunication(UUID contactUuid, UUID communicationUuid) {
         TblContact tblContact = contactRepository.findByUuid(contactUuid)
-                .orElseThrow(() -> new NotFoundException("contact.uuid.not.existing"));
+                .orElseThrow(() -> new NotFoundException(Constants.CONTACT_UUID_NOT_EXISTING));
         TblCommunication tblCommunication = communicationRepository.findByTblContactAndUuid(tblContact, communicationUuid)
-                .orElseThrow(() -> new NotFoundException("communication.uuid.not.existing"));
+                .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_UUID_NOT_EXISTING));
 
         communicationRepository.delete(tblCommunication);
     }
@@ -148,7 +148,7 @@
         if( sourceDto.getCommunicationTypeUuid() != null ) {
             destTblCommunication.setRefCommunicationType( communicationTypeRepository
                     .findByUuid(sourceDto.getCommunicationTypeUuid())
-                    .orElseThrow(() -> new NotFoundException("communication.type.uuid.not.existing")));
+                    .orElseThrow(() -> new NotFoundException(Constants.COMMUNICATION_TYPE_UUID_NOT_EXISTING)));
         }
         else {
             destTblCommunication.setRefCommunicationType(null);
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java b/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java
index 9c615d0..6c12c80 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/SalutationService.java
@@ -15,6 +15,7 @@
 package org.eclipse.openk.contactbasedata.service;
 
 import lombok.extern.log4j.Log4j2;
+import org.eclipse.openk.contactbasedata.constants.Constants;
 import org.eclipse.openk.contactbasedata.exceptions.BadRequestException;
 import org.eclipse.openk.contactbasedata.exceptions.NotFoundException;
 import org.eclipse.openk.contactbasedata.mapper.SalutationMapper;
@@ -48,7 +49,7 @@
     public SalutationDto getSalutationByUuid(UUID salutationUuid) {
         RefSalutation refSalutation = salutationRepository
                 .findByUuid(salutationUuid)
-                .orElseThrow(() -> new NotFoundException("salutation.uuid.not.existing"));
+                .orElseThrow(() -> new NotFoundException(Constants.SALUTATION_UUID_NOT_EXISTING));
         return salutationMapper.toSalutationDto(refSalutation);
     }
 
@@ -67,7 +68,7 @@
         RefSalutation salutationToSave = salutationMapper.toRefSalutation(salutationDto);
         RefSalutation existingSalutation = salutationRepository
                 .findByUuid(salutationDto.getUuid())
-                .orElseThrow(() -> new NotFoundException("salutation.uuid.not.existing"));
+                .orElseThrow(() -> new NotFoundException(Constants.SALUTATION_UUID_NOT_EXISTING));
         salutationToSave.setId(existingSalutation.getId());
         salutationUpdated = salutationRepository.save(salutationToSave);
 
@@ -77,7 +78,7 @@
     @Transactional
     public void removeSalutation(UUID uuid) {
         RefSalutation existingSalutation = salutationRepository.findByUuid(uuid)
-                .orElseThrow( () -> new BadRequestException("salutation.uuid.not.existing"));
+                .orElseThrow( () -> new BadRequestException(Constants.SALUTATION_UUID_NOT_EXISTING));
 
         salutationRepository.delete(existingSalutation);
     }
diff --git a/src/main/java/org/eclipse/openk/contactbasedata/service/util/SearchContactsFilterParams.java b/src/main/java/org/eclipse/openk/contactbasedata/service/util/SearchContactsFilterParams.java
index 802b4ed..a62ffe3 100644
--- a/src/main/java/org/eclipse/openk/contactbasedata/service/util/SearchContactsFilterParams.java
+++ b/src/main/java/org/eclipse/openk/contactbasedata/service/util/SearchContactsFilterParams.java
@@ -22,12 +22,12 @@
 @Data
 @NoArgsConstructor
 public class SearchContactsFilterParams {
-    private String contactType;
-    private UUID personTypeUuid;
-    private String searchText;
-    private String moduleName;
-    private boolean withoutModule;
-    private boolean expiringDataInPast;
-    private boolean delLockExceeded;
-    private boolean showAnonymized;
+    private String contactType; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+    private UUID personTypeUuid; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+    private String searchText; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+    private String moduleName; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+    private boolean withoutModule; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+    private boolean expiringDataInPast; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+    private boolean delLockExceeded; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
+    private boolean showAnonymized; // NOSONAR _fd: 10.02.2020 definitly used via Lombok-Accessors
 }
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/service/CompanyServiceTest.java b/src/test/java/org/eclipse/openk/contactbasedata/service/CompanyServiceTest.java
index a928ea2..fb6d18e 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/service/CompanyServiceTest.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/service/CompanyServiceTest.java
@@ -31,6 +31,8 @@
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
 import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.test.context.ContextConfiguration;
 
 import java.util.List;
@@ -39,7 +41,7 @@
 
 import static org.junit.jupiter.api.Assertions.*;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 @DataJpaTest
 @ContextConfiguration(classes = {TestConfiguration.class})
@@ -70,6 +72,24 @@
         assertEquals(ep.getContact().getUuid(), dto.getContactUuid());
     }
 
+
+    @Test
+    public void shouldFindSeveralCompaniesProperly() {
+        Page<TblCompany> page1 = MockDataHelper.mockCompanyPage();
+        Page<TblCompany> page2 = MockDataHelper.mockCompanyPage();
+        when(companyRepository.findAll(any(Pageable.class))).thenReturn(page1);
+        when(companyRepository.findByContact_anonymizedFalseOrContact_anonymizedIsNull(any(Pageable.class))).thenReturn(page2);
+        Page<CompanyDto> dtos1 = companyService.findCompanies(true, Pageable.unpaged());
+        Page<CompanyDto> dtos2 = companyService.findCompanies(false, Pageable.unpaged());
+
+        assertEquals(page1.getContent().get(0).getContact().getUuid(), dtos1.get().findFirst().get().getContactUuid());
+        assertEquals(page2.getContent().get(1).getContact().getUuid(), dtos2.getContent().get(1).getContactUuid());
+        assertNotEquals(dtos1.getContent().get(0).getContactUuid(), dtos2.getContent().get(0).getContactUuid());
+
+        verify(companyRepository, times(1)).findAll(any(Pageable.class));
+        verify(companyRepository, times(1))
+                .findByContact_anonymizedFalseOrContact_anonymizedIsNull(any(Pageable.class));
+    }
     @Test
     public void shouldThrowInErrorCaseWithCompany() {
         TblCompany ep = MockDataHelper.mockCompany();
diff --git a/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java b/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
index f4e1808..54e216e 100644
--- a/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
+++ b/src/test/java/org/eclipse/openk/contactbasedata/support/MockDataHelper.java
@@ -476,6 +476,18 @@
         return tblCompany;
     }
 
+    public static Page<TblCompany> mockCompanyPage(){
+
+        TblCompany com1 = mockCompany();
+
+        TblCompany com2 = mockCompany();
+        com2.setCompanyName("Sputnik 2000");
+        com2.setCompanyType("AG");
+
+        List<TblCompany> list = Arrays.asList(com1, com2);
+        return new PageImpl<>(list, Pageable.unpaged(), list.size());
+    }
+
     public static Page<CompanyDto> mockCompanyDtoPage(){
 
         CompanyDto com1 = mockCompanyDto();