Skip to content

Commit eab7acf

Browse files
committed
Improved code after code review
1 parent d66655b commit eab7acf

File tree

4 files changed

+121
-105
lines changed

4 files changed

+121
-105
lines changed

hackster-service-client/pom.xml

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,66 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
56

6-
<groupId>com.lohika.jclub.hackster.client</groupId>
7-
<artifactId>hackster-service-client</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
9-
<packaging>jar</packaging>
7+
<groupId>com.lohika.jclub.hackster.client</groupId>
8+
<artifactId>hackster-service-client</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<packaging>jar</packaging>
1011

11-
<name>hackster-service-client</name>
12-
<description>Client library for Hackster Service</description>
12+
<name>hackster-service-client</name>
13+
<description>Client library for Hackster Service</description>
1314

14-
<parent>
15-
<groupId>org.springframework.boot</groupId>
16-
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>1.5.4.RELEASE</version>
18-
<relativePath/> <!-- lookup parent from repository -->
19-
</parent>
15+
<parent>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-parent</artifactId>
18+
<version>1.5.4.RELEASE</version>
19+
<relativePath/> <!-- lookup parent from repository -->
20+
</parent>
2021

21-
<properties>
22-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>1.8</java.version>
25-
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
26-
</properties>
22+
<properties>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
25+
<java.version>1.8</java.version>
26+
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
27+
</properties>
2728

28-
<dependencies>
29-
<dependency>
30-
<groupId>org.springframework.cloud</groupId>
31-
<artifactId>spring-cloud-starter-eureka</artifactId>
32-
</dependency>
33-
<dependency>
34-
<groupId>org.springframework.cloud</groupId>
35-
<artifactId>spring-cloud-starter-feign</artifactId>
36-
</dependency>
37-
<dependency>
38-
<groupId>org.springframework.cloud</groupId>
39-
<artifactId>spring-cloud-starter-hystrix</artifactId>
40-
</dependency>
41-
<dependency>
42-
<groupId>org.springframework.boot</groupId>
43-
<artifactId>spring-boot-starter-hateoas</artifactId>
44-
</dependency>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.cloud</groupId>
32+
<artifactId>spring-cloud-starter-eureka</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.cloud</groupId>
36+
<artifactId>spring-cloud-starter-feign</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.springframework.cloud</groupId>
40+
<artifactId>spring-cloud-starter-hystrix</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-hateoas</artifactId>
45+
</dependency>
4546

46-
<dependency>
47-
<groupId>org.projectlombok</groupId>
48-
<artifactId>lombok</artifactId>
49-
<optional>true</optional>
50-
</dependency>
47+
<dependency>
48+
<groupId>org.projectlombok</groupId>
49+
<artifactId>lombok</artifactId>
50+
<optional>true</optional>
51+
</dependency>
5152

52-
<dependency>
53-
<groupId>org.springframework.boot</groupId>
54-
<artifactId>spring-boot-starter-test</artifactId>
55-
<scope>test</scope>
56-
</dependency>
57-
<dependency>
58-
<groupId>com.lohika.jclub</groupId>
59-
<artifactId>discovery-server</artifactId>
60-
<version>0.0.1-SNAPSHOT</version>
61-
<scope>test</scope>
62-
</dependency>
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-test</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.lohika.jclub</groupId>
60+
<artifactId>discovery-server</artifactId>
61+
<version>0.0.1-SNAPSHOT</version>
62+
<scope>test</scope>
63+
</dependency>
6364
<dependency>
6465
<groupId>org.testcontainers</groupId>
6566
<artifactId>testcontainers</artifactId>
@@ -72,18 +73,18 @@
7273
<version>0.0.1-SNAPSHOT</version>
7374
<scope>test</scope>
7475
</dependency>
75-
</dependencies>
76+
</dependencies>
7677

77-
<dependencyManagement>
78-
<dependencies>
79-
<dependency>
80-
<groupId>org.springframework.cloud</groupId>
81-
<artifactId>spring-cloud-dependencies</artifactId>
82-
<version>${spring-cloud.version}</version>
83-
<type>pom</type>
84-
<scope>import</scope>
85-
</dependency>
86-
</dependencies>
87-
</dependencyManagement>
78+
<dependencyManagement>
79+
<dependencies>
80+
<dependency>
81+
<groupId>org.springframework.cloud</groupId>
82+
<artifactId>spring-cloud-dependencies</artifactId>
83+
<version>${spring-cloud.version}</version>
84+
<type>pom</type>
85+
<scope>import</scope>
86+
</dependency>
87+
</dependencies>
88+
</dependencyManagement>
8889

8990
</project>

hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
import org.testcontainers.containers.wait.LogMessageWaitStrategy;
1515

1616
import static org.hamcrest.Matchers.equalTo;
17-
import static org.hamcrest.Matchers.notNullValue;
1817
import static org.junit.Assert.assertThat;
1918

