diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-20 18:38:08 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-21 01:18:09 +0100 |
commit | e8f31cbe437ee969f4dd0490a0409b62b2fd045d (patch) | |
tree | 694203ae0423448b259c924c167ecb5584c36229 /container-core/src/test/java/com/yahoo/container | |
parent | 5d6f586ccff9880a40366d51f75db5234795c0fc (diff) |
GC deprecated junit assertThat.
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container')
9 files changed, 103 insertions, 128 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(); |