global: cleanup code style

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2020-03-30 13:57:43 -06:00
parent 10e910186e
commit d74b988f75
18 changed files with 69 additions and 57 deletions
@@ -18,9 +18,11 @@ import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class BadConfigExceptionTest {
private static final Map<String, InputStream> CONFIG_MAP = new HashMap<>();
private static final String[] CONFIG_NAMES = {
"invalid-key",
"invalid-number",
@@ -31,14 +33,6 @@ public class BadConfigExceptionTest {
"unknown-attribute",
"unknown-section"
};
private static final Map<String, InputStream> CONFIG_MAP = new HashMap<>();
@BeforeClass
public static void readConfigs() {
for (final String config: CONFIG_NAMES) {
CONFIG_MAP.put(config, BadConfigExceptionTest.class.getClassLoader().getResourceAsStream(config + ".conf"));
}
}
@AfterClass
public static void closeStreams() {
@@ -50,6 +44,13 @@ public class BadConfigExceptionTest {
}
}
@BeforeClass
public static void readConfigs() {
for (final String config : CONFIG_NAMES) {
CONFIG_MAP.put(config, BadConfigExceptionTest.class.getClassLoader().getResourceAsStream(config + ".conf"));
}
}
@Test
public void throws_correctly_with_INVALID_KEY_reason() {
try {
@@ -5,7 +5,6 @@
package com.wireguard.config;
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.IOException;
@@ -15,8 +14,20 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class ConfigTest {
@Test(expected = BadConfigException.class)
public void invalid_config_throws() throws IOException, BadConfigException {
try (final InputStream is = Objects.requireNonNull(getClass().getClassLoader()).getResourceAsStream("broken.conf")) {
Config.parse(is);
}
}
@Test
public void valid_config_parses_correctly() throws IOException, ParseException {
Config config = null;
@@ -35,11 +46,4 @@ public class ConfigTest {
assertEquals("Test config's allowed IPs are 0.0.0.0/0 and ::0/0", config.getPeers().get(0).getAllowedIps(), expectedAllowedIps);
assertEquals("Test config has one DNS server", 1, config.getInterface().getDnsServers().size());
}
@Test(expected = BadConfigException.class)
public void invalid_config_throws() throws IOException, BadConfigException {
try (final InputStream is = Objects.requireNonNull(getClass().getClassLoader()).getResourceAsStream("broken.conf")) {
Config.parse(is);
}
}
}