2019
@RunWith(SpringRunner.class)
2120
@SpringBootTest(classes = HacksterServiceClientTestApplication.class)
2221
@ContextConfiguration(initializers = HacksterServiceClientTest.Initializer.class)
2322
public class HacksterServiceClientTest {
23+
private static final int MAX_ALLOWED_APARTMENTS_PER_REALTOR = 4;
2424

2525
@ClassRule
2626
public static GenericContainer HacksterService = new GenericContainer("hackster-service:latest")
2727
.withExposedPorts(8082)
28-
.withEnv("maxAllowedApartmentsPerRealtor", "4")
28+
.withEnv("maxAllowedApartmentsPerRealtor", Integer.toString(MAX_ALLOWED_APARTMENTS_PER_REALTOR))
2929
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started HacksterServiceApplication in.*\\s"));
3030

3131
@Autowired
@@ -40,15 +40,12 @@ public void testIfNewNumberIsNotHackster() {
4040

4141
@Test
4242
public void testIfNumberBecomeAHackster() {
43-
boolean isHacksterFalse = hacksterServiceClient.isHackster("321321312");
44-
45-
for (int i = 0; i < 5; i++) {
43+
for (int i = 0; i < MAX_ALLOWED_APARTMENTS_PER_REALTOR; i++) {
4644
hacksterServiceClient.isHackster("321321312");
4745
}
4846

4947
boolean isHacksterTrue = hacksterServiceClient.isHackster("321321312");
5048

51-
assertThat(isHacksterFalse, equalTo(false));
5249
assertThat(isHacksterTrue, equalTo(true));
5350
}
5451

@@ -58,7 +55,7 @@ public void initialize(ConfigurableApplicationContext configurableApplicationCon
5855

5956
EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
6057
"hackster-service.ribbon.servers=http://" + HacksterService.getContainerIpAddress() + ":"
61-
+ HacksterService.getMappedPort(8082) + "/"
58+
+ HacksterService.getMappedPort(8082) + "/"
6259
);
6360
}
6461
}

hackster-service/src/test/java/com/lohika/jclub/HacksterServiceApplicationTests.java

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,21 @@
33
import org.junit.Test;
44
import org.junit.runner.RunWith;
55
import org.springframework.beans.factory.annotation.Autowired;
6-
import org.springframework.beans.factory.annotation.Value;
76
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
87
import org.springframework.boot.test.context.SpringBootTest;
98
import org.springframework.test.context.junit4.SpringRunner;
10-
import org.springframework.test.web.servlet.MockMvc;
11-
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
129

13-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
14-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
15-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
10+
import static junit.framework.TestCase.assertTrue;
1611

1712
@RunWith(SpringRunner.class)
1813
@SpringBootTest
1914
@AutoConfigureMockMvc
2015
public class HacksterServiceApplicationTests {
21-
@Value("${maxAllowedApartmentsPerRealtor}")
22-
private int maxAllowedApartmentsPerRealtor;
23-
2416
@Autowired
25-
private MockMvc mockMvc;
26-
27-
@Test
28-
public void testIfNewPhoneNumberIsNotHakster() throws Exception {
29-
mockMvc.perform(get("/hackster/123123123"))
30-
.andDo(MockMvcResultHandlers.print())
31-
.andExpect(status().isOk())
32-
.andExpect(content().string("false"));
33-
}
17+
private HacksterService hacksterService;
3418

3519
@Test
36-
public void testIfPhoneNumberBecomeAHakster() throws Exception {
37-
mockMvc.perform(get("/hackster/321321"))
38-
.andDo(MockMvcResultHandlers.print())
39-
.andExpect(status().isOk())
40-
.andExpect(content().string("false"));
41-
42-
for (int i = 0; i < maxAllowedApartmentsPerRealtor - 1; i++) {
43-
mockMvc.perform(get("/hackster/321321"));
44-
}
45-
46-
mockMvc.perform(get("/hackster/321321"))
47-
.andDo(MockMvcResultHandlers.print())
48-
.andExpect(status().isOk())
49-
.andExpect(content().string("true"));
20+
public void testContextLoad() throws Exception {
21+
assertTrue(hacksterService != null);
5022
}
5123
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.lohika.jclub;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.test.context.junit4.SpringRunner;
10+
import org.springframework.test.web.servlet.MockMvc;
11+
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
12+
13+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
14+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
15+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
16+
17+
@RunWith(SpringRunner.class)
18+
@SpringBootTest
19+
@AutoConfigureMockMvc
20+
public class HacksterServiceTests {
21+
@Value("${maxAllowedApartmentsPerRealtor}")
22+
private int maxAllowedApartmentsPerRealtor;
23+
24+
@Autowired
25+
private MockMvc mockMvc;
26+
27+
@Test
28+
public void testIfNewPhoneNumberIsNotHakster() throws Exception {
29+
mockMvc.perform(get("/hackster/123123123"))
30+
.andDo(MockMvcResultHandlers.print())
31+
.andExpect(status().isOk())
32+
.andExpect(content().string("false"));
33+
}
34+
35+
@Test
36+
public void testIfPhoneNumberBecomeAHakster() throws Exception {
37+
for (int i = 0; i < maxAllowedApartmentsPerRealtor; i++) {
38+
mockMvc.perform(get("/hackster/321321"));
39+
}
40+
41+
mockMvc.perform(get("/hackster/321321"))
42+
.andDo(MockMvcResultHandlers.print())
43+
.andExpect(status().isOk())
44+
.andExpect(content().string("true"));
45+
}
46+
}

0 commit comments

Comments
 (0)