Skip to content

Commit 3a38ffe

Browse files
committed
TestObjects: return random values from more methods.
Addressed to #300 No functional changes.
1 parent 1918232 commit 3a38ffe

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

src/test/java/ru/mystamps/web/service/TestObjects.java

+27-27
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import ru.mystamps.web.util.SlugUtils;
3939

4040
import static io.qala.datagen.RandomShortApi.bool;
41+
import static io.qala.datagen.RandomShortApi.nullOr;
4142

4243
public final class TestObjects {
4344
public static final String TEST_ACTIVITY_TYPE = "EventType";
@@ -54,8 +55,6 @@ public final class TestObjects {
5455
protected static final String TEST_PASSWORD = "secret";
5556

5657
private static final String TEST_NAME = "Test Name";
57-
private static final String TEST_LOGIN = "test";
58-
5958
private static final String TEST_URL = "test.example.org";
6059
private static final BigDecimal TEST_PRICE = new BigDecimal("100.99");
6160

@@ -72,7 +71,7 @@ public static UsersActivationFullDto createUsersActivationFullDto() {
7271
UsersActivationFullDto activation = new UsersActivationFullDto(
7372
TEST_ACTIVATION_KEY,
7473
TEST_EMAIL,
75-
new Date()
74+
Random.date()
7675
);
7776
return activation;
7877
}
@@ -87,27 +86,25 @@ public static LinkEntityDto createLinkEntityDto() {
8786

8887
public static AddUserDbDto createAddUserDbDto() {
8988
AddUserDbDto user = new AddUserDbDto();
90-
user.setLogin(TEST_LOGIN);
89+
user.setLogin(Random.login());
9190
user.setRole(UserDetails.Role.USER);
9291
user.setName(TEST_NAME);
9392
user.setEmail(TEST_EMAIL);
94-
user.setRegisteredAt(new Date());
95-
user.setActivatedAt(new Date());
93+
user.setRegisteredAt(Random.date());
94+
user.setActivatedAt(Random.date());
9695
user.setHash(TEST_HASH);
9796

9897
return user;
9998
}
10099

101100
public static UserDetails createUserDetails() {
102-
String collectionSlug = TEST_LOGIN;
103-
104101
return new UserDetails(
105102
Random.userId(),
106-
TEST_LOGIN,
103+
Random.login(),
107104
TEST_NAME,
108105
TEST_HASH,
109106
UserDetails.Role.USER,
110-
collectionSlug
107+
Random.collectionSlug()
111108
);
112109
}
113110

@@ -120,18 +117,21 @@ public static DbImageDto createDbImageDto() {
120117
}
121118

122119
public static SitemapInfoDto createSitemapInfoDto() {
123-
return new SitemapInfoDto(Random.id(), new Date());
120+
return new SitemapInfoDto(Random.id(), Random.date());
124121
}
125122

126123
@SuppressWarnings("checkstyle:magicnumber")
127124
public static SeriesInfoDto createSeriesInfoDto() {
125+
String category = Random.categoryName();
126+
String country = Random.countryName();
127+
128128
return new SeriesInfoDto(
129129
Random.id(),
130-
new LinkEntityDto(Random.id(), "test-category", "Test Category"),
131-
new LinkEntityDto(Random.id(), "test-country", "Test Country"),
130+
new LinkEntityDto(Random.id(), SlugUtils.slugify(category), category),
131+
new LinkEntityDto(Random.id(), SlugUtils.slugify(country), country),
132132
15, 10, Random.issueYear(),
133133
16,
134-
bool()
134+
Random.perforated()
135135
);
136136
}
137137

@@ -146,17 +146,17 @@ public static SeriesFullInfoDto createSeriesFullInfoDto() {
146146
info.getPerforated(),
147147
"this is a full info",
148148
Random.userId(),
149-
TEST_PRICE,
150-
TEST_PRICE,
151-
TEST_PRICE,
152-
TEST_PRICE,
153-
Random.price(),
154-
Random.price()
149+
nullOr(Random.price()),
150+
nullOr(Random.price()),
151+
nullOr(Random.price()),
152+
nullOr(Random.price()),
153+
nullOr(Random.price()),
154+
nullOr(Random.price())
155155
);
156156
}
157157

158158
public static CollectionInfoDto createCollectionInfoDto() {
159-
return new CollectionInfoDto(Random.id(), "test-user", "Test User");
159+
return new CollectionInfoDto(Random.id(), Random.collectionSlug(), "Test User");
160160
}
161161

162162
public static SeriesInCollectionWithPriceDto createSeriesInCollectionWithPriceDto() {
@@ -190,16 +190,16 @@ public static SuspiciousActivityDto createSuspiciousActivityDto() {
190190
*/
191191
public static PurchaseAndSaleDto createPurchaseAndSaleDto() {
192192
return new PurchaseAndSaleDto(
193-
new Date(),
193+
Random.date(),
194194
TEST_NAME,
195195
TEST_URL,
196196
TEST_NAME,
197197
TEST_URL,
198198
TEST_URL,
199-
TEST_PRICE,
200-
Currency.RUB,
201-
TEST_PRICE,
202-
Currency.USD
199+
Random.price(),
200+
Random.currency(),
201+
Random.price(),
202+
Random.currency()
203203
);
204204
}
205205

@@ -208,7 +208,7 @@ public static EntityWithIdDto createEntityWithIdDto() {
208208
}
209209

210210
public static ImportRequestDto createImportRequestDto() {
211-
return new ImportRequestDto(Random.url(), Random.importRequestStatus(), null);
211+
return new ImportRequestDto(Random.url(), Random.importRequestStatus(), Random.id());
212212
}
213213

214214
public static SeriesParsedDataDto createSeriesParsedDataDto() {

src/test/java/ru/mystamps/web/tests/Random.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import ru.mystamps.web.util.SlugUtils;
4444
import ru.mystamps.web.validation.ValidationRules;
4545

46+
import static io.qala.datagen.RandomElements.from;
4647
import static io.qala.datagen.RandomShortApi.bool;
4748
import static io.qala.datagen.RandomShortApi.integer;
4849
import static io.qala.datagen.RandomShortApi.sample;
@@ -88,7 +89,7 @@ public static Date date() {
8889

8990
public static BigDecimal price() {
9091
// @todo #769 Random.price(): return randomized values
91-
return new BigDecimal("17");
92+
return from(new BigDecimal("17"), new BigDecimal("100.99")).sample();
9293
}
9394

9495
public static String login() {

0 commit comments

Comments
 (0)