Skip to content

Commit 9490e93

Browse files
committed
random name generation
1 parent bc1d948 commit 9490e93

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/main/java/scorekeep/UserFactory.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.io.InputStream;
1313
import java.util.List;
1414
import java.util.Map;
15+
import java.util.ArrayList;
16+
import java.util.Random;
1517

1618
public 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

Comments
 (0)