Skip to content

Commit

Permalink
fix: code smells and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenRobertsHEE committed Jul 10, 2024
1 parent deba798 commit 082c40c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import lombok.Data;

/**
* A DTO for transferring HeeUser data to the DMS.
*/
@Data
public class HeeUserDmsDto {
private final String name;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/uk/nhs/tis/sync/service/DataRequestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ public List<Object> retrieveDtos(Map<String, String> message) {
.collect(Collectors.toList());
}

if(table.equals(TABLE_HEE_USER) && message.containsKey("name")) {
if (table.equals(TABLE_HEE_USER) && message.containsKey("name")) {
String name = message.get("name");
return createNonNullList(profileServiceImpl.getSingleAdminUser(name));
}

if(table.equals(TABLE_DBC) && message.containsKey("dbc")) {
if (table.equals(TABLE_DBC) && message.containsKey("dbc")) {
String dbc = message.get("dbc");
ResponseEntity<DBCDTO> responseEntity = referenceServiceImpl.getDBCByCode(dbc);
return createNonNullList(responseEntity.getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import uk.nhs.tis.sync.dto.HeeUserDmsDto;

public class HeeUserMapperTest {
class HeeUserMapperTest {

private HeeUserMapper mapper;

Expand Down Expand Up @@ -59,4 +61,12 @@ public void shouldMapAHeeUserDtoToADataDmsDto() {
assertEquals("phone", heeUserDmsDto.getPhoneNumber());
//other HeeUserDto properties are ignored
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
void shouldMapBooleansToZeroOrOneString(boolean bool) {
heeUserDto.setActive(bool);
HeeUserDmsDto heeUserDmsDto = mapper.toDmsDto(heeUserDto);
assertEquals(bool ? "1" : "0", heeUserDmsDto.getActive());
}
}
24 changes: 24 additions & 0 deletions src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,18 @@ void shouldReturnEmptyWhenHeeUserNotFound() {
assertThat("Unexpected DTO count.", heeUsers.size(), is(0));
}

@Test
void shouldReturnEmptyWhenHeeUserMessageHasWrongKey() {
Map<String, String> message = new HashMap<String, String>() {{
put("table", "HeeUser");
put("another key", HEE_USER_NAME);
}};
List<Object> heeUsers = service.retrieveDtos(message);

assertThat("Unexpected DTO count.", heeUsers.size(), is(0));
verifyNoInteractions(profileService);
}

@Test
void shouldReturnDbcWhenDbcFound() {
DBCDTO expectedDto = new DBCDTO();
Expand Down Expand Up @@ -858,4 +870,16 @@ void shouldReturnEmptyWhenDbcNotFound() {

assertThat("Unexpected DTO count.", dbcs.size(), is(0));
}

@Test
void shouldReturnEmptyWhenDbcMessageHasWrongKey() {
Map<String, String> message = new HashMap<String, String>() {{
put("table", "DBC");
put("another key", DBC_VALUE);
}};
List<Object> dbcs = service.retrieveDtos(message);

assertThat("Unexpected DTO count.", dbcs.size(), is(0));
verifyNoInteractions(referenceService);
}
}

0 comments on commit 082c40c

Please sign in to comment.