diff options
author | Harald Musum <musum@verizonmedia.com> | 2019-07-24 08:58:03 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2019-07-24 08:58:03 +0200 |
commit | 19a60421f2bcf9cf9e347458720d57a3173dd032 (patch) | |
tree | 4ee4f80c19c9049bec48008990f10d738549bbff /config/src/test | |
parent | 01862bd9cb0608a3cda36800eb73e6dc9bfa5157 (diff) |
Cleanup code, no functional changes
Diffstat (limited to 'config/src/test')
18 files changed, 135 insertions, 135 deletions
diff --git a/config/src/test/java/com/yahoo/config/subscription/AppService.java b/config/src/test/java/com/yahoo/config/subscription/AppService.java index 6c395b12129..0f8d93e6fe0 100644 --- a/config/src/test/java/com/yahoo/config/subscription/AppService.java +++ b/config/src/test/java/com/yahoo/config/subscription/AppService.java @@ -10,25 +10,22 @@ import com.yahoo.vespa.config.TimingValues; * Application that subscribes to config defined in app.def and * generated code in AppConfig.java. */ -public class AppService { - protected int timesConfigured = 0; +class AppService { + private int timesConfigured = 0; - protected AppConfig config = null; + private AppConfig config = null; private final ConfigSubscriber subscriber; - protected final String configId; - final Thread configThread; - boolean stopThread = false; + private boolean stopThread = false; - public AppService(String configId, ConfigSourceSet csource) { + AppService(String configId, ConfigSourceSet csource) { this(configId, csource, null); } - public int timesConfigured() { return timesConfigured; } + int timesConfigured() { return timesConfigured; } - public AppService(String configId, ConfigSourceSet csource, TimingValues timingValues) { + private AppService(String configId, ConfigSourceSet csource, TimingValues timingValues) { if (csource == null) throw new IllegalArgumentException("Config source cannot be null"); - this.configId = configId; subscriber = new ConfigSubscriber(csource); ConfigHandle<AppConfig> temp; if (timingValues == null) { @@ -37,15 +34,12 @@ public class AppService { temp = subscriber.subscribe(AppConfig.class, configId, csource, timingValues); } final ConfigHandle<AppConfig> handle = temp; - configThread = new Thread(new Runnable() { - @Override - public void run() { - while (!stopThread) { - boolean changed = subscriber.nextConfig(500); - if (changed) { - configure(handle.getConfig()); - timesConfigured++; - } + Thread configThread = new Thread(() -> { + while (!stopThread) { + boolean changed = subscriber.nextConfig(500); + if (changed) { + configure(handle.getConfig()); + timesConfigured++; } } }); @@ -56,7 +50,7 @@ public class AppService { configThread.start(); } - public void configure(AppConfig config) { + private void configure(AppConfig config) { this.config = config; } diff --git a/config/src/test/java/com/yahoo/config/subscription/ConfigGetterTest.java b/config/src/test/java/com/yahoo/config/subscription/ConfigGetterTest.java index 731a5f50816..07eeb78f0d9 100644 --- a/config/src/test/java/com/yahoo/config/subscription/ConfigGetterTest.java +++ b/config/src/test/java/com/yahoo/config/subscription/ConfigGetterTest.java @@ -37,6 +37,8 @@ public class ConfigGetterTest { AppConfig serviceConfig = service.getConfig(); assertTrue(service.isConfigured()); assertThat(config, is(serviceConfig)); + + service.cancelSubscription(); } @Test @@ -107,5 +109,7 @@ public class ConfigGetterTest { AppConfig serviceConfig = service.getConfig(); assertTrue(service.isConfigured()); assertThat(config, is(serviceConfig)); + + service.cancelSubscription(); } } diff --git a/config/src/test/java/com/yahoo/config/subscription/ConfigInstanceSerializerTest.java b/config/src/test/java/com/yahoo/config/subscription/ConfigInstanceSerializerTest.java index 0c8af47dccb..ee8682efe3c 100644 --- a/config/src/test/java/com/yahoo/config/subscription/ConfigInstanceSerializerTest.java +++ b/config/src/test/java/com/yahoo/config/subscription/ConfigInstanceSerializerTest.java @@ -25,7 +25,7 @@ import static org.junit.Assert.fail; */ public class ConfigInstanceSerializerTest { @Test - public void test_that_leaf_types_are_serialized_to_json_types() throws IOException { + public void test_that_leaf_types_are_serialized_to_json_types() { SimpletypesConfig.Builder builder = new SimpletypesConfig.Builder(); builder.boolval(false); builder.stringval("foo"); @@ -50,7 +50,7 @@ public class ConfigInstanceSerializerTest { } @Test - public void test_that_nested_structs_are_formatted_to_json() throws IOException { + public void test_that_nested_structs_are_formatted_to_json() { StructtypesConfig.Builder builder = new StructtypesConfig.Builder(); StructtypesConfig.Nested.Builder nestedBuilder = new StructtypesConfig.Nested.Builder(); StructtypesConfig.Nested.Inner.Builder innerBuilder = new StructtypesConfig.Nested.Inner.Builder(); @@ -106,7 +106,7 @@ public class ConfigInstanceSerializerTest { } @Test - public void test_that_arrays_are_formatted_to_json() throws IOException { + public void test_that_arrays_are_formatted_to_json() { ArraytypesConfig.Builder builder = new ArraytypesConfig.Builder(); builder.boolarr(true); builder.boolarr(false); @@ -149,7 +149,7 @@ public class ConfigInstanceSerializerTest { } @Test - public void test_that_maps_are_formatted_to_json() throws IOException { + public void test_that_maps_are_formatted_to_json() { MaptypesConfig.Builder builder = new MaptypesConfig.Builder(); builder.boolmap("foo", true); builder.intmap("bar", 3); @@ -195,7 +195,7 @@ public class ConfigInstanceSerializerTest { } @Test - public void test_that_non_standard_types_are_formatted_as_json_strings() throws IOException { + public void test_that_non_standard_types_are_formatted_as_json_strings() { SpecialtypesConfig.Builder builder = new SpecialtypesConfig.Builder(); builder.myfile("thefilename"); builder.myref("thereference"); diff --git a/config/src/test/java/com/yahoo/config/subscription/ConfigInstanceTest.java b/config/src/test/java/com/yahoo/config/subscription/ConfigInstanceTest.java index e086202eca8..1da53e4c3b9 100644 --- a/config/src/test/java/com/yahoo/config/subscription/ConfigInstanceTest.java +++ b/config/src/test/java/com/yahoo/config/subscription/ConfigInstanceTest.java @@ -34,6 +34,9 @@ public class ConfigInstanceTest { assertEquals(1, service1.timesConfigured()); assertEquals(1, service2.timesConfigured()); + + service1.cancelSubscription(); + service2.cancelSubscription(); } /** @@ -107,11 +110,10 @@ public class ConfigInstanceTest { } private class TestNonstring { - private final ConfigSubscriber subscriber; - private final ConfigHandle<TestNonstringConfig> handle; + public TestNonstring(String configId) { - subscriber = new ConfigSubscriber(); - handle = subscriber.subscribe(TestNonstringConfig.class, configId); + ConfigSubscriber subscriber = new ConfigSubscriber(); + ConfigHandle<TestNonstringConfig> handle = subscriber.subscribe(TestNonstringConfig.class, configId); subscriber.nextConfig(); handle.getConfig(); } diff --git a/config/src/test/java/com/yahoo/config/subscription/ConfigSetSubscriptionTest.java b/config/src/test/java/com/yahoo/config/subscription/ConfigSetSubscriptionTest.java index d17a2ff61f4..21cdfbe7d30 100644 --- a/config/src/test/java/com/yahoo/config/subscription/ConfigSetSubscriptionTest.java +++ b/config/src/test/java/com/yahoo/config/subscription/ConfigSetSubscriptionTest.java @@ -33,8 +33,8 @@ public class ConfigSetSubscriptionTest { configSet, new TimingValues()); - assertTrue(c1.equals(c1)); - assertFalse(c1.equals(c2)); + assertEquals(c1, c1); + assertNotEquals(c1, c2); } @Test(expected = IllegalArgumentException.class) diff --git a/config/src/test/java/com/yahoo/config/subscription/ConfigSourceSetTest.java b/config/src/test/java/com/yahoo/config/subscription/ConfigSourceSetTest.java index b45f30d244d..38d4a6a4571 100755 --- a/config/src/test/java/com/yahoo/config/subscription/ConfigSourceSetTest.java +++ b/config/src/test/java/com/yahoo/config/subscription/ConfigSourceSetTest.java @@ -15,25 +15,24 @@ import static org.junit.Assert.*; public class ConfigSourceSetTest { @Test public void testEquals() { - assertTrue(new ConfigSourceSet().equals(new ConfigSourceSet())); - assertFalse(new ConfigSourceSet().equals(new ConfigSourceSet(new String[]{"a"}))); + assertEquals(new ConfigSourceSet(), new ConfigSourceSet()); + assertNotEquals(new ConfigSourceSet(), new ConfigSourceSet(new String[]{"a"})); - assertTrue(new ConfigSourceSet(new String[]{"a"}).equals(new ConfigSourceSet(new String[]{"a"}))); - assertTrue(new ConfigSourceSet(new String[]{"a"}).equals(new ConfigSourceSet(new String[]{" A "}))); - assertTrue(new ConfigSourceSet(new String[]{"a"}).equals(new ConfigSourceSet(new String[]{"A", "a"}))); - assertTrue(new ConfigSourceSet(new String[]{"A"}).equals(new ConfigSourceSet(new String[]{"a", " a "}))); + assertEquals(new ConfigSourceSet(new String[]{"a"}), new ConfigSourceSet(new String[]{"a"})); + assertEquals(new ConfigSourceSet(new String[]{"a"}), new ConfigSourceSet(new String[]{" A "})); + assertEquals(new ConfigSourceSet(new String[]{"a"}), new ConfigSourceSet(new String[]{"A", "a"})); + assertEquals(new ConfigSourceSet(new String[]{"A"}), new ConfigSourceSet(new String[]{"a", " a "})); - assertFalse(new ConfigSourceSet(new String[]{"a"}).equals(new ConfigSourceSet(new String[]{"b"}))); - assertFalse(new ConfigSourceSet(new String[]{"a"}).equals(new ConfigSourceSet(new String[]{"a", "b"}))); + assertNotEquals(new ConfigSourceSet(new String[]{"a"}), new ConfigSourceSet(new String[]{"b"})); + assertNotEquals(new ConfigSourceSet(new String[]{"a"}), new ConfigSourceSet(new String[]{"a", "b"})); - assertTrue(new ConfigSourceSet(new String[]{"a", "b"}).equals(new ConfigSourceSet(new String[]{"a", "b"}))); - assertTrue(new ConfigSourceSet(new String[]{"b", "a"}).equals(new ConfigSourceSet(new String[]{"a", "b"}))); - assertTrue(new ConfigSourceSet(new String[]{"A", " b"}).equals(new ConfigSourceSet(new String[]{"a ", "B"}))); - assertTrue(new ConfigSourceSet(new String[]{"b", "a", "c"}) - .equals(new ConfigSourceSet(new String[]{"a", "b", "c"}))); + assertEquals(new ConfigSourceSet(new String[]{"a", "b"}), new ConfigSourceSet(new String[]{"a", "b"})); + assertEquals(new ConfigSourceSet(new String[]{"b", "a"}), new ConfigSourceSet(new String[]{"a", "b"})); + assertEquals(new ConfigSourceSet(new String[]{"A", " b"}), new ConfigSourceSet(new String[]{"a ", "B"})); + assertEquals(new ConfigSourceSet(new String[]{"b", "a", "c"}), new ConfigSourceSet(new String[]{"a", "b", "c"})); - assertFalse(new ConfigSourceSet(new String[]{"a", "b"}).equals(new ConfigSourceSet(new String[]{"b", "c"}))); - assertFalse(new ConfigSourceSet().equals("foo")); + assertNotEquals(new ConfigSourceSet(new String[]{"a", "b"}), new ConfigSourceSet(new String[]{"b", "c"})); + assertNotEquals("foo", new ConfigSourceSet()); } @Test diff --git a/config/src/test/java/com/yahoo/config/subscription/ConfigSubscriptionTest.java b/config/src/test/java/com/yahoo/config/subscription/ConfigSubscriptionTest.java index 3aa422eb116..933a9fd130a 100644 --- a/config/src/test/java/com/yahoo/config/subscription/ConfigSubscriptionTest.java +++ b/config/src/test/java/com/yahoo/config/subscription/ConfigSubscriptionTest.java @@ -3,7 +3,6 @@ package com.yahoo.config.subscription; import com.yahoo.config.ConfigInstance; import com.yahoo.config.ConfigurationRuntimeException; -import com.yahoo.config.subscription.impl.GenericConfigHandle; import com.yahoo.foo.SimpletypesConfig; import com.yahoo.foo.AppConfig; import com.yahoo.config.subscription.impl.ConfigSubscription; @@ -59,8 +58,8 @@ public class ConfigSubscriptionTest { configSet, new TimingValues()); - assertTrue(c1.equals(c1)); - assertFalse(c1.equals(c2)); + assertEquals(c1, c1); + assertNotEquals(c1, c2); } @Test diff --git a/config/src/test/java/com/yahoo/config/subscription/FunctionTest.java b/config/src/test/java/com/yahoo/config/subscription/FunctionTest.java index 5c535f6a5fa..b32cdcd8c16 100644 --- a/config/src/test/java/com/yahoo/config/subscription/FunctionTest.java +++ b/config/src/test/java/com/yahoo/config/subscription/FunctionTest.java @@ -178,7 +178,7 @@ public class FunctionTest { } //System.out.println("Config lacking " + param + "-> " + config + "\n"); try { - ConfigGetter<FunctionTestConfig> getter = new ConfigGetter<FunctionTestConfig>(FunctionTestConfig.class); + ConfigGetter<FunctionTestConfig> getter = new ConfigGetter<>(FunctionTestConfig.class); getter.getConfig("raw:\n" + config); if (isArray) { // Arrays are empty by default @@ -210,7 +210,7 @@ public class FunctionTest { assertEquals(1, config.boolarr().size()); assertEquals(1, config.boolarr().size()); // new api with accessor for a List of the original Java type assertEquals(false, config.boolarr().get(0)); // new List api - assertEquals(false, config.boolarr(0)); // short-hand + assertFalse(config.boolarr(0)); // short-hand assertEquals(0, config.intarr().size()); assertEquals(2, config.longarr().size()); assertEquals(Long.MAX_VALUE, config.longarr(0)); @@ -239,9 +239,9 @@ public class FunctionTest { assertEquals("inner1", config.rootStruct().inner1().name()); assertEquals(12, config.rootStruct().inner1().index()); assertEquals(2, config.rootStruct().innerArr().size()); - assertEquals(true, config.rootStruct().innerArr(0).boolVal()); + assertTrue(config.rootStruct().innerArr(0).boolVal()); assertEquals("deep", config.rootStruct().innerArr(0).stringVal()); - assertEquals(false, config.rootStruct().innerArr(1).boolVal()); + assertFalse(config.rootStruct().innerArr(1).boolVal()); assertEquals("blue a=\"escaped\"", config.rootStruct().innerArr(1).stringVal()); assertEquals(2, config.myarray().size()); // new List api diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigBuilderMergeTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigBuilderMergeTest.java index c1e5cfb8f0f..c77985c91d8 100644 --- a/config/src/test/java/com/yahoo/vespa/config/ConfigBuilderMergeTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/ConfigBuilderMergeTest.java @@ -82,10 +82,10 @@ public class ConfigBuilderMergeTest { public void require_that_struct_fields_are_overwritten() { String name1 = "foo"; String gender1 = "MALE"; - String emails1[] = { "foo@bar", "bar@foo" }; + String[] emails1 = {"foo@bar", "bar@foo"}; String name2 = "bar"; String gender2 = "FEMALE"; - String emails2[] = { "foo@bar", "bar@foo" }; + String[] emails2 = {"foo@bar", "bar@foo"}; StructtypesConfig.Builder b1 = createSimpleStructBuilder(name1, gender1, emails1); StructtypesConfig.Builder b2 = createSimpleStructBuilder(name2, gender2, emails2); ConfigInstanceUtil.setValues(b1, b2); diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigCacheKeyTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigCacheKeyTest.java index bb4505b1250..bb65fdaa153 100755 --- a/config/src/test/java/com/yahoo/vespa/config/ConfigCacheKeyTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/ConfigCacheKeyTest.java @@ -24,11 +24,11 @@ public class ConfigCacheKeyTest { ConfigCacheKey k5 = new ConfigCacheKey("foo", "id", "ns_1", null); // test with null defMd5 final ConfigKey<?> configKey = new ConfigKey<>("foo", "id", "ns"); ConfigCacheKey k1_2 = new ConfigCacheKey(configKey, defMd5); - assertTrue(k1.equals(k1)); - assertTrue(k1.equals(k1_2)); - assertTrue(k1.equals(k2)); - assertFalse(k3.equals(k2)); - assertFalse(k4.equals(k1)); + assertEquals(k1, k1); + assertEquals(k1, k1_2); + assertEquals(k1, k2); + assertNotEquals(k3, k2); + assertNotEquals(k4, k1); assertThat(k1.hashCode(), is(k2.hashCode())); assertThat(k1.getDefMd5(), is(defMd5)); assertThat(k1.toString(), is(configKey.toString() + "," + defMd5)); diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionBuilderTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionBuilderTest.java index f1220143b28..dba73223097 100644 --- a/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionBuilderTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionBuilderTest.java @@ -26,7 +26,7 @@ public class ConfigDefinitionBuilderTest { @Test // TODO Test ranges - public void testCreateConfigDefinition() throws IOException, InterruptedException { + public void testCreateConfigDefinition() throws IOException { File defFile = new File(DEF_NAME); DefParser defParser = new DefParser(defFile.getName(), new FileReader(defFile)); CNode root = defParser.getTree(); @@ -122,8 +122,8 @@ public class ConfigDefinitionBuilderTest { assertEquals(def.getLeafMapDefs().get("intMap").getTypeSpec().getType(), "int"); assertEquals(def.getLeafMapDefs().get("stringMap").getTypeSpec().getType(), "string"); assertEquals(def.getStructMapDefs().size(), 1); - assertEquals(def.getStructMapDefs().get("myStructMap").getIntDefs().get("myInt").getDefVal(), null); - assertEquals(def.getStructMapDefs().get("myStructMap").getStringDefs().get("myString").getDefVal(), null); + assertNull(def.getStructMapDefs().get("myStructMap").getIntDefs().get("myInt").getDefVal()); + assertNull(def.getStructMapDefs().get("myStructMap").getStringDefs().get("myString").getDefVal()); assertEquals(def.getStructMapDefs().get("myStructMap").getIntDefs().get("myIntDef").getDefVal(), (Integer)56); assertEquals(def.getStructMapDefs().get("myStructMap").getStringDefs().get("myStringDef").getDefVal(), "g"); diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionKeyTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionKeyTest.java index c4024a73c97..4f5291c6a36 100644 --- a/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionKeyTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionKeyTest.java @@ -20,10 +20,10 @@ public class ConfigDefinitionKeyTest { assertEquals("foo", def1.getName()); assertEquals("fuz", def1.getNamespace()); - assertTrue(def1.equals(def1)); - assertFalse(def1.equals(def2)); - assertFalse(def1.equals(new Object())); - assertTrue(def2.equals(def2)); + assertEquals(def1, def1); + assertNotEquals(def1, def2); + assertNotEquals(def1, new Object()); + assertEquals(def2, def2); } @Test diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionTest.java index 01bdf4e0ad8..845092fccb5 100755 --- a/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/ConfigDefinitionTest.java @@ -113,8 +113,14 @@ public class ConfigDefinitionTest { def.addLongDef("mylongdef", 11L); def.addDoubleDef("mydouble"); def.addDoubleDef("mydoubledef", 2d); - EnumDef ed = new EnumDef(new ArrayList<String>(){{add("a1"); add("a2");}}, null); - EnumDef eddef = new EnumDef(new ArrayList<String>(){{add("a11"); add("a22");}}, "a22"); + EnumDef ed = new EnumDef(new ArrayList<>() {{ + add("a1"); + add("a2"); + }}, null); + EnumDef eddef = new EnumDef(new ArrayList<>() {{ + add("a11"); + add("a22"); + }}, "a22"); def.addEnumDef("myenum", ed); def.addEnumDef("myenumdef", eddef); def.addReferenceDef("myref"); diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigFileFormatterTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigFileFormatterTest.java index 27d907d279d..3cc030d944b 100644 --- a/config/src/test/java/com/yahoo/vespa/config/ConfigFileFormatterTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/ConfigFileFormatterTest.java @@ -17,6 +17,7 @@ import org.junit.Ignore; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; @@ -137,7 +138,7 @@ public class ConfigFileFormatterTest { InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ConfigFileFormat(def).encode(baos, slime); - assertThat(baos.toString("UTF-8"), is("enumval null\nintval null\nlongval null\nboolval false\ndoubleval null\n")); + assertThat(baos.toString(StandardCharsets.UTF_8), is("enumval null\nintval null\nlongval null\nboolval false\ndoubleval null\n")); } // TODO: Reenable this when we can reenable typechecking. @@ -160,7 +161,7 @@ public class ConfigFileFormatterTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree(); new ConfigFileFormat(def).encode(baos, slime); - assertThat(baos.toString("UTF-8"), is("stringval \"" + value + "\"\n")); + assertThat(baos.toString(StandardCharsets.UTF_8), is("stringval \"" + value + "\"\n")); } @Test @@ -326,7 +327,7 @@ public class ConfigFileFormatterTest { assertThat(Utf8.toString(baos.toByteArray()), is("stringval \"" + input + "\"\n")); } - public static String bytesToHexString(byte[] bytes){ + private static String bytesToHexString(byte[] bytes){ StringBuilder sb = new StringBuilder(); for(byte b : bytes){ sb.append(String.format("%02x", b&0xff)); diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigKeyTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigKeyTest.java index 0642d5733c9..427014316cf 100644 --- a/config/src/test/java/com/yahoo/vespa/config/ConfigKeyTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/ConfigKeyTest.java @@ -27,16 +27,16 @@ public class ConfigKeyTest { assertEquals(key1, key2); ConfigKey<?> key3 = new ConfigKey<>("foo", "a/b/c/d", namespace); - assertTrue(!key1.equals(key3)); assertFalse(key1.equals(key3)); + assertNotEquals(key1, key3); assertEquals("a/b/c", new ConfigKey<>("foo", "a/b/c", namespace).getConfigId()); assertEquals("a", new ConfigKey<>("foo", "a", namespace).getConfigId()); assertEquals("", new ConfigKey<>("foo", "", namespace).getConfigId()); - assertTrue(key1.equals(key1)); - assertFalse(key1.equals(key3)); - assertFalse(key1.equals(new Object())); + assertEquals(key1, key1); + assertNotEquals(key1, key3); + assertNotEquals(key1, new Object()); ConfigKey<?> key4 = new ConfigKey<>("myConfig", null, namespace); assertEquals("", key4.getConfigId()); @@ -70,11 +70,11 @@ public class ConfigKeyTest { ConfigKey<?> noNamespace = new ConfigKey<>("name", "id", null); ConfigKey<?> namespaceFoo = new ConfigKey<>("name", "id", "foo"); ConfigKey<?> namespaceBar = new ConfigKey<>("name", "id", "bar"); - assertTrue(noNamespace.equals(noNamespace)); - assertTrue(namespaceFoo.equals(namespaceFoo)); - assertFalse(noNamespace.equals(namespaceFoo)); - assertFalse(namespaceFoo.equals(noNamespace)); - assertFalse(namespaceFoo.equals(namespaceBar)); + assertEquals(noNamespace, noNamespace); + assertEquals(namespaceFoo, namespaceFoo); + assertNotEquals(noNamespace, namespaceFoo); + assertNotEquals(namespaceFoo, noNamespace); + assertNotEquals(namespaceFoo, namespaceBar); assertEquals(noNamespace.getNamespace(), CNode.DEFAULT_NAMESPACE); assertEquals(namespaceBar.getNamespace(), "bar"); } diff --git a/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadTest.java b/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadTest.java index 63a55d20edf..f1b0adc03e7 100644 --- a/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/ConfigPayloadTest.java @@ -14,7 +14,6 @@ import com.yahoo.slime.Slime; import com.yahoo.text.StringUtilities; import org.junit.Test; -import java.io.IOException; import java.io.StringReader; import static org.hamcrest.CoreMatchers.is; @@ -31,13 +30,13 @@ import static org.junit.Assert.assertTrue; public class ConfigPayloadTest { @Test - public void test_simple_builder() throws Exception { + public void test_simple_builder() { SimpletypesConfig config = createSimpletypesConfig("stringval", "abcde"); assertThat(config.stringval(), is("abcde")); } @Test - public void require_that_arrays_are_built() throws Exception { + public void require_that_arrays_are_built() { AppConfig config = createAppConfig("foo", "4", new String[] { "bar", "baz", "bim" }); assertThat(config.message(), is("foo")); assertThat(config.times(), is(4)); @@ -47,7 +46,7 @@ public class ConfigPayloadTest { } @Test - public void test_int_leaf_legal() throws Exception { + public void test_int_leaf_legal() { SimpletypesConfig config = createSimpletypesConfig("intval", "0"); assertThat(config.intval(), is(0)); config = createSimpletypesConfig("intval", String.valueOf(Integer.MIN_VALUE)); @@ -61,27 +60,27 @@ public class ConfigPayloadTest { } @Test (expected = RuntimeException.class) - public void test_int_leaf_too_large() throws Exception { - createSimpletypesConfig("intval", String.valueOf(Integer.MAX_VALUE) + "00"); + public void test_int_leaf_too_large() { + createSimpletypesConfig("intval", Integer.MAX_VALUE + "00"); } @Test (expected = RuntimeException.class) - public void test_int_leaf_too_large_neg() throws Exception { - createSimpletypesConfig("intval", String.valueOf(Integer.MIN_VALUE) + "00"); + public void test_int_leaf_too_large_neg() { + createSimpletypesConfig("intval", Integer.MIN_VALUE + "00"); } @Test(expected=RuntimeException.class) - public void test_int_leaf_illegal_string() throws Exception { + public void test_int_leaf_illegal_string() { createSimpletypesConfig("intval", "illegal"); } @Test(expected=RuntimeException.class) - public void test_int_leaf_illegal_string_suffix() throws Exception { + public void test_int_leaf_illegal_string_suffix() { createSimpletypesConfig("intval", "123illegal"); } @Test(expected=RuntimeException.class) - public void test_int_leaf_illegal_string_prefix() throws Exception { + public void test_int_leaf_illegal_string_prefix() { createSimpletypesConfig("intval", "illegal123"); } @@ -95,7 +94,7 @@ public class ConfigPayloadTest { @Test - public void test_long_leaf() throws Exception { + public void test_long_leaf() { SimpletypesConfig config = createSimpletypesConfig("longval", "0"); assertThat(config.longval(), is(0L)); config = createSimpletypesConfig("longval", String.valueOf(Long.MIN_VALUE)); @@ -109,22 +108,22 @@ public class ConfigPayloadTest { } @Test(expected = RuntimeException.class) - public void test_long_leaf_illegal_string() throws Exception { + public void test_long_leaf_illegal_string() { createSimpletypesConfig("longval", "illegal"); } @Test (expected = RuntimeException.class) - public void test_long_leaf_too_large() throws Exception { - createSimpletypesConfig("longval", String.valueOf(Long.MAX_VALUE) + "00"); + public void test_long_leaf_too_large() { + createSimpletypesConfig("longval", Long.MAX_VALUE + "00"); } @Test (expected = RuntimeException.class) - public void test_long_leaf_too_large_neg() throws Exception { - createSimpletypesConfig("longval", String.valueOf(Long.MIN_VALUE) + "00"); + public void test_long_leaf_too_large_neg() { + createSimpletypesConfig("longval", Long.MIN_VALUE + "00"); } @Test - public void test_double_leaf() throws Exception { + public void test_double_leaf() { SimpletypesConfig config = createSimpletypesConfig("doubleval", "0"); assertEquals(0.0, config.doubleval(), 0.01); assertEquals(133.3, createSimpletypesConfig("doubleval", "133.3").doubleval(), 0.001); @@ -135,35 +134,35 @@ public class ConfigPayloadTest { } @Test - public void test_serializer() throws IOException { + public void test_serializer() { ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder())); assertThat(payload.toString(true), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}")); } @Test(expected=RuntimeException.class) - public void test_double_leaf_illegal_string() throws Exception { + public void test_double_leaf_illegal_string() { createSimpletypesConfig("doubleval", "illegal"); } @Test - public void test_double_leaf_negative_infinity() throws Exception { + public void test_double_leaf_negative_infinity() { assertThat(createSimpletypesConfig("doubleval", "-Infinity").doubleval(), is(Double.NEGATIVE_INFINITY)); assertThat(createSimpletypesConfig("doubleval", "Infinity").doubleval(), is(Double.POSITIVE_INFINITY)); } @Test - public void test_enum_leaf() throws Exception { + public void test_enum_leaf() { assertThat(createSimpletypesConfig("enumval", "VAL1").enumval(), is(SimpletypesConfig.Enumval.Enum.VAL1)); assertThat(createSimpletypesConfig("enumval", "VAL2").enumval(), is(SimpletypesConfig.Enumval.Enum.VAL2)); } @Test(expected=RuntimeException.class) - public void test_enum_leaf_illegal_string() throws Exception { + public void test_enum_leaf_illegal_string() { createSimpletypesConfig("enumval", "ILLEGAL"); } @Test - public void test_bool_leaf() throws Exception { + public void test_bool_leaf() { SimpletypesConfig config = createSimpletypesConfig("boolval", "true"); assertThat(config.boolval(), is(true)); config = createSimpletypesConfig("boolval", "false"); @@ -175,18 +174,18 @@ public class ConfigPayloadTest { } @Test// FIXME: (expected = RuntimeException.class) - public void test_bool_leaf_illegal() throws Exception { + public void test_bool_leaf_illegal() { createSimpletypesConfig("boolval", "illegal"); } @Test - public void test_string_illegal_value() throws Exception { + public void test_string_illegal_value() { // TODO: What do we consider illegal string values? createSimpletypesConfig("stringval", "insert_illegal_value_please"); } @Test - public void test_int_array() throws Exception { + public void test_int_array() { // Normal behavior ArraytypesConfig config = createArraytypesConfig("intarr", new String[] { "2", "3", "1", "-2", "5"}); assertThat(config.intarr().size(), is(5)); @@ -210,12 +209,12 @@ public class ConfigPayloadTest { } @Test(expected = RuntimeException.class) - public void test_int_array_illegal() throws Exception { + public void test_int_array_illegal() { createArraytypesConfig("intarr", new String[] { "2", "3", "illegal", "-2", "5"}); } @Test - public void test_long_array() throws Exception { + public void test_long_array() { // Normal behavior ArraytypesConfig config = createArraytypesConfig("longarr", new String[] { "2", "3", "1", "-2", "5"}); assertThat(config.longarr().size(), is(5)); @@ -239,7 +238,7 @@ public class ConfigPayloadTest { } @Test - public void test_double_array() throws Exception { + public void test_double_array() { // Normal behavior ArraytypesConfig config = createArraytypesConfig("doublearr", new String[] { "2.1", "3.3", "1.5", "-2.1", "Infinity"}); assertThat(config.doublearr().size(), is(5)); @@ -251,7 +250,7 @@ public class ConfigPayloadTest { } @Test - public void test_enum_array() throws Exception { + public void test_enum_array() { // Normal behavior ArraytypesConfig config = createArraytypesConfig("enumarr", new String[] { "VAL1", "VAL2", "VAL1" }); assertThat(config.enumarr().size(), is(3)); @@ -261,7 +260,7 @@ public class ConfigPayloadTest { } @Test - public void test_simple_struct() throws Exception { + public void test_simple_struct() { Slime slime = new Slime(); addStructFields(slime.setObject().setObject("simple"), "foobar", "MALE", new String[] { "foo@bar", "bar@foo" }); StructtypesConfig config = new ConfigPayload(slime).toInstance(StructtypesConfig.class, ""); @@ -273,7 +272,7 @@ public class ConfigPayloadTest { } @Test - public void test_simple_struct_arrays() throws Exception { + public void test_simple_struct_arrays() { StructtypesConfig config = createStructtypesConfigArray(new String[] { "foo", "bar" }, new String[] { "MALE", "FEMALE" }); assertThat(config.simplearr(0).name(), is("foo")); @@ -284,7 +283,7 @@ public class ConfigPayloadTest { @Test - public void test_nested_struct() throws Exception { + public void test_nested_struct() { StructtypesConfig config = createStructtypesConfigNested("foo", "FEMALE"); assertThat(config.nested().inner().name(), is("foo")); assertThat(config.nested().inner().gender(), is(StructtypesConfig.Nested.Inner.Gender.Enum.FEMALE)); @@ -293,7 +292,7 @@ public class ConfigPayloadTest { @Test - public void test_nested_struct_array() throws Exception { + public void test_nested_struct_array() { String [] names = { "foo" ,"bar" }; String [] genders = { "FEMALE", "MALE" }; String [][] emails = { @@ -314,7 +313,7 @@ public class ConfigPayloadTest { @Test - public void test_complex_struct_array() throws Exception { + public void test_complex_struct_array() { String [][] names = { { "foo", "bar" }, { "baz", "bim" } @@ -454,19 +453,19 @@ public class ConfigPayloadTest { } @Test - public void test_escaped_string() throws Exception { + public void test_escaped_string() { SimpletypesConfig config = createSimpletypesConfig("stringval", "b=\"escaped\""); assertThat(config.stringval(), is("b=\"escaped\"")); } @Test - public void test_unicode() throws Exception { + public void test_unicode() { SimpletypesConfig config = createSimpletypesConfig("stringval", "Hei \u00E6\u00F8\u00E5 \uBC14\uB451 \u00C6\u00D8\u00C5 hallo"); assertThat(config.stringval(), is("Hei \u00E6\u00F8\u00E5 \uBC14\uB451 \u00C6\u00D8\u00C5 hallo")); } @Test - public void test_empty_payload() throws Exception { + public void test_empty_payload() { Slime slime = new Slime(); slime.setObject(); IntConfig config = new ConfigPayload(slime).toInstance(IntConfig.class, ""); diff --git a/config/src/test/java/com/yahoo/vespa/config/RawConfigTest.java b/config/src/test/java/com/yahoo/vespa/config/RawConfigTest.java index b19da2c1689..a564fea8b2e 100644 --- a/config/src/test/java/com/yahoo/vespa/config/RawConfigTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/RawConfigTest.java @@ -15,6 +15,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; @@ -75,10 +76,10 @@ public class RawConfigTest { assertThat(config.getVespaVersion(), is(not(config3.getVespaVersion()))); // null config - assertFalse(config.equals(null)); + assertNotEquals(null, config); // different type of object - assertFalse(config.equals(key)); + assertNotEquals(config, key); // errors RawConfig errorConfig1 = new RawConfig(key, defMd5, payload, configMd5, generation, false, 1, defContent, Optional.empty()); diff --git a/config/src/test/java/com/yahoo/vespa/config/protocol/PayloadTest.java b/config/src/test/java/com/yahoo/vespa/config/protocol/PayloadTest.java index d4c63ae35cd..e5fc5190ad1 100644 --- a/config/src/test/java/com/yahoo/vespa/config/protocol/PayloadTest.java +++ b/config/src/test/java/com/yahoo/vespa/config/protocol/PayloadTest.java @@ -8,11 +8,10 @@ import com.yahoo.vespa.config.ConfigPayload; import com.yahoo.vespa.config.LZ4PayloadCompressor; import org.junit.Test; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; /** * @author Ulf Lilleengen @@ -58,19 +57,15 @@ public class PayloadTest { Payload h = null; Payload i = null; Payload j = null; - try { - g = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed()); - h = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed()); + g = Payload.from(new Utf8Array(foo1.getBytes(StandardCharsets.UTF_8)), CompressionInfo.uncompressed()); + h = Payload.from(new Utf8Array(foo1.getBytes(StandardCharsets.UTF_8)), CompressionInfo.uncompressed()); - LZ4PayloadCompressor compressor = new LZ4PayloadCompressor(); - CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, foo2.length()); - Utf8Array compressed = new Utf8Array(compressor.compress(foo2.getBytes())); + LZ4PayloadCompressor compressor = new LZ4PayloadCompressor(); + CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, foo2.length()); + Utf8Array compressed = new Utf8Array(compressor.compress(foo2.getBytes())); - i = Payload.from(compressed, info); - j = Payload.from(compressed, info); - } catch (UnsupportedEncodingException e1) { - fail(); - } + i = Payload.from(compressed, info); + j = Payload.from(compressed, info); new EqualsTester() .addEqualityGroup(a, b, g, h) |