1212import java .io .InputStream ;
1313import java .util .List ;
1414import java .util .Map ;
15+ import java .util .ArrayList ;
16+ import java .util .Random ;
1517
1618public class UserFactory {
1719 private final UserModel model = new UserModel ();
@@ -36,22 +38,21 @@ public User newUser(String name) throws IOException {
3638 return user ;
3739 }
3840
39- public String randomName () throws IOException {
40- CloseableHttpClient httpclient = HttpClientBuilder .create ().build ();
41- HttpGet httpGet = new HttpGet ("http://uinames.com/api/" );
42- CloseableHttpResponse response = httpclient .execute (httpGet );
43- try {
44- HttpEntity entity = response .getEntity ();
45- InputStream inputStream = entity .getContent ();
46- ObjectMapper mapper = new ObjectMapper ();
47- Map <String , String > jsonMap = mapper .readValue (inputStream , Map .class );
48- String name = jsonMap .get ("name" );
49- EntityUtils .consume (entity );
50- Sns .sendNotification ("Scorekeep user created" , "Name: " + name );
51- return name ;
52- } finally {
53- response .close ();
54- }
41+ public String randomName () {
42+ List <String > names = new ArrayList <String >();
43+
44+ names .add ("Billy" );
45+ names .add ("Jake" );
46+ names .add ("Emma" );
47+ names .add ("Ralph" );
48+ names .add ("Lucy" );
49+
50+ Random random = new Random ();
51+ int index = random .nextInt (names .size ());
52+ String name = names .get (index );
53+
54+ Sns .sendNotification ("Scorekeep user created" , "Name: " + name );
55+ return name ;
5556 }
5657
5758 public User getUser (String userId ) throws UserNotFoundException {
0 commit comments