Skip to content

Commit

Permalink
Code cleanup and refactoring #86
Browse files Browse the repository at this point in the history
  • Loading branch information
tillias committed Nov 6, 2020
1 parent cfd4c9e commit 0436a6a
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 54 deletions.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sonar.testExecutionReportPaths=target/test-results/jest/TESTS-results-sonar.xml
sonar.typescript.lcov.reportPaths=target/test-results/lcov.info

sonar.sourceEncoding=UTF-8
sonar.exclusions=src/main/webapp/content/**/*.*, src/main/webapp/i18n/*.js, target/classes/static/**/*.*, **/main/resources/**/*, **/test/**/*, **/main/webapp/app/admin/**/*, **/aop/logging/*
sonar.exclusions=src/main/webapp/content/**/*.*, src/main/webapp/i18n/*.js, target/classes/static/**/*.*, **/main/resources/**/*, **/test/**/*, **/main/webapp/app/admin/**/*, **/aop/logging/*, **/dto/custom/builder/*

sonar.issue.ignore.multicriteria=S3437,S4502,S4684,UndocumentedApi,BoldAndItalicTagsCheck
# Rule https://sonarcloud.io/coding_rules?open=squid%3AS3437&rule_key=squid%3AS3437 is ignored, as a JPA-managed field cannot be transient
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.microcatalog.service.dto.custom;

public abstract class BaseDto {
private Long id;
private String name;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
package com.github.microcatalog.service.dto.custom;

public class DependencyDto {
private Long id;
private String name;
public class DependencyDto extends BaseDto {
private MicroserviceDto source;
private MicroserviceDto target;

public DependencyDto id(Long id) {
this.id = id;
return this;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public MicroserviceDto getSource() {
return source;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
package com.github.microcatalog.service.dto.custom;

public class MicroserviceDto {
private Long id;
private String name;
public class MicroserviceDto extends BaseDto {

public MicroserviceDto id(Long id) {
this.id = id;
return this;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.github.microcatalog.service.dto.custom.builder;

import com.github.microcatalog.service.dto.custom.DependencyDto;
import com.github.microcatalog.service.dto.custom.MicroserviceDto;

public final class DependencyDtoBuilder {
private MicroserviceDto source;
private MicroserviceDto target;
private Long id;
private String name;

private DependencyDtoBuilder() {
}

public static DependencyDtoBuilder aDependencyDto() {
return new DependencyDtoBuilder();
}

public DependencyDtoBuilder withSource(MicroserviceDto source) {
this.source = source;
return this;
}

public DependencyDtoBuilder withTarget(MicroserviceDto target) {
this.target = target;
return this;
}

public DependencyDtoBuilder withId(Long id) {
this.id = id;
return this;
}

public DependencyDtoBuilder withName(String name) {
this.name = name;
return this;
}

public DependencyDto build() {
DependencyDto dependencyDto = new DependencyDto();
dependencyDto.setSource(source);
dependencyDto.setTarget(target);
dependencyDto.setId(id);
dependencyDto.setName(name);
return dependencyDto;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.microcatalog.service.dto.custom.builder;

import com.github.microcatalog.service.dto.custom.MicroserviceDto;

public final class MicroserviceDtoBuilder {
private Long id;
private String name;

private MicroserviceDtoBuilder() {
}

public static MicroserviceDtoBuilder aMicroserviceDto() {
return new MicroserviceDtoBuilder();
}

public MicroserviceDtoBuilder withId(Long id) {
this.id = id;
return this;
}

public MicroserviceDtoBuilder withName(String name) {
this.name = name;
return this;
}

public MicroserviceDto build() {
MicroserviceDto microserviceDto = new MicroserviceDto();
microserviceDto.setId(id);
microserviceDto.setName(name);
return microserviceDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.microcatalog.MockMvcWithUser;
import com.github.microcatalog.service.custom.DependencyService;
import com.github.microcatalog.service.dto.custom.DependencyDto;
import com.github.microcatalog.service.dto.custom.builder.DependencyDtoBuilder;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -14,6 +15,7 @@
import java.util.Arrays;
import java.util.Collections;

import static com.github.microcatalog.service.dto.custom.builder.DependencyDtoBuilder.aDependencyDto;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand All @@ -34,9 +36,9 @@ void findAllById_Found_Success() throws Exception {

given(service.findAllById(Arrays.asList(1L, 2L, 3L)))
.willReturn(Arrays.asList(
new DependencyDto().id(1L),
new DependencyDto().id(2L),
new DependencyDto().id(3L))
aDependencyDto().withId(1L).build(),
aDependencyDto().withId(2L).build(),
aDependencyDto().withId(3L).build())
);

mockMvc.perform(get("/api/dependencies/by/1,2,3"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Arrays;
import java.util.Collections;

import static com.github.microcatalog.service.dto.custom.builder.MicroserviceDtoBuilder.aMicroserviceDto;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand All @@ -34,9 +35,9 @@ void findAllById_Found_Success() throws Exception {

given(service.findAllById(Arrays.asList(1L, 2L, 3L)))
.willReturn(Arrays.asList(
new MicroserviceDto().id(1L),
new MicroserviceDto().id(2L),
new MicroserviceDto().id(3L))
aMicroserviceDto().withId(1L).build(),
aMicroserviceDto().withId(2L).build(),
aMicroserviceDto().withId(3L).build())
);

mockMvc.perform(get("/api/microservices/by/1,2,3"))
Expand Down

0 comments on commit 0436a6a

Please sign in to comment.