summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-12-20 18:38:08 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2021-12-21 01:18:09 +0100
commite8f31cbe437ee969f4dd0490a0409b62b2fd045d (patch)
tree694203ae0423448b259c924c167ecb5584c36229 /container-core
parent5d6f586ccff9880a40366d51f75db5234795c0fc (diff)
GC deprecated junit assertThat.
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java27
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java63
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java32
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java26
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java22
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java36
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java9
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java14
-rw-r--r--container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java2
-rw-r--r--container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java15
-rw-r--r--container-core/src/test/java/com/yahoo/processing/handler/ProcessingHandlerTestCase.java207
-rw-r--r--container-core/src/test/java/com/yahoo/processing/rendering/AsynchronousSectionedRendererTest.java56
12 files changed, 236 insertions, 273 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java b/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java
index 99ea6a4ee58..695efbf7c17 100644
--- a/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java
@@ -9,21 +9,17 @@ import com.yahoo.container.di.ConfigRetriever.BootstrapConfigs;
import com.yahoo.container.di.ConfigRetriever.ComponentsConfigs;
import com.yahoo.container.di.ConfigRetriever.ConfigSnapshot;
import com.yahoo.vespa.config.ConfigKey;
-import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
@@ -52,7 +48,7 @@ public class ConfigRetrieverTest {
ConfigRetriever retriever = createConfigRetriever();
ConfigSnapshot bootstrapConfigs = retriever.getConfigs(Collections.emptySet(), 0, true);
- assertThat(bootstrapConfigs, Matchers.instanceOf(BootstrapConfigs.class));
+ assertTrue(bootstrapConfigs instanceof BootstrapConfigs);
}
@Test
@@ -66,19 +62,15 @@ public class ConfigRetrieverTest {
ConfigSnapshot componentsConfigs = retriever.getConfigs(Collections.singleton(testConfigKey), 0, true);
if (componentsConfigs instanceof ComponentsConfigs) {
- assertThat(componentsConfigs.size(), is(3));
+ assertEquals(3, componentsConfigs.size());
} else {
fail("ComponentsConfigs has unexpected type: " + componentsConfigs);
}
}
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Ignore
@SuppressWarnings("unused")
public void require_exception_upon_modified_components_keys_without_bootstrap() {
- expectedException.expect(IllegalArgumentException.class);
writeConfigs();
ConfigRetriever retriever = createConfigRetriever();
@@ -88,15 +80,20 @@ public class ConfigRetrieverTest {
Set<ConfigKey<? extends ConfigInstance>> keys = new HashSet<>();
keys.add(testConfigKey);
keys.add(new ConfigKey<>(TestConfig.class, ""));
- retriever.getConfigs(keys, 0, true);
+ try {
+ retriever.getConfigs(keys, 0, true);
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertEquals("", e.getMessage());
+ }
}
@Test
public void require_that_empty_components_keys_after_bootstrap_returns_components_configs() {
writeConfigs();
ConfigRetriever retriever = createConfigRetriever();
- assertThat(retriever.getConfigs(Collections.emptySet(), 0, true), instanceOf(BootstrapConfigs.class));
- assertThat(retriever.getConfigs(Collections.emptySet(), 0, true), instanceOf(ComponentsConfigs.class));
+ assertTrue(retriever.getConfigs(Collections.emptySet(), 0, true) instanceof BootstrapConfigs);
+ assertTrue(retriever.getConfigs(Collections.emptySet(), 0, true) instanceof ComponentsConfigs);
}
public void writeConfigs() {
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java
index 1ded443a3eb..4d44281658c 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java
@@ -30,16 +30,11 @@ import java.util.concurrent.Executors;
import java.util.function.Supplier;
import static com.yahoo.container.di.componentgraph.core.ComponentGraph.isBindingAnnotation;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -80,7 +75,7 @@ public class ComponentGraphTest {
ComponentTakingConfig instance = componentGraph.getInstance(ComponentTakingConfig.class);
assertNotNull(instance);
- assertThat(instance.config.stringVal(), is("test-value"));
+ assertEquals("test-value", instance.config.stringVal());
}
@Test
@@ -154,7 +149,7 @@ public class ComponentGraphTest {
componentGraph.complete();
ComponentTakingAllSimpleComponents instance = componentGraph.getInstance(ComponentTakingAllSimpleComponents.class);
- assertThat(instance.simpleComponents.allComponents().size(), is(3));
+ assertEquals(3, instance.simpleComponents.allComponents().size());
}
@Test
@@ -164,7 +159,7 @@ public class ComponentGraphTest {
componentGraph.complete();
ComponentTakingAllSimpleComponents instance = componentGraph.getInstance(ComponentTakingAllSimpleComponents.class);
- assertThat(instance.simpleComponents.allComponents().size(), is(0));
+ assertTrue(instance.simpleComponents.allComponents().isEmpty());
}
@Test
@@ -177,7 +172,7 @@ public class ComponentGraphTest {
ComponentTakingAllSimpleComponentsUpperBound instance = componentGraph
.getInstance(ComponentTakingAllSimpleComponentsUpperBound.class);
- assertThat(instance.simpleComponents.allComponents().size(), is(2));
+ assertEquals(2, instance.simpleComponents.allComponents().size());
}
@Test(expected = RuntimeException.class)
@@ -202,7 +197,7 @@ public class ComponentGraphTest {
SimpleComponent instance1 = componentGraph.getInstance(SimpleComponent.class);
SimpleComponent instance2 = componentGraph.getInstance(SimpleComponent.class);
- assertThat(instance1, sameInstance(instance2));
+ assertSame(instance1, instance2);
}
@Test
@@ -218,7 +213,7 @@ public class ComponentGraphTest {
ComponentTakingComponent instance = componentGraph.getInstance(ComponentTakingComponent.class);
ComponentTakingConfig injected = (ComponentTakingConfig) instance.injectedComponent;
- assertThat(injected.config.stringVal(), is("test-value"));
+ assertEquals("test-value", injected.config.stringVal());
}
@Test(expected = RuntimeException.class)
@@ -248,11 +243,11 @@ public class ComponentGraphTest {
componentGraph.complete();
Set<ConfigKey<? extends ConfigInstance>> configKeys = componentGraph.configKeys();
- assertThat(configKeys.size(), is(2));
+ assertEquals(2, configKeys.size());
configKeys.forEach(key -> {
- assertThat(key.getConfigClass(), equalTo(TestConfig.class));
- assertThat(key.getConfigId(), containsString("component"));
+ assertEquals(key.getConfigClass(), TestConfig.class);
+ assertTrue(key.getConfigId().contains("component"));
});
}
@@ -362,8 +357,8 @@ public class ComponentGraphTest {
componentGraph.complete();
fail("Cycle exception expected.");
} catch (Throwable e) {
- assertThat(e.getMessage(), containsString("cycle"));
- assertThat(e.getMessage(), containsString("ComponentCausingCycle"));
+ assertTrue(e.getMessage().contains("cycle"));
+ assertTrue(e.getMessage().contains("ComponentCausingCycle"));
}
}
@@ -411,8 +406,8 @@ public class ComponentGraphTest {
Executor executorA = graph.getSecond().getFirst();
Executor executorB = graph.getSecond().getSecond();
- assertThat(graphSize, is(4));
- assertThat(executorA, not(sameInstance(executorB)));
+ assertEquals(4, graphSize);
+ assertNotSame(executorA, executorB);
}
@Test
@@ -423,8 +418,8 @@ public class ComponentGraphTest {
Executor executorA = graph.getSecond().getFirst();
Executor executorB = graph.getSecond().getSecond();
- assertThat(graphSize, is(3));
- assertThat(executorA, sameInstance(executorB));
+ assertEquals(3, graphSize);
+ assertSame(executorA, executorB);
}
private Pair<Integer, Pair<Executor, Executor>> buildGraphWithChildInjector(Supplier<Executor> executorProvider) {
@@ -459,7 +454,7 @@ public class ComponentGraphTest {
newGraph.reuseNodes(oldGraph);
Executor newExecutor = newGraph.getInstance(Executor.class);
- assertThat(executor, sameInstance(newExecutor));
+ assertSame(executor, newExecutor);
}
private ComponentGraph createReusingGraph() {
@@ -478,7 +473,7 @@ public class ComponentGraphTest {
componentGraph.add(mockComponentNodeWithId(ComponentTakingComponentId.class, componentId));
componentGraph.complete();
- assertThat(componentGraph.getInstance(ComponentTakingComponentId.class).componentId, is(ComponentId.fromString(componentId)));
+ assertEquals(ComponentId.fromString(componentId), componentGraph.getInstance(ComponentTakingComponentId.class).componentId);
}
@@ -512,7 +507,7 @@ public class ComponentGraphTest {
private final TestConfig config;
public ComponentTakingConfig(TestConfig config) {
- assertThat(config, notNullValue());
+ assertNotNull(config);
this.config = config;
}
}
@@ -521,7 +516,7 @@ public class ComponentGraphTest {
private final SimpleComponent injectedComponent;
public ComponentTakingComponent(SimpleComponent injectedComponent) {
- assertThat(injectedComponent, notNullValue());
+ assertNotNull(injectedComponent);
this.injectedComponent = injectedComponent;
}
}
@@ -530,7 +525,7 @@ public class ComponentGraphTest {
private final ComponentTakingComponent injectedComponent;
public ComponentTakingComponentTakingComponent(ComponentTakingComponent injectedComponent) {
- assertThat(injectedComponent, notNullValue());
+ assertNotNull(injectedComponent);
this.injectedComponent = injectedComponent;
}
}
@@ -541,8 +536,8 @@ public class ComponentGraphTest {
private final SimpleComponent simpleComponent;
public ComponentTakingConfigAndComponent(TestConfig config, SimpleComponent injectedComponent) {
- assertThat(config, notNullValue());
- assertThat(injectedComponent, notNullValue());
+ assertNotNull(config);
+ assertNotNull(injectedComponent);
this.config = config;
this.simpleComponent = injectedComponent;
}
@@ -552,7 +547,7 @@ public class ComponentGraphTest {
public final ComponentRegistry<SimpleComponent> simpleComponents;
public ComponentTakingAllSimpleComponents(ComponentRegistry<SimpleComponent> simpleComponents) {
- assertThat(simpleComponents, notNullValue());
+ assertNotNull(simpleComponents);
this.simpleComponents = simpleComponents;
}
}
@@ -561,20 +556,20 @@ public class ComponentGraphTest {
private final ComponentRegistry<? extends SimpleComponent> simpleComponents;
public ComponentTakingAllSimpleComponentsUpperBound(ComponentRegistry<? extends SimpleComponent> simpleComponents) {
- assertThat(simpleComponents, notNullValue());
+ assertNotNull(simpleComponents);
this.simpleComponents = simpleComponents;
}
}
public static class ComponentTakingAllComponentsWithTypeVariable<COMPONENT extends AbstractComponent> extends AbstractComponent {
public ComponentTakingAllComponentsWithTypeVariable(ComponentRegistry<COMPONENT> simpleComponents) {
- assertThat(simpleComponents, notNullValue());
+ assertNotNull(simpleComponents);
}
}
public static class ComponentTakingNamedComponent extends AbstractComponent {
public ComponentTakingNamedComponent(@Named("named-test") SimpleComponent injectedComponent) {
- assertThat(injectedComponent, notNullValue());
+ assertNotNull(injectedComponent);
}
}
@@ -633,7 +628,7 @@ public class ComponentGraphTest {
private final Executor executor;
public ComponentTakingExecutor(Executor executor) {
- assertThat(executor, notNullValue());
+ assertNotNull(executor);
this.executor = executor;
}
}
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java
index 188e04d8497..1e3d67ed463 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/FallbackToGuiceInjectorTest.java
@@ -10,23 +10,19 @@ import com.google.inject.name.Names;
import com.yahoo.component.AbstractComponent;
import com.yahoo.component.ComponentId;
import com.yahoo.config.ConfigInstance;
-import com.yahoo.container.di.componentgraph.core.ComponentGraph;
-import com.yahoo.container.di.componentgraph.core.ComponentNode;
-import com.yahoo.container.di.componentgraph.core.Node;
import com.yahoo.vespa.config.ConfigKey;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* @author Tony Vaagenes
@@ -37,11 +33,8 @@ public class FallbackToGuiceInjectorTest {
private ComponentGraph componentGraph;
private Injector injector;
- private Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configs =
- new HashMap<>();
+ private final Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configs = new HashMap<>();
- @Rule
- public final ExpectedException exception = ExpectedException.none();
@Before
public void createGraph() {
@@ -91,7 +84,7 @@ public class FallbackToGuiceInjectorTest {
complete();
MyComponent component = getInstance(MyComponent.class);
- assertThat(component.url, is("http://yahoo.com"));
+ assertEquals("http://yahoo.com", component.url);
assertNotNull(component.executor);
}
@@ -102,17 +95,19 @@ public class FallbackToGuiceInjectorTest {
complete();
ComponentTakingDefaultString component = getInstance(ComponentTakingDefaultString.class);
- assertThat(component.injectedString, is(""));
+ assertTrue(component.injectedString.isEmpty());
}
@Test
public void guice_injector_fails_when_no_explicit_binding_exists_and_class_has_no_default_ctor() {
setInjector(emptyGuiceInjector());
register(ComponentThatCannotBeConstructed.class);
-
- exception.expect(RuntimeException.class);
- exception.expectMessage("When resolving dependencies of 'com.yahoo.container.di.componentgraph.core.FallbackToGuiceInjectorTest$ComponentThatCannotBeConstructed'");
- complete();
+ try {
+ complete();
+ fail();
+ } catch (RuntimeException e) {
+ assertEquals("When resolving dependencies of 'com.yahoo.container.di.componentgraph.core.FallbackToGuiceInjectorTest$ComponentThatCannotBeConstructed'", e.getMessage());
+ }
}
public void register(Class<?> componentClass) {
@@ -123,9 +118,8 @@ public class FallbackToGuiceInjectorTest {
return ComponentId.fromString(componentClass.getName());
}
- @SuppressWarnings("unchecked")
private Node mockComponentNode(Class<?> componentClass) {
- return new ComponentNode(toId(componentClass), toId(componentClass).toString(), (Class<Object>)componentClass, null);
+ return new ComponentNode(toId(componentClass), toId(componentClass).toString(), componentClass, null);
}
public <T> T getInstance(Class<T> componentClass) {
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java
index 537140d6f3f..29452f7babe 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java
@@ -21,11 +21,9 @@ import java.util.concurrent.Executor;
import java.util.function.Function;
import java.util.function.Supplier;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
/**
* @author gjoranv
@@ -47,7 +45,7 @@ public class ReuseComponentsTest {
newGraph.reuseNodes(graph);
T instance2 = getComponent(newGraph, classToLookup);
- assertThat(instance2, sameInstance(instance));
+ assertSame(instance2, instance);
}
@Test(expected = IllegalStateException.class)
@@ -59,7 +57,7 @@ public class ReuseComponentsTest {
newGraph.reuseNodes(graph);
SimpleComponent2 instance2 = getComponent(newGraph, SimpleComponent2.class);
- assertThat(instance2.getId(), is(instance.getId()));
+ assertEquals(instance2.getId(),instance.getId());
@SuppressWarnings("unused")
SimpleComponent throwsException = getComponent(newGraph, SimpleComponent.class);
}
@@ -79,7 +77,7 @@ public class ReuseComponentsTest {
newGraph.reuseNodes(graph);
ComponentTakingConfig instance2 = getComponent(newGraph, componentClass);
- assertThat(instance2, not(sameInstance(instance)));
+ assertNotSame(instance2, instance);
}
@Test
@@ -111,7 +109,7 @@ public class ReuseComponentsTest {
newGraph.reuseNodes(oldGraph);
ComponentTakingComponent newInstance = getComponent(newGraph, ComponentTakingComponent.class);
- assertThat(newInstance, not(sameInstance(oldInstance)));
+ assertNotSame(newInstance, oldInstance);
}
@Test
@@ -143,7 +141,7 @@ public class ReuseComponentsTest {
newGraph.reuseNodes(oldGraph);
ComponentRegistry<SimpleComponent> newSimpleComponentRegistry = getComponent(newGraph, ComponentTakingAllSimpleComponents.class).simpleComponents;
- assertThat(newSimpleComponentRegistry, not(sameInstance(oldSimpleComponentRegistry)));
+ assertNotSame(newSimpleComponentRegistry, oldSimpleComponentRegistry);
}
@Test
@@ -177,8 +175,8 @@ public class ReuseComponentsTest {
SimpleComponent newInjectedComponent = getComponent(newGraph, SimpleComponent.class);
ComponentTakingConfigAndComponent newDependentComponent = getComponent(newGraph, ComponentTakingConfigAndComponent.class);
- assertThat(newDependentComponent, not(sameInstance(oldDependentComponent)));
- assertThat(newInjectedComponent, sameInstance(oldInjectedComponent));
+ assertNotSame(newDependentComponent, oldDependentComponent);
+ assertSame(newInjectedComponent, oldInjectedComponent);
}
@Test
@@ -197,7 +195,7 @@ public class ReuseComponentsTest {
componentRetriever.apply(oldGraph); // Ensure creation of GuiceNode
ComponentGraph newGraph = makeGraph.get();
newGraph.reuseNodes(oldGraph);
- assertThat(componentRetriever.apply(oldGraph), sameInstance(componentRetriever.apply(newGraph)));
+ assertSame(componentRetriever.apply(oldGraph), componentRetriever.apply(newGraph));
}
@Test
@@ -218,7 +216,7 @@ public class ReuseComponentsTest {
Node targetNode1 = createNodeWithInjectedNodeWithInjectedNode.apply("indirectlyInjected_1");
Node targetNode2 = createNodeWithInjectedNodeWithInjectedNode.apply("indirectlyInjected_2");
- assertThat(targetNode1, equalTo(targetNode2));
+ assertEquals(targetNode1, targetNode2);
}
private void completeNode(ComponentNode node) {
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java
index d1d3914a5ff..65fbdc578aa 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/CycleFinderTest.java
@@ -4,13 +4,13 @@ package com.yahoo.container.di.componentgraph.cycle;
import org.junit.Test;
+import java.util.List;
+
import static com.yahoo.container.di.componentgraph.cycle.CycleFinderTest.Vertices.A;
import static com.yahoo.container.di.componentgraph.cycle.CycleFinderTest.Vertices.B;
import static com.yahoo.container.di.componentgraph.cycle.CycleFinderTest.Vertices.C;
import static com.yahoo.container.di.componentgraph.cycle.CycleFinderTest.Vertices.D;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.empty;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
/**
* @author gjoranv
@@ -28,7 +28,7 @@ public class CycleFinderTest {
graph.edge(D, A);
var cycleFinder = new CycleFinder<>(graph);
- assertThat(cycleFinder.findCycle(), empty());
+ assertTrue(cycleFinder.findCycle().isEmpty());
}
@Test
@@ -39,7 +39,7 @@ public class CycleFinderTest {
graph.edge(C, A);
var cycleFinder = new CycleFinder<>(graph);
- assertThat(cycleFinder.findCycle(), contains(A, B, C, A));
+ assertTrue(cycleFinder.findCycle().containsAll(List.of(A, B, C, A)));
}
@Test
@@ -48,7 +48,7 @@ public class CycleFinderTest {
graph.edge(A, A);
var cycleFinder = new CycleFinder<>(graph);
- assertThat(cycleFinder.findCycle(), contains(A, A));
+ assertTrue(cycleFinder.findCycle().containsAll(List.of(A, A)));
}
@Test
@@ -59,7 +59,7 @@ public class CycleFinderTest {
graph.edge(C, B);
var cycleFinder = new CycleFinder<>(graph);
- assertThat(cycleFinder.findCycle(), contains(B, C, B));
+ assertTrue(cycleFinder.findCycle().containsAll(List.of(B, C, B)));
}
@Test
@@ -68,8 +68,8 @@ public class CycleFinderTest {
graph.edge(A, A);
var cycleFinder = new CycleFinder<>(graph);
- assertThat(cycleFinder.findCycle(), contains(A, A));
- assertThat(cycleFinder.findCycle(), contains(A, A));
+ assertTrue(cycleFinder.findCycle().containsAll(List.of(A, A)));
+ assertTrue(cycleFinder.findCycle().containsAll(List.of(A, A)));
}
@Test
@@ -78,8 +78,8 @@ public class CycleFinderTest {
graph.edge(A, B);
var cycleFinder = new CycleFinder<>(graph);
- assertThat(cycleFinder.findCycle(), empty());
- assertThat(cycleFinder.findCycle(), empty());
+ assertTrue(cycleFinder.findCycle().isEmpty());
+ assertTrue(cycleFinder.findCycle().isEmpty());
}
}
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java
index c5c6e97180c..526e683ad46 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/cycle/GraphTest.java
@@ -2,18 +2,16 @@
package com.yahoo.container.di.componentgraph.cycle;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+
+import java.util.List;
import static com.yahoo.container.di.componentgraph.cycle.GraphTest.Vertices.A;
import static com.yahoo.container.di.componentgraph.cycle.GraphTest.Vertices.B;
import static com.yahoo.container.di.componentgraph.cycle.GraphTest.Vertices.C;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.empty;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* @author gjoranv
@@ -22,9 +20,6 @@ public class GraphTest {
enum Vertices {A, B, C}
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Test
public void vertices_and_edges_are_added_and_can_be_retrieved() {
var graph = new Graph<Vertices>();
@@ -32,19 +27,22 @@ public class GraphTest {
graph.edge(B, C);
graph.edge(A, C);
- assertThat(graph.getVertices().size(), is(3));
- assertThat(graph.getAdjacent(A), containsInAnyOrder(B, C));
- assertThat(graph.getAdjacent(B), containsInAnyOrder(C));
- assertThat(graph.getAdjacent(C), empty());
+ assertEquals(3, graph.getVertices().size());
+ assertTrue(graph.getAdjacent(A).containsAll(List.of(B, C)));
+ assertTrue(graph.getAdjacent(B).contains(C));
+ assertTrue(graph.getAdjacent(C).isEmpty());
}
@Test
public void null_vertices_are_not_allowed() {
var graph = new Graph<Vertices>();
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Null vertices are not allowed");
- graph.edge(A, null);
+ try {
+ graph.edge(A, null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertEquals("Null vertices are not allowed, edge: A->null", e.getMessage());
+ }
}
@Test
@@ -53,7 +51,7 @@ public class GraphTest {
graph.edge(A, B);
graph.edge(A, B);
- assertThat(graph.getAdjacent(A).size(), is(1));
+ assertEquals(1, graph.getAdjacent(A).size());
}
@Test
@@ -61,7 +59,7 @@ public class GraphTest {
var graph = new Graph<Vertices>();
graph.edge(A, A);
- assertThat(graph.getAdjacent(A), contains(A));
+ assertTrue(graph.getAdjacent(A).contains(A));
}
}
diff --git a/container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java
index aad064bc82e..2eba4144b45 100644
--- a/container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java
+++ b/container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java
@@ -9,8 +9,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.Executor;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
public class AccessLogRequestHandlerTest {
@@ -25,14 +24,14 @@ public class AccessLogRequestHandlerTest {
keeper.addUri("foo");
HttpResponse response = handler.handle(null);
response.render(out);
- assertThat(out.toString(), is("{\"entries\":[{\"url\":\"foo\"}]}"));
+ assertEquals("{\"entries\":[{\"url\":\"foo\"}]}", out.toString());
}
@Test
public void testEmpty() throws IOException {
HttpResponse response = handler.handle(null);
response.render(out);
- assertThat(out.toString(), is("{\"entries\":[]}"));
+ assertEquals("{\"entries\":[]}", out.toString());
}
@Test
@@ -41,7 +40,7 @@ public class AccessLogRequestHandlerTest {
keeper.addUri("foo");
HttpResponse response = handler.handle(null);
response.render(out);
- assertThat(out.toString(), is("{\"entries\":[{\"url\":\"foo\"},{\"url\":\"foo\"}]}"));
+ assertEquals("{\"entries\":[{\"url\":\"foo\"},{\"url\":\"foo\"}]}", out.toString());
}
}
diff --git a/container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java b/container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java
index 604fe9494d7..2efa717800d 100644
--- a/container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java
+++ b/container-core/src/test/java/com/yahoo/container/handler/test/MockServiceTest.java
@@ -12,8 +12,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.Executor;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
/**
* @author Ulf Lilleengen
@@ -37,7 +36,7 @@ public class MockServiceTest {
@Test
public void testNoHandlerFound() throws InterruptedException, IOException {
HttpResponse response = runHandler(com.yahoo.jdisc.http.HttpRequest.Method.DELETE, "/foo/bar");
- assertThat(response.getStatus(), is(404));
+ assertEquals(404, response.getStatus());
assertResponseContents(response, "DELETE:/foo/bar was not found");
}
@@ -52,19 +51,14 @@ public class MockServiceTest {
}
private void assertResponse(HttpResponse response, int expectedCode, String expectedMessage) throws IOException {
- assertThat(response.getStatus(), is(expectedCode));
+ assertEquals(expectedCode, response.getStatus());
assertResponseContents(response, expectedMessage);
}
private void assertResponseContents(HttpResponse response, String expected) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.render(baos);
- assertThat(baos.toString(), is(expected));
- }
-
- private void assertResponseOk(HttpResponse response) {
- assertThat(response.getStatus(), is(200));
- assertThat(response.getContentType(), is("text/plain"));
+ assertEquals(expected, baos.toString());
}
private HttpResponse runHandler(com.yahoo.jdisc.http.HttpRequest.Method method, String path) throws InterruptedException, IOException {
diff --git a/container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java b/container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java
index c69e293750c..451e6dc42bb 100644
--- a/container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java
+++ b/container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java
@@ -8,7 +8,7 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
public class CircularArrayAccessLogKeeperTest {
private CircularArrayAccessLogKeeper circularArrayAccessLogKeeper = new CircularArrayAccessLogKeeper();
diff --git a/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java b/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java
index 2b1a8a42149..4433b78c807 100644
--- a/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java
+++ b/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java
@@ -4,8 +4,7 @@ package com.yahoo.osgi.provider.model;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
/**
* @author gjoranv
@@ -13,7 +12,7 @@ import static org.junit.Assert.assertThat;
public class ComponentModelTest {
@Test
- public void create_from_instantiation_spec() throws Exception {
+ public void create_from_instantiation_spec() {
ComponentModel model = new ComponentModel(
BundleInstantiationSpecification.getFromStrings("id", "class", "bundle"));
verifyBundleSpec(model);
@@ -29,19 +28,19 @@ public class ComponentModelTest {
ComponentModel model = new ComponentModel(
BundleInstantiationSpecification.getFromStrings("id", "class", "bundle"), "configId");
verifyBundleSpec(model);
- assertThat(model.configId, is("configId"));
+ assertEquals("configId", model.configId);
}
@Test
public void create_from_strings() throws Exception {
ComponentModel model = new ComponentModel("id", "class", "bundle", "configId");
verifyBundleSpec(model);
- assertThat(model.configId, is("configId"));
+ assertEquals("configId", model.configId);
}
private void verifyBundleSpec(ComponentModel model) {
- assertThat(model.getComponentId().stringValue(), is("id"));
- assertThat(model.getClassId().stringValue(), is("class"));
- assertThat(model.bundleInstantiationSpec.bundle.stringValue(), is("bundle"));
+ assertEquals("id", model.getComponentId().stringValue());
+ assertEquals("class", model.getClassId().stringValue());
+ assertEquals("bundle", model.bundleInstantiationSpec.bundle.stringValue());
}
}
diff --git a/container-core/src/test/java/com/yahoo/processing/handler/ProcessingHandlerTestCase.java b/container-core/src/test/java/com/yahoo/processing/handler/ProcessingHandlerTestCase.java
index eddaf91986d..3ff3f6e2d27 100644
--- a/container-core/src/test/java/com/yahoo/processing/handler/ProcessingHandlerTestCase.java
+++ b/container-core/src/test/java/com/yahoo/processing/handler/ProcessingHandlerTestCase.java
@@ -30,7 +30,6 @@ import java.io.InputStream;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
@@ -40,13 +39,11 @@ import java.util.concurrent.ExecutionException;
import static com.yahoo.jdisc.http.server.jetty.AccessLoggingRequestHandler.CONTEXT_KEY_ACCESS_LOG_ENTRY;
import static com.yahoo.processing.test.ProcessorLibrary.MapData;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
@@ -64,17 +61,17 @@ public class ProcessingHandlerTestCase {
private ProcessingTestDriver driver;
private final Chain<Processor> defaultChain =
- new Chain<Processor>("default",
+ new Chain<>("default",
new ProcessorLibrary.StringDataListAdder("Item1", "Item2"),
new ProcessorLibrary.Trace("TraceMessage", 1),
new ProcessorLibrary.StringDataAdder("StringData.toString()"));
private final Chain<Processor> simpleChain =
- new Chain<Processor>("simple",
+ new Chain<>("simple",
new ProcessorLibrary.StringDataAdder("StringData.toString()"));
private final Chain<Processor> logValueChain =
- new Chain<Processor>("log-value",
+ new Chain<>("log-value",
new ProcessorLibrary.LogValueAdder(LOG_KEY, LOG_VALUE));
@After
@@ -94,11 +91,11 @@ public class ProcessingHandlerTestCase {
requestContent.close(null);
request.release();
responseHandler.readAll();
- assertThat(entry.getKeyValues().get(LOG_KEY), is(List.of(LOG_VALUE)));
+ assertEquals(List.of(LOG_VALUE), entry.getKeyValues().get(LOG_KEY));
}
@Test
- public void testProcessingHandlerResolvesChains() throws Exception {
+ public void testProcessingHandlerResolvesChains() {
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(defaultChain);
chains.add(simpleChain);
@@ -109,16 +106,16 @@ public class ProcessingHandlerTestCase {
}
@Test
- public void testProcessingHandlerPropagatesRequestParametersAndContext() throws InterruptedException {
+ public void testProcessingHandlerPropagatesRequestParametersAndContext() {
List<Chain<Processor>> chains = new ArrayList<>();
- chains.add(new Chain<Processor>("default", new RequestPropertyTracer()));
+ chains.add(new Chain<>("default", new RequestPropertyTracer()));
driver = new ProcessingTestDriver(chains);
assertTrue("JDisc request context is propagated to properties()",
driver.sendRequest("http://localhost/?chain=default&tracelevel=4").readAll().contains("context.contextVariable: '37'"));
}
@Test
- public void testProcessingHandlerOutputsTrace() throws Exception {
+ public void testProcessingHandlerOutputsTrace() {
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(defaultChain);
driver = new ProcessingTestDriver(chains);
@@ -131,28 +128,28 @@ public class ProcessingHandlerTestCase {
}
@Test
- public void testProcessingHandlerTransfersErrorsToHttpStatusCodesNoData() throws Exception {
+ public void testProcessingHandlerTransfersErrorsToHttpStatusCodesNoData() {
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(simpleChain);
- chains.add(new Chain<Processor>("moved_permanently", new ProcessorLibrary.ErrorAdder(new ErrorMessage(301,"Message"))));
- chains.add(new Chain<Processor>("unauthorized", new ProcessorLibrary.ErrorAdder(new ErrorMessage(401,"Message"))));
- chains.add(new Chain<Processor>("unauthorized_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code,"Message"))));
- chains.add(new Chain<Processor>("forbidden", new ProcessorLibrary.ErrorAdder(new ErrorMessage(403,"Message"))));
- chains.add(new Chain<Processor>("forbidden_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code,"Message"))));
- chains.add(new Chain<Processor>("not_found", new ProcessorLibrary.ErrorAdder(new ErrorMessage(404,"Message"))));
- chains.add(new Chain<Processor>("not_found_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code,"Message"))));
- chains.add(new Chain<Processor>("too_many_requests", new ProcessorLibrary.ErrorAdder(new ErrorMessage(429,"Message"))));
- chains.add(new Chain<Processor>("bad_request", new ProcessorLibrary.ErrorAdder(new ErrorMessage(400,"Message"))));
- chains.add(new Chain<Processor>("bad_request_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code,"Message"))));
- chains.add(new Chain<Processor>("internal_server_error", new ProcessorLibrary.ErrorAdder(new ErrorMessage(500,"Message"))));
- chains.add(new Chain<Processor>("internal_server_error_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code,"Message"))));
- chains.add(new Chain<Processor>("service_unavailable", new ProcessorLibrary.ErrorAdder(new ErrorMessage(503,"Message"))));
- chains.add(new Chain<Processor>("service_unavailable_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code,"Message"))));
- chains.add(new Chain<Processor>("gateway_timeout", new ProcessorLibrary.ErrorAdder(new ErrorMessage(504,"Message"))));
- chains.add(new Chain<Processor>("gateway_timeout_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code,"Message"))));
- chains.add(new Chain<Processor>("bad_gateway", new ProcessorLibrary.ErrorAdder(new ErrorMessage(502,"Message"))));
- chains.add(new Chain<Processor>("bad_gateway_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code,"Message"))));
- chains.add(new Chain<Processor>("unknown_code", new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567,"Message"))));
+ chains.add(new Chain<>("moved_permanently", new ProcessorLibrary.ErrorAdder(new ErrorMessage(301,"Message"))));
+ chains.add(new Chain<>("unauthorized", new ProcessorLibrary.ErrorAdder(new ErrorMessage(401,"Message"))));
+ chains.add(new Chain<>("unauthorized_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code,"Message"))));
+ chains.add(new Chain<>("forbidden", new ProcessorLibrary.ErrorAdder(new ErrorMessage(403,"Message"))));
+ chains.add(new Chain<>("forbidden_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code,"Message"))));
+ chains.add(new Chain<>("not_found", new ProcessorLibrary.ErrorAdder(new ErrorMessage(404,"Message"))));
+ chains.add(new Chain<>("not_found_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code,"Message"))));
+ chains.add(new Chain<>("too_many_requests", new ProcessorLibrary.ErrorAdder(new ErrorMessage(429,"Message"))));
+ chains.add(new Chain<>("bad_request", new ProcessorLibrary.ErrorAdder(new ErrorMessage(400,"Message"))));
+ chains.add(new Chain<>("bad_request_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code,"Message"))));
+ chains.add(new Chain<>("internal_server_error", new ProcessorLibrary.ErrorAdder(new ErrorMessage(500,"Message"))));
+ chains.add(new Chain<>("internal_server_error_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code,"Message"))));
+ chains.add(new Chain<>("service_unavailable", new ProcessorLibrary.ErrorAdder(new ErrorMessage(503,"Message"))));
+ chains.add(new Chain<>("service_unavailable_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code,"Message"))));
+ chains.add(new Chain<>("gateway_timeout", new ProcessorLibrary.ErrorAdder(new ErrorMessage(504,"Message"))));
+ chains.add(new Chain<>("gateway_timeout_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code,"Message"))));
+ chains.add(new Chain<>("bad_gateway", new ProcessorLibrary.ErrorAdder(new ErrorMessage(502,"Message"))));
+ chains.add(new Chain<>("bad_gateway_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code,"Message"))));
+ chains.add(new Chain<>("unknown_code", new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567,"Message"))));
driver = new ProcessingTestDriver(chains);
assertEqualStatus(200, "http://localhost/?chain=simple");
assertEqualStatus(301, "http://localhost/?chain=moved_permanently");
@@ -177,28 +174,28 @@ public class ProcessingHandlerTestCase {
}
@Test
- public void testProcessingHandlerTransfersErrorsToHttpStatusCodesWithData() throws Exception {
+ public void testProcessingHandlerTransfersErrorsToHttpStatusCodesWithData() {
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(simpleChain);
- chains.add(new Chain<Processor>("moved_permanently", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(301,"Message"))));
- chains.add(new Chain<Processor>("unauthorized", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(401,"Message"))));
- chains.add(new Chain<Processor>("unauthorized_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code,"Message"))));
- chains.add(new Chain<Processor>("forbidden", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(403,"Message"))));
- chains.add(new Chain<Processor>("forbidden_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code,"Message"))));
- chains.add(new Chain<Processor>("not_found", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(404,"Message"))));
- chains.add(new Chain<Processor>("not_found_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code,"Message"))));
- chains.add(new Chain<Processor>("too_many_requests", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(429,"Message"))));
- chains.add(new Chain<Processor>("bad_request", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(400,"Message"))));
- chains.add(new Chain<Processor>("bad_request_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code,"Message"))));
- chains.add(new Chain<Processor>("internal_server_error", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(500,"Message"))));
- chains.add(new Chain<Processor>("internal_server_error_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code,"Message"))));
- chains.add(new Chain<Processor>("service_unavailable", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(503,"Message"))));
- chains.add(new Chain<Processor>("service_unavailable_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code,"Message"))));
- chains.add(new Chain<Processor>("gateway_timeout", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(504,"Message"))));
- chains.add(new Chain<Processor>("gateway_timeout_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code,"Message"))));
- chains.add(new Chain<Processor>("bad_gateway", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(502,"Message"))));
- chains.add(new Chain<Processor>("bad_gateway_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code,"Message"))));
- chains.add(new Chain<Processor>("unknown_code", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567,"Message"))));
+ chains.add(new Chain<>("moved_permanently", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(301,"Message"))));
+ chains.add(new Chain<>("unauthorized", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(401,"Message"))));
+ chains.add(new Chain<>("unauthorized_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code,"Message"))));
+ chains.add(new Chain<>("forbidden", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(403,"Message"))));
+ chains.add(new Chain<>("forbidden_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code,"Message"))));
+ chains.add(new Chain<>("not_found", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(404,"Message"))));
+ chains.add(new Chain<>("not_found_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code,"Message"))));
+ chains.add(new Chain<>("too_many_requests", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(429,"Message"))));
+ chains.add(new Chain<>("bad_request", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(400,"Message"))));
+ chains.add(new Chain<>("bad_request_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code,"Message"))));
+ chains.add(new Chain<>("internal_server_error", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(500,"Message"))));
+ chains.add(new Chain<>("internal_server_error_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code,"Message"))));
+ chains.add(new Chain<>("service_unavailable", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(503,"Message"))));
+ chains.add(new Chain<>("service_unavailable_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code,"Message"))));
+ chains.add(new Chain<>("gateway_timeout", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(504,"Message"))));
+ chains.add(new Chain<>("gateway_timeout_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code,"Message"))));
+ chains.add(new Chain<>("bad_gateway", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(502,"Message"))));
+ chains.add(new Chain<>("bad_gateway_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code,"Message"))));
+ chains.add(new Chain<>("unknown_code", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567,"Message"))));
driver = new ProcessingTestDriver(chains);
assertEqualStatus(200, "http://localhost/?chain=simple");
assertEqualStatus(301, "http://localhost/?chain=moved_permanently");
@@ -227,15 +224,15 @@ public class ProcessingHandlerTestCase {
ProcessingTestDriver.MockResponseHandler responseHandler = null;
try {
Map<String,List<String>> responseHeaders = new HashMap<>();
- responseHeaders.put("foo", Collections.singletonList("fooValue"));
- responseHeaders.put("bar", Arrays.asList(new String[] { "barValue", "bazValue"}));
+ responseHeaders.put("foo", List.of("fooValue"));
+ responseHeaders.put("bar", List.of("barValue", "bazValue"));
Map<String,List<String>> otherResponseHeaders = new HashMap<>();
- otherResponseHeaders.put("foo", Collections.singletonList("fooValue2"));
- otherResponseHeaders.put("bax", Collections.singletonList("baxValue"));
+ otherResponseHeaders.put("foo", List.of("fooValue2"));
+ otherResponseHeaders.put("bax", List.of("baxValue"));
List<Chain<Processor>> chains = new ArrayList<>();
- chains.add(new Chain<Processor>("default",new ResponseHeaderSetter(responseHeaders),
+ chains.add(new Chain<>("default",new ResponseHeaderSetter(responseHeaders),
new ResponseHeaderSetter(otherResponseHeaders)));
driver = new ProcessingTestDriver(chains);
responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
@@ -256,7 +253,7 @@ public class ProcessingHandlerTestCase {
ProcessingTestDriver.MockResponseHandler responseHandler = null;
try {
List<Chain<Processor>> chains = new ArrayList<>();
- chains.add(new Chain<Processor>("default", new ResponseStatusSetter(429)));
+ chains.add(new Chain<>("default", new ResponseStatusSetter(429)));
driver = new ProcessingTestDriver(chains);
responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
Response response = responseHandler.getResponse();
@@ -275,7 +272,7 @@ public class ProcessingHandlerTestCase {
ProcessingTestDriver.MockResponseHandler responseHandler = null;
try {
List<Chain<Processor>> chains = new ArrayList<>();
- chains.add(new Chain<Processor>("default", new ResponseStatusSetter(200),
+ chains.add(new Chain<>("default", new ResponseStatusSetter(200),
new ProcessorLibrary.StringDataAdder("Hello"),
new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code,"Message"))));
driver = new ProcessingTestDriver(chains);
@@ -307,14 +304,14 @@ public class ProcessingHandlerTestCase {
@SuppressWarnings("unchecked")
@Test
- public void testProcessingHandlerSupportsAsyncRendering() throws Exception {
+ public void testProcessingHandlerSupportsAsyncRendering() {
// Set up
ProcessorLibrary.FutureDataSource futureDataSource = new ProcessorLibrary.FutureDataSource();
- Chain<Processor> asyncCompletionChain = new Chain<Processor>("asyncCompletion", new ProcessorLibrary.DataCounter("async"));
+ Chain<Processor> asyncCompletionChain = new Chain<>("asyncCompletion", new ProcessorLibrary.DataCounter("async"));
Chain<Processor> chain =
- new Chain<Processor>("federation", new ProcessorLibrary.DataCounter("sync"),
+ new Chain<>("federation", new ProcessorLibrary.DataCounter("sync"),
new ProcessorLibrary.Federator(new Chain<Processor>(new ProcessorLibrary.DataSource()),
- new Chain<Processor>(new ProcessorLibrary.AsyncDataProcessingInitiator(asyncCompletionChain),futureDataSource)));
+ new Chain<>(new ProcessorLibrary.AsyncDataProcessingInitiator(asyncCompletionChain),futureDataSource)));
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(chain);
driver = new ProcessingTestDriver(chains);
@@ -350,17 +347,17 @@ public class ProcessingHandlerTestCase {
assertEquals(",{\"data\":\"[sync] Data count: 3\"}" + // Async items not counted as they arrive after chain completion
"]}",
responseHandler.read());
- assertTrue("Transmission completed", null == responseHandler.read());
+ assertNull("Transmission completed", responseHandler.read());
}
@SuppressWarnings("unchecked")
@Test
- public void testProcessingHandlerSupportsAsyncUnorderedRendering() throws Exception {
+ public void testProcessingHandlerSupportsAsyncUnorderedRendering() {
// Set up
ProcessorLibrary.FutureDataSource futureDataSource1 = new ProcessorLibrary.FutureDataSource();
ProcessorLibrary.FutureDataSource futureDataSource2 = new ProcessorLibrary.FutureDataSource();
Chain<Processor> chain =
- new Chain<Processor>("federation",
+ new Chain<>("federation",
new ProcessorLibrary.Federator(false,new Chain<Processor>(futureDataSource1),
new Chain<Processor>(futureDataSource2)));
List<Chain<Processor>> chains = new ArrayList<>();
@@ -393,7 +390,7 @@ public class ProcessingHandlerTestCase {
"]}",
responseHandler.read());
- assertTrue("Transmission completed", responseHandler.read()==null);
+ assertNull("Transmission completed", responseHandler.read());
}
@SuppressWarnings("unchecked")
@@ -401,7 +398,7 @@ public class ProcessingHandlerTestCase {
public void testAsyncOnlyRendering() throws Exception {
// Set up
ProcessorLibrary.ListenableFutureDataSource futureDataSource = new ProcessorLibrary.ListenableFutureDataSource();
- Chain<Processor> chain = new Chain<>("main", Collections.<Processor>singletonList(futureDataSource));
+ Chain<Processor> chain = new Chain<>("main", List.of(futureDataSource));
driver = new ProcessingTestDriver(chain);
ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main");
@@ -421,7 +418,7 @@ public class ProcessingHandlerTestCase {
responseHandler.read());
assertEquals(200, responseHandler.getStatus());
- assertTrue("Transmission completed", null == responseHandler.read());
+ assertNull("Transmission completed", responseHandler.read());
}
@SuppressWarnings("unchecked")
@@ -429,7 +426,7 @@ public class ProcessingHandlerTestCase {
public void testAsyncRenderingWithClientClose() throws Exception {
// Set up
ProcessorLibrary.ListenableFutureDataSource futureDataSource = new ProcessorLibrary.ListenableFutureDataSource();
- Chain<Processor> chain = new Chain<>("main", Collections.<Processor>singletonList(futureDataSource));
+ Chain<Processor> chain = new Chain<>("main", List.of(futureDataSource));
driver = new ProcessingTestDriver(chain);
ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main");
@@ -446,7 +443,7 @@ public class ProcessingHandlerTestCase {
assertNull(responseHandler.read());
assertEquals(200, responseHandler.getStatus());
- assertTrue("Transmission completed", null == responseHandler.read());
+ assertNull("Transmission completed", responseHandler.read());
}
@SuppressWarnings("unchecked")
@@ -482,7 +479,7 @@ public class ProcessingHandlerTestCase {
assertEquals("Data is completed, so post data is read", "Hello, world!", postReader.bodyDataFuture.get().trim());
assertEquals(200, responseHandler.getStatus());
- assertTrue("Transmission completed", null == responseHandler.read());
+ assertNull("Transmission completed", responseHandler.read());
}
private static class PostReader extends Processor {
@@ -511,12 +508,12 @@ public class ProcessingHandlerTestCase {
@Test
public void testStatusAndHeadersCanBeSetAsynchronously() throws Exception {
Map<String,List<String>> responseHeaders = new HashMap<>();
- responseHeaders.put("foo", Collections.singletonList("fooValue"));
- responseHeaders.put("bar", Arrays.asList(new String[] { "barValue", "bazValue"}));
+ responseHeaders.put("foo", List.of("fooValue"));
+ responseHeaders.put("bar", List.of("barValue", "bazValue"));
// Set up
ProcessorLibrary.ListenableFutureDataSource futureDataSource = new ProcessorLibrary.ListenableFutureDataSource(true, false);
- Chain<Processor> chain = new Chain<Processor>("main", new ProcessorLibrary.AsyncDataProcessingInitiator(new Chain<Processor>("async", new ProcessorLibrary.StatusSetter(500), new ResponseHeaderSetter(responseHeaders))), futureDataSource);
+ Chain<Processor> chain = new Chain<>("main", new ProcessorLibrary.AsyncDataProcessingInitiator(new Chain<>("async", new ProcessorLibrary.StatusSetter(500), new ResponseHeaderSetter(responseHeaders))), futureDataSource);
driver = new ProcessingTestDriver(chain);
ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main");
@@ -530,18 +527,18 @@ public class ProcessingHandlerTestCase {
assertEquals(500, responseHandler.getStatus());
assertEquals("[fooValue]", responseHandler.getResponse().headers().get("foo").toString());
assertEquals("[barValue, bazValue]", responseHandler.getResponse().headers().get("bar").toString());
- assertTrue("Transmission completed", null == responseHandler.read());
+ assertNull("Transmission completed", responseHandler.read());
}
@SuppressWarnings("unchecked")
@Test
- public void testAsyncRenderingDoesNotHoldThreads() throws Exception {
+ public void testAsyncRenderingDoesNotHoldThreads() {
// Set up
ProcessorLibrary.FutureDataSource futureDataSource = new ProcessorLibrary.FutureDataSource();
// Add some sync data as well to cause rendering to start before async data is added.
// This allows us to wait on return data rather than having to wait for the 100 requests
// to be done, which is cumbersome.
- Chain<Processor> chain = new Chain<Processor>("main", new ProcessorLibrary.Federator(new Chain<Processor>(new ProcessorLibrary.DataSource()), new Chain<Processor>(futureDataSource)));
+ Chain<Processor> chain = new Chain<>("main", new ProcessorLibrary.Federator(new Chain<Processor>(new ProcessorLibrary.DataSource()), new Chain<Processor>(futureDataSource)));
driver = new ProcessingTestDriver(chain);
int requestCount = 1000;
@@ -561,7 +558,7 @@ public class ProcessingHandlerTestCase {
futureDataSource.incomingData.get(i).addLast(new ProcessorLibrary.StringData(null, "d2"));
assertEquals(",{\"data\":\"d2\"}]}", responseHandler[i].read());
assertEquals("]}", responseHandler[i].read());
- assertTrue("Transmission completed", null == responseHandler[i].read());
+ assertNull("Transmission completed", responseHandler[i].read());
}
}
@@ -569,10 +566,10 @@ public class ProcessingHandlerTestCase {
@Test
public void testStreamedRendering() throws Exception {
// Set up
- Chain<Processor> streamChain = new Chain<Processor>(new StreamProcessor());
+ Chain<Processor> streamChain = new Chain<>(new StreamProcessor());
ProcessorLibrary.ListenableFutureDataSource futureDataSource = new ProcessorLibrary.ListenableFutureDataSource();
- Chain<Processor> mainChain = new Chain<Processor>("main", new ProcessorLibrary.StreamProcessingInitiator(streamChain), futureDataSource);
+ Chain<Processor> mainChain = new Chain<>("main", new ProcessorLibrary.StreamProcessingInitiator(streamChain), futureDataSource);
driver = new ProcessingTestDriver(mainChain);
ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main");
@@ -596,14 +593,13 @@ public class ProcessingHandlerTestCase {
",{\"data\":\"map data: {streamProcessed=true}\"}]}",
responseHandler.read());
- assertTrue("Transmission completed", null == responseHandler.read());
+ assertNull("Transmission completed", responseHandler.read());
}
- @SuppressWarnings("unchecked")
@Test
- public void testEagerStreamedRenderingOnFreeze() throws Exception {
+ public void testEagerStreamedRenderingOnFreeze() {
FreezingDataSource source = new FreezingDataSource();
- Chain<Processor> mainChain = new Chain<Processor>("main", source);
+ Chain<Processor> mainChain = new Chain<>("main", source);
driver = new ProcessingTestDriver(mainChain);
ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main");
assertEquals("No data is available at this point", 0, responseHandler.available());
@@ -611,18 +607,17 @@ public class ProcessingHandlerTestCase {
assertEquals("{\"datalist\":[{\"data\":\"d1\"}", responseHandler.read());
source.addLastData.set(true); // signal completion
assertEquals(",{\"data\":\"d2\"}]}", responseHandler.read());
- assertTrue("Transmission completed", null == responseHandler.read());
+ assertNull("Transmission completed", responseHandler.read());
}
- @SuppressWarnings("unchecked")
@Test
@Ignore // TODO
- public void testNestedEagerStreamedRenderingOnFreeze() throws Exception {
+ public void testNestedEagerStreamedRenderingOnFreeze() {
try {
FreezingDataSource source1 = new FreezingDataSource("s1");
FreezingDataSource source2 = new FreezingDataSource("s2");
FreezingDataSource source3 = new FreezingDataSource("s3");
- Chain<Processor> mainChain = new Chain<Processor>("main",
+ Chain<Processor> mainChain = new Chain<>("main",
new ProcessorLibrary.StringDataAdder("main-data"),
new ProcessorLibrary.EagerReturnFederator(true,
new Chain<Processor>(source1),
@@ -639,7 +634,7 @@ public class ProcessingHandlerTestCase {
assertEquals("{\"datalist\":[{\"data\":\"s1d1\"}", responseHandler.read());
source1.addLastData.set(true); // Make source 1 and 2 available
assertEquals(",{\"data\":\"d2\"}]}", responseHandler.read());
- assertTrue("Transmission completed", null == responseHandler.read());
+ assertNull("Transmission completed", responseHandler.read());
}
catch (Throwable t) {
t.printStackTrace();
@@ -648,31 +643,31 @@ public class ProcessingHandlerTestCase {
}
@Test(expected = IllegalArgumentException.class)
- public void testRetrievingNonExistingRendererThrows() throws Exception {
- driver = new ProcessingTestDriver(Collections.<Chain<Processor>>emptyList());
+ public void testRetrievingNonExistingRendererThrows() {
+ driver = new ProcessingTestDriver(List.of());
driver.processingHandler().getRendererCopy(ComponentSpecification.fromString("non-existent"));
}
@Test
- public void testDefaultRendererIsAddedToRegistryWhenNoneIsGivenByUser() throws Exception {
+ public void testDefaultRendererIsAddedToRegistryWhenNoneIsGivenByUser() {
String defaultId = AbstractProcessingHandler.DEFAULT_RENDERER_ID;
- driver = new ProcessingTestDriver(Collections.<Chain<Processor>>emptyList());
+ driver = new ProcessingTestDriver(List.of());
Renderer defaultRenderer = driver.processingHandler().getRenderers().getComponent(defaultId);
- assertThat(defaultRenderer, notNullValue());
+ assertNotNull(defaultRenderer);
}
@Test
- public void testUserSpecifiedDefaultRendererIsNotReplacedInRegistry() throws Exception {
+ public void testUserSpecifiedDefaultRendererIsNotReplacedInRegistry() {
String defaultId = AbstractProcessingHandler.DEFAULT_RENDERER_ID;
Renderer myDefaultRenderer = new ProcessingRenderer();
ComponentRegistry<Renderer> renderers = new ComponentRegistry<>();
renderers.register(ComponentId.fromString(defaultId), myDefaultRenderer);
- driver = new ProcessingTestDriver(Collections.<Chain<Processor>>emptyList(), renderers);
+ driver = new ProcessingTestDriver(List.of(), renderers);
Renderer defaultRenderer = driver.processingHandler().getRenderers().getComponent(defaultId);
- assertThat(defaultRenderer, sameInstance(myDefaultRenderer));
+ assertSame(defaultRenderer, myDefaultRenderer);
}
@@ -727,7 +722,7 @@ public class ProcessingHandlerTestCase {
}
- private String defaultChainResponse =
+ private final String defaultChainResponse =
"{\"datalist\":[" +
"{\"data\":\"StringData.toString()\"}," +
"{\"datalist\":[" +
@@ -736,17 +731,17 @@ public class ProcessingHandlerTestCase {
"}]" +
"}";
- private String simpleChainResponse =
+ private final String simpleChainResponse =
"{\"datalist\":[" +
"{\"data\":\"StringData.toString()\"}]" +
"}";
- private String trace1 =
+ private final String trace1 =
"{\"trace\":[" +
"\"TraceMessage\"" +
"],";
- private String trace1WithFullResult =
+ private final String trace1WithFullResult =
"{\"trace\":[" +
"\"TraceMessage\"" +
"]," +
@@ -758,7 +753,7 @@ public class ProcessingHandlerTestCase {
"]}" +
"]}";
- private String trace4 =
+ private final String trace4 =
"{\"trace\":[" +
"\"Invoke '(anonymous)' of class 'com.yahoo.processing.test.ProcessorLibrary$StringDataListAdder'\"," +
"\"Invoke '(anonymous)' of class 'com.yahoo.processing.test.ProcessorLibrary$Trace'\"," +
@@ -769,7 +764,7 @@ public class ProcessingHandlerTestCase {
"\"Return '(anonymous)' of class 'com.yahoo.processing.test.ProcessorLibrary$StringDataListAdder'\"" +
"],";
- private String trace5 =
+ private final String trace5 =
"{\"trace\":[" +
"\"Invoke '(anonymous)' of class 'com.yahoo.processing.test.ProcessorLibrary$StringDataListAdder'\"," +
"\"Invoke '(anonymous)' of class 'com.yahoo.processing.test.ProcessorLibrary$Trace'\"," +
@@ -780,7 +775,7 @@ public class ProcessingHandlerTestCase {
"\"Return '(anonymous)' of class 'com.yahoo.processing.test.ProcessorLibrary$StringDataListAdder'\"" +
"],";
- private String trace6 =
+ private final String trace6 =
"{\"trace\":[" +
"{\"timestamp\":ddddddddddddd,\"message\":\"Invoke '(anonymous)' of class 'com.yahoo.processing.test.ProcessorLibrary$StringDataListAdder'\"}," +
"{\"timestamp\":ddddddddddddd,\"message\":\"Invoke '(anonymous)' of class 'com.yahoo.processing.test.ProcessorLibrary$Trace'\"}," +
diff --git a/container-core/src/test/java/com/yahoo/processing/rendering/AsynchronousSectionedRendererTest.java b/container-core/src/test/java/com/yahoo/processing/rendering/AsynchronousSectionedRendererTest.java
index 627081e0d3b..0ea8a157410 100644
--- a/container-core/src/test/java/com/yahoo/processing/rendering/AsynchronousSectionedRendererTest.java
+++ b/container-core/src/test/java/com/yahoo/processing/rendering/AsynchronousSectionedRendererTest.java
@@ -23,15 +23,12 @@ import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
/**
* @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
@@ -45,7 +42,7 @@ public class AsynchronousSectionedRendererTest {
TestRenderer rendererPrototype = new TestRenderer();
TestRenderer rendererCopy1 = (TestRenderer)rendererPrototype.clone();
rendererCopy1.init();
- assertTrue(rendererPrototype.getRenderingExecutor() == rendererCopy1.getRenderingExecutor());
+ assertSame(rendererPrototype.getRenderingExecutor(), rendererCopy1.getRenderingExecutor());
}
@Test
@@ -57,7 +54,7 @@ public class AsynchronousSectionedRendererTest {
TestRenderer rendererPrototype2 = new TestRenderer();
TestRenderer rendererCopy2 = (TestRenderer)rendererPrototype2.clone();
rendererCopy2.init();
- assertTrue(rendererPrototype1.getRenderingExecutor() != rendererCopy2.getRenderingExecutor());
+ assertNotSame(rendererPrototype1.getRenderingExecutor(), rendererCopy2.getRenderingExecutor());
}
@Test
@@ -69,9 +66,9 @@ public class AsynchronousSectionedRendererTest {
String str = render(renderer, dataList);
- assertThat(str,
- equalTo(" beginResponse beginList[f\\o\"o, [b/a\br, f\f\no\ro\tbar\u0005]] dataf\\o\"o beginList[b/a\br, " +
- "f\f\no\ro\tbar\u0005] datab/a\br dataf\f\no\ro\tbar\u0005 endList[b/a\br, f\f\no\ro\tbar\u0005] endList[f\\o\"o, [b/a\br, f\f\no\ro\tbar\u0005]] endResponse"));
+ assertEquals(" beginResponse beginList[f\\o\"o, [b/a\br, f\f\no\ro\tbar\u0005]] dataf\\o\"o beginList[b/a\br, " +
+ "f\f\no\ro\tbar\u0005] datab/a\br dataf\f\no\ro\tbar\u0005 endList[b/a\br, f\f\no\ro\tbar\u0005] endList[f\\o\"o, [b/a\br, f\f\no\ro\tbar\u0005]] endResponse",
+ str);
}
@Test
@@ -79,23 +76,21 @@ public class AsynchronousSectionedRendererTest {
Request request = new Request();
DataList dataList = ArrayDataList.create(request);
- assertThat(render(dataList),
- equalTo("{\"datalist\":[" +
- "]}"));
+ assertEquals("{\"datalist\":[]}", render(dataList));
}
@Test
public void testProcessingRendering() throws IOException, InterruptedException {
StringDataList dataList = createDataListWithStrangeStrings();
- assertThat(render(dataList),
- equalTo("{\"datalist\":[" +
+ assertEquals("{\"datalist\":[" +
"{\"data\":\"f\\\\o\\\"o\"}," +
"{\"datalist\":[" +
"{\"data\":\"b/a\\br\"}," +
"{\"data\":\"f\\f\\no\\ro\\tbar\\u0005\"}" +
"]}" +
- "]}"));
+ "]}",
+ render(dataList));
}
@Test
@@ -106,8 +101,7 @@ public class AsynchronousSectionedRendererTest {
dataList.request().errors().add(new ErrorMessage("m1","d1"));
dataList.request().errors().add(new ErrorMessage("m2","d2"));
- assertThat(render(dataList),
- equalTo("{\"errors\":[" +
+ assertEquals("{\"errors\":[" +
"\"m1: d1\"," +
"\"m2: d2\"" +
"]," +
@@ -117,12 +111,13 @@ public class AsynchronousSectionedRendererTest {
"{\"data\":\"l11\"}," +
"{\"data\":\"l12\"}" +
"]}" +
- "]}"));
+ "]}",
+ render(dataList));
}
@Test
public void testProcessingRenderingWithStackTraces() throws IOException, InterruptedException {
- Exception exception=null;
+ Exception exception;
// Create thrown exception
try {
throw new RuntimeException("Thrown");
@@ -155,8 +150,7 @@ public class AsynchronousSectionedRendererTest {
dataList.add(new StringDataList(dataList.request().clone())); // Cloning a request which contains errors
// ... should not cause repetition of those errors
- assertThat(render(dataList),
- equalTo("{\"errors\":[" +
+ assertEquals("{\"errors\":[" +
"\"m1: d1\"," +
"\"m2: d2\"" +
"]," +
@@ -167,7 +161,8 @@ public class AsynchronousSectionedRendererTest {
"{\"data\":\"l12\"}" +
"]}," +
"{\"datalist\":[]}" +
- "]}"));
+ "]}",
+ render(dataList));
}
@Test
@@ -181,8 +176,7 @@ public class AsynchronousSectionedRendererTest {
// and adding new errors to it
dataList.asList().get(2).request().errors().add(new ErrorMessage("m3","d3"));
- assertThat(render(dataList),
- equalTo("{\"errors\":[" +
+ assertEquals("{\"errors\":[" +
"\"m1: d1\"," +
"\"m2: d2\"" +
"]," +
@@ -196,7 +190,8 @@ public class AsynchronousSectionedRendererTest {
"\"m3: d3\"" +
"]," +
"\"datalist\":[]}" +
- "]}"));
+ "]}",
+ render(dataList));
}
public StringDataList createDataList() {
@@ -334,7 +329,7 @@ public class AsynchronousSectionedRendererTest {
}
}
- private abstract class StringData extends ListenableFreezableClass implements Data {
+ private static abstract class StringData extends ListenableFreezableClass implements Data {
private final Request request;
private StringData(Request request) {
@@ -410,7 +405,7 @@ public class AsynchronousSectionedRendererTest {
@Override
@SuppressWarnings("removal")
public ListenableFuture<DataList<StringData>> complete() {
- return new ListenableFuture<DataList<StringData>>() {
+ return new ListenableFuture<>() {
@Override
public void addListener(Runnable runnable, Executor executor) {
}
@@ -431,13 +426,12 @@ public class AsynchronousSectionedRendererTest {
}
@Override
- public DataList<StringData> get() throws InterruptedException, ExecutionException {
+ public DataList<StringData> get() {
return StringDataList.this;
}
@Override
- public DataList<StringData> get(long l, TimeUnit timeUnit)
- throws InterruptedException, ExecutionException, TimeoutException {
+ public DataList<StringData> get(long l, TimeUnit timeUnit) {
return StringDataList.this;
}
};