Skip to content

Commit 60f8191

Browse files
committed
All tests run properly.
1 parent bb95a0c commit 60f8191

File tree

4 files changed

+15
-67
lines changed

4 files changed

+15
-67
lines changed

pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,6 @@
4848
<version>1.11.3</version>
4949
<scope>test</scope>
5050
</dependency>
51-
<dependency>
52-
<groupId>org.junit.jupiter</groupId>
53-
<artifactId>junit-jupiter-api</artifactId>
54-
<version>RELEASE</version>
55-
<scope>test</scope>
56-
</dependency>
57-
<dependency>
58-
<groupId>org.junit.jupiter</groupId>
59-
<artifactId>junit-jupiter-api</artifactId>
60-
<version>RELEASE</version>
61-
<scope>test</scope>
62-
</dependency>
6351
</dependencies>
6452

6553
<build>

src/test/java/com/trendyol/recomengine/webservice/controller/BaseMongoIntegrationTest.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
package com.trendyol.recomengine.webservice.controller;
22

3-
import com.trendyol.recomengine.webservice.model.Recommendation;
4-
import com.trendyol.recomengine.webservice.repository.RecommendationRepository;
5-
import com.trendyol.recomengine.webservice.service.RecommendationService;
6-
import org.junit.Assert;
7-
import org.junit.Test;
83
import org.junit.runner.RunWith;
9-
import org.springframework.beans.factory.annotation.Autowired;
104
import org.springframework.boot.test.context.SpringBootTest;
115
import org.springframework.boot.test.util.TestPropertyValues;
126
import org.springframework.context.ApplicationContextInitializer;
@@ -22,26 +16,12 @@
2216
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
2317
@ActiveProfiles("test")
2418
@ContextConfiguration(initializers = BaseMongoIntegrationTest.Initializer.class)
25-
public class BaseMongoIntegrationTest {
19+
public abstract class BaseMongoIntegrationTest {
2620
private static final int MONGO_PORT = 27017;
2721

2822
private static GenericContainer mongoContainer = new GenericContainer("mongo:latest")
2923
.withExposedPorts(MONGO_PORT)
3024
.waitingFor(Wait.forListeningPort());
31-
@Autowired
32-
RecommendationRepository recommendationRepository;
33-
@Autowired
34-
RecommendationService recommendationService;
35-
36-
@Test
37-
public void dummyTest() {
38-
String userId = "3";
39-
String[] recommendations = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
40-
41-
Recommendation recommendation = new Recommendation(userId, recommendations);
42-
recommendationRepository.save(recommendation);
43-
Assert.assertEquals(recommendationService.getRecommendations(userId).get_id(), userId);
44-
}
4525

4626
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
4727
@Override

src/test/java/com/trendyol/recomengine/webservice/controller/RecommendationControllerIntegrationTests.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,23 @@
33
import com.trendyol.recomengine.webservice.model.Recommendation;
44
import com.trendyol.recomengine.webservice.repository.RecommendationRepository;
55
import com.trendyol.recomengine.webservice.service.RecommendationService;
6+
import org.junit.Assert;
67
import org.junit.Test;
7-
import org.junit.runner.RunWith;
88
import org.springframework.beans.factory.annotation.Autowired;
9-
import org.springframework.boot.test.context.SpringBootTest;
10-
import org.springframework.test.context.ActiveProfiles;
11-
import org.springframework.test.context.ContextConfiguration;
12-
import org.springframework.test.context.junit4.SpringRunner;
13-
import org.springframework.test.context.support.AnnotationConfigContextLoader;
14-
import org.testcontainers.containers.GenericContainer;
159

16-
@RunWith(SpringRunner.class)
17-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
18-
@ActiveProfiles("test")
19-
public class RecommendationControllerIntegrationTests {
10+
public class RecommendationControllerIntegrationTests extends BaseMongoIntegrationTest {
2011
@Autowired
21-
RecommendationRepository recommendationRepository;
22-
12+
private RecommendationRepository recommendationRepository;
2313
@Autowired
24-
RecommendationService recommendationService;
14+
private RecommendationService recommendationService;
2515

2616
@Test
27-
public void contextLoad() {
28-
29-
}
30-
31-
@Test
32-
public void givenUserObject_whenSave_thenCreateNewUser() {
17+
public void getRecommendationShouldReturnTheRelevantUsersRecommendation() {
3318
String userId = "3";
3419
String[] recommendations = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
3520

3621
Recommendation recommendation = new Recommendation(userId, recommendations);
3722
recommendationRepository.save(recommendation);
38-
assert (recommendationService.getRecommendations(userId).get_id().equals(userId));
23+
Assert.assertEquals(recommendationService.getRecommendations(userId).get_id(), userId);
3924
}
40-
4125
}
42-

src/test/java/com/trendyol/recomengine/webservice/controller/ReviewControllerUnitTests.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.trendyol.recomengine.webservice.model.Review;
5-
import com.trendyol.recomengine.webservice.repository.RecommendationRepository;
65
import org.junit.Test;
76
import org.junit.runner.RunWith;
87
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,12 +13,10 @@
1413
import org.springframework.test.context.junit4.SpringRunner;
1514
import org.springframework.test.web.servlet.MockMvc;
1615

17-
import java.io.Serializable;
1816
import java.sql.Timestamp;
1917
import java.text.SimpleDateFormat;
2018
import java.util.TimeZone;
2119

22-
import static org.mockito.BDDMockito.given;
2320
import static org.springframework.test.web.servlet.ResultMatcher.matchAll;
2421
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
2522
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@@ -36,6 +33,14 @@ public class ReviewControllerUnitTests {
3633
@MockBean
3734
private KafkaTemplate<String, String> kafkaTemplate;
3835

36+
public static String asJsonString(final Object obj) {
37+
try {
38+
return new ObjectMapper().writeValueAsString(obj);
39+
} catch (Exception e) {
40+
throw new RuntimeException(e);
41+
}
42+
}
43+
3944
@Test
4045
public void createReviewShouldReturnTheGivenReviewBack() throws Exception {
4146
String userId = "3";
@@ -102,14 +107,6 @@ public void createReviewShouldReturnBadRequestSinceAllFieldsDoNotExist() throws
102107
.andExpect(status().isBadRequest());
103108
}
104109

105-
public static String asJsonString(final Object obj) {
106-
try {
107-
return new ObjectMapper().writeValueAsString(obj);
108-
} catch (Exception e) {
109-
throw new RuntimeException(e);
110-
}
111-
}
112-
113110
private String getTimeStringFormatted(Timestamp time) {
114111
String timeStringFormatted;
115112
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

0 commit comments

Comments
 (0)