Skip to content

Commit 0210038

Browse files
nomemoryCiobanu, Andrei-Nicolin (UK - EDC)
authored andcommitted
Added two MockUnits:
- One that cycles through a collection / array. - One that returns an arbitrary CityName
1 parent 66bfe98 commit 0210038

File tree

8 files changed

+20508
-32
lines changed

8 files changed

+20508
-32
lines changed

src/main/java/net/andreinc/mockneat/MockNeat.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
*/
1919

2020
import net.andreinc.mockneat.abstraction.*;
21+
import net.andreinc.mockneat.types.enums.DictType;
2122
import net.andreinc.mockneat.types.enums.RandomType;
23+
import net.andreinc.mockneat.unit.address.Cities;
2224
import net.andreinc.mockneat.unit.address.Countries;
2325
import net.andreinc.mockneat.unit.companies.Departments;
2426
import net.andreinc.mockneat.unit.financial.*;
@@ -59,6 +61,7 @@ public class MockNeat {
5961
private final Random random;
6062

6163
private final Bools rBools;
64+
private final Cities rCities;
6265
private final Countries rCountries;
6366
private final CreditCards rCCS;
6467
private final Chars rChars;
@@ -100,6 +103,7 @@ public MockNeat(RandomType randomTypeType) {
100103
this.rBools = new Bools(this);
101104
this.rCountries = new Countries(this);
102105
this.rCCS = new CreditCards(this);
106+
this.rCities = new Cities(this);
103107
this.rCurrencies = new Currencies(this);
104108
this.rCVVS = new CVVS(this);
105109
this.rDays = new Days(this);
@@ -149,6 +153,8 @@ public MockNeat(RandomType randomTypeType, Long seed) {
149153

150154
public Chars chars() { return this.rChars; }
151155

156+
public Cities cities() { return this.rCities; }
157+
152158
public CreditCards creditCards() {
153159
return this.rCCS;
154160
}
@@ -231,7 +237,9 @@ public <T, FT> Factory<T, FT> factory(Class<T> targetCls, Class<FT> factoryCls)
231237

232238
public <T> Reflect<T> reflect(Class<T> cls) { return new Reflect<>(this, cls);}
233239

234-
public <T> Seq<T> seq(Iterable<T> iterable) { return new Seq(iterable); }
240+
public <T> Seq<T> seq(Iterable<T> iterable) { return Seq.fromIterable(iterable); }
241+
242+
public Seq<String> seq(DictType dictType) { return Seq.fromDict(dictType); }
235243

236244
public Shufflers shufflers() { return rShufflers; }
237245

src/main/java/net/andreinc/mockneat/types/enums/DictType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public enum DictType {
2323
COUNTRY_NAME("country-name"),
2424
COUNTRY_ISO_CODE_2("country-iso-code-2"),
2525

26+
// CITIES
27+
CITIES_US("cities/cities-us"),
28+
CITIES_CAPITALS("cities/cities-capitals"),
29+
2630
// DOMAINS
2731
DOMAIN_EMAIL("domain-email"),
2832
DOMAIN_TOP_LEVEL_ALL("domain-top-level-all"),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.andreinc.mockneat.unit.address;
2+
3+
import net.andreinc.mockneat.MockNeat;
4+
import net.andreinc.mockneat.abstraction.MockUnitBase;
5+
import net.andreinc.mockneat.abstraction.MockUnitString;
6+
import net.andreinc.mockneat.types.enums.DictType;
7+
8+
/**
9+
* Copyright 2017, Andrei N. Ciobanu
10+
11+
Permission is hereby granted, free of charge, to any user obtaining a copy of this software and associated
12+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
13+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
14+
persons to whom the Software is furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
17+
Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. PARAM NO EVENT SHALL THE AUTHORS OR
21+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER PARAM AN ACTION OF CONTRACT, TORT OR
22+
OTHERWISE, ARISING FROM, FREE_TEXT OF OR PARAM CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS PARAM THE SOFTWARE.
23+
*/
24+
25+
//TODO document and unit tests
26+
public class Cities extends MockUnitBase {
27+
28+
public Cities(MockNeat mockNeat) {
29+
super(mockNeat);
30+
}
31+
32+
public MockUnitString capitals() {
33+
return () -> mockNeat.dicts().type(DictType.CITIES_CAPITALS).supplier();
34+
}
35+
36+
public MockUnitString us() {
37+
return () -> mockNeat.dicts().type(DictType.CITIES_US).supplier();
38+
}
39+
}

src/main/java/net/andreinc/mockneat/unit/seq/Seq.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
*/
1919

2020
import net.andreinc.mockneat.abstraction.MockUnit;
21+
import net.andreinc.mockneat.types.enums.DictType;
22+
import net.andreinc.mockneat.utils.file.FileManager;
2123

2224
import java.util.Iterator;
25+
import java.util.List;
2326
import java.util.function.Supplier;
2427

2528
import static net.andreinc.mockneat.utils.ValidationUtils.*;
@@ -32,9 +35,19 @@ public class Seq<T> implements MockUnit<T> {
3235
private Iterator<T> iterator;
3336

3437
private boolean cycle = false;
35-
private T after = null;
38+
private Supplier<T> after = null;
3639

37-
public Seq(Iterable<T> iterable) {
40+
public static Seq<String> fromDict(DictType dictType) {
41+
notNull(dictType, "dictType");
42+
List<String> lines = FileManager.getInstance().getLines(dictType);
43+
return new Seq<>(lines);
44+
}
45+
46+
public static <R> Seq<R> fromIterable(Iterable<R> iterable) {
47+
return new Seq<>(iterable);
48+
}
49+
50+
private Seq(Iterable<T> iterable) {
3851

3952
notNull(iterable, "iterable");
4053

@@ -50,7 +63,12 @@ public Seq<T> cycle(boolean value) {
5063
}
5164

5265
public Seq<T> after(T after) {
53-
this.after = after;
66+
this.after = () -> after;
67+
return this;
68+
}
69+
70+
public Seq<T> after(MockUnit<T> after) {
71+
this.after = after.supplier();
5472
return this;
5573
}
5674

@@ -68,4 +86,5 @@ public Supplier<T> supplier() {
6886
return(T) after;
6987
};
7088
}
89+
7190
}

src/main/java/net/andreinc/mockneat/unit/text/Dicts.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import net.andreinc.mockneat.types.enums.DictType;
2424
import net.andreinc.mockneat.utils.file.FileManager;
2525

26+
import static net.andreinc.mockneat.utils.ValidationUtils.notEmptyOrNullValues;
2627
import static net.andreinc.mockneat.utils.ValidationUtils.notNull;
2728

2829
public class Dicts extends MockUnitBase {
@@ -38,4 +39,11 @@ public MockUnitString type(DictType type) {
3839
return () -> mockNeat.fromStrings(fm.getLines(type))::val;
3940
}
4041

42+
public MockUnitString types(DictType... types) {
43+
notEmptyOrNullValues(types, "types");
44+
return () -> {
45+
DictType type = mockNeat.from(types).val();
46+
return mockNeat.fromStrings(fm.getLines(type))::val;
47+
};
48+
}
4149
}
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
Abu Dhabi
2+
Abuja
3+
Accra
4+
Addis Ababa
5+
Amman
6+
Amsterdam
7+
Andorra la Vella
8+
Ankara
9+
Ankara
10+
Antananarivo
11+
Apia
12+
Asgabat
13+
Asmara
14+
Astana
15+
Asuncion
16+
Athens
17+
Baghdad
18+
Baku
19+
Bamako
20+
Bandar Seri Begawan
21+
Bangkok
22+
Bangui
23+
Banjul
24+
Basseterre
25+
Beijing
26+
Beirut
27+
Belgrade
28+
Belmopan
29+
Berlin
30+
Bern
31+
Bishkek
32+
Bogotá
33+
Brasília
34+
Bratislava
35+
Brazzaville
36+
Bridgetown
37+
Brussels
38+
Bucharest
39+
Budapest
40+
Buenos Aires
41+
Bujumbura
42+
Cairo
43+
Canberra
44+
Caracas
45+
Castries
46+
Cayenne
47+
Chisinau
48+
Cockburn Town
49+
Conakry
50+
Copenhagen
51+
Dakar
52+
Damascus
53+
Dar es Salaam
54+
Dhaka
55+
Dili
56+
Djibouti
57+
Doha
58+
Dublin
59+
Dushanbe
60+
Freetown
61+
Funafuti
62+
Gaborone
63+
George Town
64+
Georgetown
65+
Guatemala
66+
Hanoi
67+
Harare
68+
Havana
69+
Helsinki
70+
Honiara
71+
Islamabad
72+
Jakarta
73+
Jerusalem
74+
Jerusalem
75+
Juba
76+
Kabul
77+
Kampala
78+
Kathmandu
79+
Khartoum
80+
Kigali
81+
Kingston
82+
Kingstown
83+
Kinshasa
84+
Koror
85+
Kuala Lumpur
86+
Kuwait
87+
Kyiv or Kiev
88+
La Paz and Sucre
89+
La’youn
90+
Libreville
91+
Lilongwe
92+
Lima
93+
Lisbon
94+
Ljubljana
95+
Lome
96+
London
97+
Luanda
98+
Lusaka
99+
Luxembourg City
100+
Madrid
101+
Majuro
102+
Malabo
103+
Malé
104+
Managua
105+
Manama
106+
Manila
107+
Maputo
108+
Maseru
109+
Mbabane
110+
Mexico City
111+
Minsk
112+
Mogadishu
113+
Monaco
114+
Monrovia
115+
Montevideo
116+
Moroni
117+
Moscow
118+
Moscow
119+
Muscat
120+
Nairobi
121+
Nassau
122+
Naypyidaw
123+
New Delhi
124+
Niamey
125+
Nicosia
126+
Nouakchott
127+
Nuku’alofa
128+
N’Djamena
129+
Oslo
130+
Ottawa
131+
Ouagadougou
132+
Palikir
133+
Panama City
134+
Paramaribo
135+
Paris
136+
Phnom Penh
137+
Podgorica
138+
Port Louis
139+
Port Moresby
140+
Port Vila
141+
Port of Spain
142+
Port-au-Prince
143+
Porto Novo
144+
Prague
145+
Praia
146+
Pretoria
147+
Pyongyang
148+
Quito
149+
Rabat
150+
Reykjavik
151+
Riga
152+
Riyadh
153+
Rome
154+
Roseau
155+
San José
156+
San Juan
157+
San Marino
158+
San Salvador
159+
Sana’a
160+
Santiago
161+
Santo Domingo
162+
Sarajevo
163+
Seoul
164+
Singapore
165+
Skopje
166+
Sofia
167+
South Tarawa
168+
Sri Jayawardenapura Kotte and Colombo now
169+
St George’s
170+
St. John’s
171+
Stockholm
172+
Suva
173+
São Tomé
174+
Taipei
175+
Taipei
176+
Tallinn
177+
Tashkent
178+
Tbilisi
179+
Tegucigalpa
180+
Tehran
181+
Thimphu
182+
Tirana
183+
Tokyo
184+
Tripoli
185+
Tunis
186+
Ulaanbaatar
187+
Vaduz
188+
Valletta
189+
Vatican City
190+
Victoria
191+
Vienna
192+
Vientiane
193+
Vilnius
194+
Warsaw
195+
Washington DC
196+
Wellington
197+
Windhoek
198+
Yamoussoukro
199+
Yaoundé
200+
Yaren
201+
Yerevan
202+
Zagreb

0 commit comments

Comments
 (0)