Skip to content

Commit

Permalink
Added two MockUnits:
Browse files Browse the repository at this point in the history
- One that cycles through a collection / array.
- One that returns an arbitrary CityName
  • Loading branch information
nomemory authored and Ciobanu, Andrei-Nicolin (UK - EDC) committed May 22, 2017
1 parent 66bfe98 commit 0210038
Show file tree
Hide file tree
Showing 8 changed files with 20,508 additions and 32 deletions.
10 changes: 9 additions & 1 deletion src/main/java/net/andreinc/mockneat/MockNeat.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/

import net.andreinc.mockneat.abstraction.*;
import net.andreinc.mockneat.types.enums.DictType;
import net.andreinc.mockneat.types.enums.RandomType;
import net.andreinc.mockneat.unit.address.Cities;
import net.andreinc.mockneat.unit.address.Countries;
import net.andreinc.mockneat.unit.companies.Departments;
import net.andreinc.mockneat.unit.financial.*;
Expand Down Expand Up @@ -59,6 +61,7 @@ public class MockNeat {
private final Random random;

private final Bools rBools;
private final Cities rCities;
private final Countries rCountries;
private final CreditCards rCCS;
private final Chars rChars;
Expand Down Expand Up @@ -100,6 +103,7 @@ public MockNeat(RandomType randomTypeType) {
this.rBools = new Bools(this);
this.rCountries = new Countries(this);
this.rCCS = new CreditCards(this);
this.rCities = new Cities(this);
this.rCurrencies = new Currencies(this);
this.rCVVS = new CVVS(this);
this.rDays = new Days(this);
Expand Down Expand Up @@ -149,6 +153,8 @@ public MockNeat(RandomType randomTypeType, Long seed) {

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

public Cities cities() { return this.rCities; }

public CreditCards creditCards() {
return this.rCCS;
}
Expand Down Expand Up @@ -231,7 +237,9 @@ public <T, FT> Factory<T, FT> factory(Class<T> targetCls, Class<FT> factoryCls)

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

public <T> Seq<T> seq(Iterable<T> iterable) { return new Seq(iterable); }
public <T> Seq<T> seq(Iterable<T> iterable) { return Seq.fromIterable(iterable); }

public Seq<String> seq(DictType dictType) { return Seq.fromDict(dictType); }

public Shufflers shufflers() { return rShufflers; }

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/andreinc/mockneat/types/enums/DictType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public enum DictType {
COUNTRY_NAME("country-name"),
COUNTRY_ISO_CODE_2("country-iso-code-2"),

// CITIES
CITIES_US("cities/cities-us"),
CITIES_CAPITALS("cities/cities-capitals"),

// DOMAINS
DOMAIN_EMAIL("domain-email"),
DOMAIN_TOP_LEVEL_ALL("domain-top-level-all"),
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/net/andreinc/mockneat/unit/address/Cities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.andreinc.mockneat.unit.address;

import net.andreinc.mockneat.MockNeat;
import net.andreinc.mockneat.abstraction.MockUnitBase;
import net.andreinc.mockneat.abstraction.MockUnitString;
import net.andreinc.mockneat.types.enums.DictType;

/**
* Copyright 2017, Andrei N. Ciobanu
Permission is hereby granted, free of charge, to any user obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. PARAM NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER PARAM AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, FREE_TEXT OF OR PARAM CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS PARAM THE SOFTWARE.
*/

//TODO document and unit tests
public class Cities extends MockUnitBase {

public Cities(MockNeat mockNeat) {
super(mockNeat);
}

public MockUnitString capitals() {
return () -> mockNeat.dicts().type(DictType.CITIES_CAPITALS).supplier();
}

public MockUnitString us() {
return () -> mockNeat.dicts().type(DictType.CITIES_US).supplier();
}
}
25 changes: 22 additions & 3 deletions src/main/java/net/andreinc/mockneat/unit/seq/Seq.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/

import net.andreinc.mockneat.abstraction.MockUnit;
import net.andreinc.mockneat.types.enums.DictType;
import net.andreinc.mockneat.utils.file.FileManager;

import java.util.Iterator;
import java.util.List;
import java.util.function.Supplier;

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

private boolean cycle = false;
private T after = null;
private Supplier<T> after = null;

public Seq(Iterable<T> iterable) {
public static Seq<String> fromDict(DictType dictType) {
notNull(dictType, "dictType");
List<String> lines = FileManager.getInstance().getLines(dictType);
return new Seq<>(lines);
}

public static <R> Seq<R> fromIterable(Iterable<R> iterable) {
return new Seq<>(iterable);
}

private Seq(Iterable<T> iterable) {

notNull(iterable, "iterable");

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

public Seq<T> after(T after) {
this.after = after;
this.after = () -> after;
return this;
}

public Seq<T> after(MockUnit<T> after) {
this.after = after.supplier();
return this;
}

Expand All @@ -68,4 +86,5 @@ public Supplier<T> supplier() {
return(T) after;
};
}

}
8 changes: 8 additions & 0 deletions src/main/java/net/andreinc/mockneat/unit/text/Dicts.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.andreinc.mockneat.types.enums.DictType;
import net.andreinc.mockneat.utils.file.FileManager;

import static net.andreinc.mockneat.utils.ValidationUtils.notEmptyOrNullValues;
import static net.andreinc.mockneat.utils.ValidationUtils.notNull;

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

public MockUnitString types(DictType... types) {
notEmptyOrNullValues(types, "types");
return () -> {
DictType type = mockNeat.from(types).val();
return mockNeat.fromStrings(fm.getLines(type))::val;
};
}
}
202 changes: 202 additions & 0 deletions src/main/resources/dicts/cities/cities-capitals
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
Abu Dhabi
Abuja
Accra
Addis Ababa
Amman
Amsterdam
Andorra la Vella
Ankara
Ankara
Antananarivo
Apia
Asgabat
Asmara
Astana
Asuncion
Athens
Baghdad
Baku
Bamako
Bandar Seri Begawan
Bangkok
Bangui
Banjul
Basseterre
Beijing
Beirut
Belgrade
Belmopan
Berlin
Bern
Bishkek
Bogotá
Brasília
Bratislava
Brazzaville
Bridgetown
Brussels
Bucharest
Budapest
Buenos Aires
Bujumbura
Cairo
Canberra
Caracas
Castries
Cayenne
Chisinau
Cockburn Town
Conakry
Copenhagen
Dakar
Damascus
Dar es Salaam
Dhaka
Dili
Djibouti
Doha
Dublin
Dushanbe
Freetown
Funafuti
Gaborone
George Town
Georgetown
Guatemala
Hanoi
Harare
Havana
Helsinki
Honiara
Islamabad
Jakarta
Jerusalem
Jerusalem
Juba
Kabul
Kampala
Kathmandu
Khartoum
Kigali
Kingston
Kingstown
Kinshasa
Koror
Kuala Lumpur
Kuwait
Kyiv or Kiev
La Paz and Sucre
La’youn
Libreville
Lilongwe
Lima
Lisbon
Ljubljana
Lome
London
Luanda
Lusaka
Luxembourg City
Madrid
Majuro
Malabo
Malé
Managua
Manama
Manila
Maputo
Maseru
Mbabane
Mexico City
Minsk
Mogadishu
Monaco
Monrovia
Montevideo
Moroni
Moscow
Moscow
Muscat
Nairobi
Nassau
Naypyidaw
New Delhi
Niamey
Nicosia
Nouakchott
Nuku’alofa
N’Djamena
Oslo
Ottawa
Ouagadougou
Palikir
Panama City
Paramaribo
Paris
Phnom Penh
Podgorica
Port Louis
Port Moresby
Port Vila
Port of Spain
Port-au-Prince
Porto Novo
Prague
Praia
Pretoria
Pyongyang
Quito
Rabat
Reykjavik
Riga
Riyadh
Rome
Roseau
San José
San Juan
San Marino
San Salvador
Sana’a
Santiago
Santo Domingo
Sarajevo
Seoul
Singapore
Skopje
Sofia
South Tarawa
Sri Jayawardenapura Kotte and Colombo now
St George’s
St. John’s
Stockholm
Suva
São Tomé
Taipei
Taipei
Tallinn
Tashkent
Tbilisi
Tegucigalpa
Tehran
Thimphu
Tirana
Tokyo
Tripoli
Tunis
Ulaanbaatar
Vaduz
Valletta
Vatican City
Victoria
Vienna
Vientiane
Vilnius
Warsaw
Washington DC
Wellington
Windhoek
Yamoussoukro
Yaoundé
Yaren
Yerevan
Zagreb
Loading

0 comments on commit 0210038

Please sign in to comment.