-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestDataSupport.java
More file actions
126 lines (106 loc) · 4.06 KB
/
TestDataSupport.java
File metadata and controls
126 lines (106 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package util;
import com.news_articles.domain.Article;
import com.news_articles.model.ArticleDto;
import com.news_articles.model.ArticlesDto;
import java.util.ArrayList;
import java.util.List;
public class TestDataSupport {
public static final String SPORT = "sport";
public static final String BUSINESS = "business";
public static final String ART = "art";
public static final String ENTERTAINMENT = "entertainment";
/**
* This test support class creates dummy test data for the final task.
* Each of the Articles has a title, category and shareCount
* The shareCount is the number of times a user has shared an article
* A category with the most shareCount would be the user's favourite
*/
public static ArticlesDto createRequestData() {
var userID = TestSupportRandom.randomString();
List<ArticleDto> sport = new ArrayList<>();
int increment = 10;
for (int i = 0; i < 5; i++) {
sport.add(ArticleDto.builder()
.title(TestSupportRandom.randomString())
.category(SPORT)
.shareCount(i + increment)
.build());
}
List<ArticleDto> business = new ArrayList<>();
increment = 20;
for (int i = 0; i < 4; i++) {
business.add(ArticleDto.builder()
.title(TestSupportRandom.randomString())
.category(BUSINESS)
.shareCount(i + increment)
.build());
}
List<ArticleDto> art = new ArrayList<>();
increment = 30;
for (int i = 0; i < 3; i++) {
art.add(ArticleDto.builder()
.title(TestSupportRandom.randomString())
.category(ART)
.shareCount(i + increment)
.build());
}
List<ArticleDto> entertainment = new ArrayList<>();
increment = 40;
for (int i = 0; i < 2; i++) {
entertainment.add(ArticleDto.builder()
.title(TestSupportRandom.randomString())
.category(ART)
.shareCount(i + increment)
.build());
}
List<ArticleDto> articleDtos = new ArrayList<>();
articleDtos.addAll(sport);
articleDtos.addAll(business);
articleDtos.addAll(art);
articleDtos.addAll(entertainment);
return ArticlesDto.builder()
.userID(userID)
.articleDtos(articleDtos)
.build();
}
public static List<Article> createArticles() {
List<Article> sports = new ArrayList<>();
for (int i = 0; i < 5; i++) {
sports.add(Article.builder()
.title(TestSupportRandom.randomString())
.category(SPORT)
.shareCount(TestSupportRandom.randomInt())
.build());
}
List<Article> businesses = new ArrayList<>();
for (int i = 0; i < 4; i++) {
businesses.add(Article.builder()
.title(TestSupportRandom.randomString())
.category(BUSINESS)
.shareCount(TestSupportRandom.randomInt())
.build());
}
List<Article> arts = new ArrayList<>();
for (int i = 0; i < 3; i++) {
arts.add(Article.builder()
.title(TestSupportRandom.randomString())
.category(ART)
.shareCount(TestSupportRandom.randomInt())
.build());
}
List<Article> entertainments = new ArrayList<>();
for (int i = 0; i < 2; i++) {
entertainments.add(Article.builder()
.title(TestSupportRandom.randomString())
.category(ENTERTAINMENT)
.shareCount(TestSupportRandom.randomInt())
.build());
}
List<Article> categories = new ArrayList<>();
categories.addAll(sports);
categories.addAll(businesses);
categories.addAll(arts);
categories.addAll(entertainments);
return categories;
}
}