refactor: final var

This commit is contained in:
ineanto 2023-12-22 14:17:21 +01:00
parent 83bc00aebe
commit 153d666b78
2 changed files with 7 additions and 4 deletions

View file

@ -24,13 +24,13 @@ public class RandomNameFetcher {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource))) {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
String[] values = line.split("\n"); final String[] values = line.split("\n");
records.add(Arrays.asList(values)); records.add(Arrays.asList(values));
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return records.get(new Random().nextInt(records.size() -1)).get(0); return records.get(new Random().nextInt(records.size() - 1)).get(0);
} }
} }

View file

@ -8,8 +8,9 @@ import org.junit.jupiter.api.Test;
import xyz.ineanto.nicko.NickoBukkit; import xyz.ineanto.nicko.NickoBukkit;
import xyz.ineanto.nicko.appearance.random.RandomNameFetcher; import xyz.ineanto.nicko.appearance.random.RandomNameFetcher;
import xyz.ineanto.nicko.config.Configuration; import xyz.ineanto.nicko.config.Configuration;
import xyz.ineanto.nicko.mojang.MojangUtils;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.*;
public class RandomNameTest { public class RandomNameTest {
private static NickoBukkit plugin; private static NickoBukkit plugin;
@ -25,7 +26,9 @@ public class RandomNameTest {
@DisplayName("Get random name") @DisplayName("Get random name")
public void getRandomName() { public void getRandomName() {
final RandomNameFetcher randomNameFetcher = new RandomNameFetcher(plugin); final RandomNameFetcher randomNameFetcher = new RandomNameFetcher(plugin);
assertNotNull(randomNameFetcher.getRandomUsername()); final String username = randomNameFetcher.getRandomUsername();
assertNotNull(username);
assertFalse(MojangUtils.isUsernameInvalid(username));
} }
@AfterAll @AfterAll