diff --git a/geowebcache/arcgiscache/src/test/java/org/geowebcache/arcgis/layer/XMLConfigurationLayerConformanceWithArcGisLayersTest.java b/geowebcache/arcgiscache/src/test/java/org/geowebcache/arcgis/layer/XMLConfigurationLayerConformanceWithArcGisLayersTest.java index 101bc4290..963c67b0b 100644 --- a/geowebcache/arcgiscache/src/test/java/org/geowebcache/arcgis/layer/XMLConfigurationLayerConformanceWithArcGisLayersTest.java +++ b/geowebcache/arcgiscache/src/test/java/org/geowebcache/arcgis/layer/XMLConfigurationLayerConformanceWithArcGisLayersTest.java @@ -15,8 +15,8 @@ package org.geowebcache.arcgis.layer; import static org.geowebcache.util.TestUtils.isPresent; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasProperty; -import static org.junit.Assert.assertThat; import java.io.File; import java.io.IOException; diff --git a/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheDispatcherTest.java b/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheDispatcherTest.java index baa52a11e..17f657ce4 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheDispatcherTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheDispatcherTest.java @@ -15,7 +15,7 @@ package org.geowebcache; import static org.geowebcache.TestHelpers.hasStatus; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Collections; import javax.servlet.http.HttpServletResponse; diff --git a/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheExtensionsTest.java b/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheExtensionsTest.java index 5d71ef778..9c3837584 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheExtensionsTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheExtensionsTest.java @@ -4,12 +4,12 @@ import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.util.HashMap; diff --git a/geowebcache/core/src/test/java/org/geowebcache/MockExtensionRuleTest.java b/geowebcache/core/src/test/java/org/geowebcache/MockExtensionRuleTest.java index 02b6bb7b5..3b93ebcc6 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/MockExtensionRuleTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/MockExtensionRuleTest.java @@ -14,24 +14,22 @@ */ package org.geowebcache; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import java.util.Collection; import org.hamcrest.Matchers; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.Description; import org.junit.runners.model.Statement; public class MockExtensionRuleTest { - @Rule public ExpectedException exception = ExpectedException.none(); - @Test public void testRestoresPreviousState() throws Throwable { MockExtensionRule rule = new MockExtensionRule(); @@ -81,19 +79,24 @@ public void evaluate() throws Throwable { public void testPropagatesException() throws Throwable { MockExtensionRule rule = new MockExtensionRule(); - exception.expectMessage("TEST EXCEPTION"); - rule.apply( - new Statement() { - - @Override - public void evaluate() throws Throwable { - String bean = "THISISTHEBEAN"; - rule.addBean("foo", bean, String.class); - throw new RuntimeException("TEST EXCEPTION"); - } - }, - Description.createSuiteDescription("MOCK")) - .evaluate(); + RuntimeException exception = + assertThrows( + RuntimeException.class, + () -> + rule.apply( + new Statement() { + + @Override + public void evaluate() throws Throwable { + String bean = "THISISTHEBEAN"; + rule.addBean("foo", bean, String.class); + throw new RuntimeException( + "TEST EXCEPTION"); + } + }, + Description.createSuiteDescription("MOCK")) + .evaluate()); + assertThat(exception.getMessage(), containsString("TEST EXCEPTION")); } @Test diff --git a/geowebcache/core/src/test/java/org/geowebcache/blobstore/file/FileBlobStoreComformanceTest.java b/geowebcache/core/src/test/java/org/geowebcache/blobstore/file/FileBlobStoreComformanceTest.java index 0050490bf..23c360614 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/blobstore/file/FileBlobStoreComformanceTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/blobstore/file/FileBlobStoreComformanceTest.java @@ -14,9 +14,9 @@ */ package org.geowebcache.blobstore.file; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/BlobStoreConfigurationTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/BlobStoreConfigurationTest.java index 45bbacbd7..30266fa3d 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/BlobStoreConfigurationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/BlobStoreConfigurationTest.java @@ -19,13 +19,14 @@ import static org.easymock.EasyMock.verify; import static org.geowebcache.util.TestUtils.isPresent; import static org.geowebcache.util.TestUtils.notPresent; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.arrayContainingInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import java.io.IOException; import java.util.Collection; @@ -87,14 +88,12 @@ public void testRollBackOnUnsuitableStorageExceptionInAddHandler() throws Except expectLastCall().andThrow(new UnsuitableStorageException("TEST")); EasyMock.replay(listener); config.addBlobStoreListener(listener); - exception.expect(instanceOf(ConfigurationPersistenceException.class)); - exception.expectCause(instanceOf(UnsuitableStorageException.class)); - try { - config.addBlobStore(info); - } finally { - verify(listener); - assertThat(config.getBlobStore("test"), notPresent()); - } + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, () -> config.addBlobStore(info)); + assertThat(exception.getCause(), instanceOf(UnsuitableStorageException.class)); + verify(listener); + assertThat(config.getBlobStore("test"), notPresent()); } @Test @@ -109,14 +108,13 @@ public void testRollBackOnUnsuitableStorageExceptionInModifyHandler() throws Exc EasyMock.replay(listener); config.addBlobStoreListener(listener); config.addBlobStore(info1); - exception.expect(instanceOf(ConfigurationPersistenceException.class)); - exception.expectCause(instanceOf(UnsuitableStorageException.class)); - try { - config.modifyBlobStore(info2); - } finally { - verify(listener); - assertThat(config.getBlobStore("test"), isPresent(infoEquals(info1))); - } + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, + () -> config.modifyBlobStore(info2)); + assertThat(exception.getCause(), instanceOf(UnsuitableStorageException.class)); + verify(listener); + assertThat(config.getBlobStore("test"), isPresent(infoEquals(info1))); } @Test @@ -142,14 +140,13 @@ public void testRollBackOnSupressedUnsuitableStorageExceptionInModifyHandler() config.addBlobStoreListener(listener1); config.addBlobStoreListener(listener2); config.addBlobStore(info1); - exception.expect(instanceOf(ConfigurationPersistenceException.class)); - exception.expectCause(instanceOf(IOException.class)); - try { - config.modifyBlobStore(info2); - } finally { - control.verify(); - assertThat(config.getBlobStore("test"), isPresent(infoEquals(info1))); - } + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, + () -> config.modifyBlobStore(info2)); + assertThat(exception.getCause(), instanceOf(IOException.class)); + control.verify(); + assertThat(config.getBlobStore("test"), isPresent(infoEquals(info1))); } @Test @@ -168,14 +165,12 @@ public void testRollBackOnSupressedUnsuitableStorageExceptionInAddHandler() thro control.replay(); config.addBlobStoreListener(listener1); config.addBlobStoreListener(listener2); - exception.expect(instanceOf(ConfigurationPersistenceException.class)); - exception.expectCause(instanceOf(IOException.class)); - try { - config.addBlobStore(info1); - } finally { - control.verify(); - assertThat(config.getBlobStore("test"), notPresent()); - } + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, () -> config.addBlobStore(info1)); + assertThat(exception.getCause(), instanceOf(IOException.class)); + control.verify(); + assertThat(config.getBlobStore("test"), notPresent()); } @Test @@ -464,12 +459,10 @@ public void testExceptionInAddListenerIsWrapped() throws Exception { EasyMock.expectLastCall().andThrow(ex); EasyMock.replay(listener); - exception.expect( - allOf( - instanceOf(ConfigurationPersistenceException.class), - hasProperty("cause", sameInstance(ex)))); - - this.addInfo(this.config, goodInfo); + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, () -> addInfo(config, goodInfo)); + assertThat(exception.getCause(), sameInstance(ex)); } @Test @@ -537,18 +530,14 @@ public void testExceptionInAddListenerRecordsSuppressedExceptions() throws Excep EasyMock.replay(listener1, listener2); - exception.expect( + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, () -> addInfo(config, goodInfo)); + assertThat( + exception.getCause(), allOf( - instanceOf(ConfigurationPersistenceException.class), - hasProperty( - "cause", - allOf( - sameInstance(ex2), - hasProperty( - "suppressed", - arrayContainingInAnyOrder(sameInstance(ex1))))))); - - this.addInfo(this.config, goodInfo); + sameInstance(ex2), + hasProperty("suppressed", arrayContainingInAnyOrder(sameInstance(ex1))))); } // Exceptions during modify handlers @@ -564,12 +553,11 @@ public void testExceptionInModifyListenerIsWrapped() throws Exception { EasyMock.expectLastCall().andThrow(ex); EasyMock.replay(listener); - exception.expect( - allOf( - instanceOf(ConfigurationPersistenceException.class), - hasProperty("cause", sameInstance(ex)))); - - this.modifyInfo(this.config, goodInfo); + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, + () -> modifyInfo(config, goodInfo)); + assertThat(exception.getCause(), sameInstance(ex)); } /** @@ -650,18 +638,19 @@ public void testExceptionInModifyListenerRecordsSuppressedExceptions() throws Ex EasyMock.replay(listener1, listener2); - exception.expect( - allOf( - instanceOf(ConfigurationPersistenceException.class), - hasProperty( - "cause", - allOf( - sameInstance(ex2), - hasProperty( - "suppressed", - arrayContainingInAnyOrder(sameInstance(ex1))))))); - - this.modifyInfo(this.config, goodInfo); + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, + () -> modifyInfo(config, goodInfo)); + assertThat( + exception, + hasProperty( + "cause", + allOf( + sameInstance(ex2), + hasProperty( + "suppressed", + arrayContainingInAnyOrder(sameInstance(ex1)))))); } // Exceptions during rename handlers @@ -689,12 +678,11 @@ public void testExceptionInRenameListenerIsWrapped() throws Exception { EasyMock.expectLastCall().andThrow(ex); EasyMock.replay(listener); - exception.expect( - allOf( - instanceOf(ConfigurationPersistenceException.class), - hasProperty("cause", sameInstance(ex)))); - - this.renameInfo(this.config, "test", "test2"); + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, + () -> renameInfo(config, "test", "test2")); + assertThat(exception.getCause(), sameInstance(ex)); } @Test @@ -763,18 +751,19 @@ public void testExceptionInRenameListenerRecordsSuppressedExceptions() throws Ex EasyMock.replay(listener1, listener2); - exception.expect( - allOf( - instanceOf(ConfigurationPersistenceException.class), - hasProperty( - "cause", - allOf( - sameInstance(ex2), - hasProperty( - "suppressed", - arrayContainingInAnyOrder(sameInstance(ex1))))))); - - this.renameInfo(this.config, "test", "test2"); + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, + () -> renameInfo(config, "test", "test2")); + assertThat( + exception, + hasProperty( + "cause", + allOf( + sameInstance(ex2), + hasProperty( + "suppressed", + arrayContainingInAnyOrder(sameInstance(ex1)))))); } // Exceptions during remove handlers @@ -802,12 +791,10 @@ public void testExceptionInRemoveListenerIsWrapped() throws Exception { EasyMock.expectLastCall().andThrow(ex); EasyMock.replay(listener); - exception.expect( - allOf( - instanceOf(ConfigurationPersistenceException.class), - hasProperty("cause", sameInstance(ex)))); - - this.removeInfo(this.config, "test"); + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, () -> removeInfo(config, "test")); + assertThat(exception.getCause(), sameInstance(ex)); } @Test @@ -876,17 +863,17 @@ public void testExceptionInRemoveListenerRecordsSuppressedExceptions() throws Ex EasyMock.replay(listener1, listener2); - exception.expect( - allOf( - instanceOf(ConfigurationPersistenceException.class), - hasProperty( - "cause", - allOf( - sameInstance(ex2), - hasProperty( - "suppressed", - arrayContainingInAnyOrder(sameInstance(ex1))))))); - - this.removeInfo(this.config, "test"); + ConfigurationPersistenceException exception = + assertThrows( + ConfigurationPersistenceException.class, () -> removeInfo(config, "test")); + assertThat( + exception, + hasProperty( + "cause", + allOf( + sameInstance(ex2), + hasProperty( + "suppressed", + arrayContainingInAnyOrder(sameInstance(ex1)))))); } } diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/ConfigurationTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/ConfigurationTest.java index 670cc7c15..6067c3dda 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/ConfigurationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/ConfigurationTest.java @@ -18,11 +18,11 @@ import static org.geowebcache.util.TestUtils.isPresent; import static org.geowebcache.util.TestUtils.notPresent; import static org.geowebcache.util.TestUtils.requirePresent; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import java.util.ArrayList; import java.util.Collection; @@ -37,16 +37,12 @@ import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public abstract class ConfigurationTest { protected C config; - @Rule public ExpectedException exception = ExpectedException.none(); - @Before public void setUpTestUnit() throws Exception { config = getConfig(); @@ -82,11 +78,7 @@ public void testDoubleAddException() throws Exception { I doubleGridSet = getGoodInfo("test", 2); assertThat("Invalid test", goodGridSet, not(infoEquals(doubleGridSet))); addInfo(config, goodGridSet); - exception.expect( - instanceOf( - IllegalArgumentException - .class)); // May want to change to something more specific. - addInfo(config, doubleGridSet); + assertThrows(IllegalArgumentException.class, () -> addInfo(config, doubleGridSet)); } @Test @@ -107,9 +99,7 @@ public void testDoubleAddNoChange() throws Exception { @Test public void testAddBadInfoException() throws Exception { I badGridSet = getBadInfo("test", 1); - exception.expect( - IllegalArgumentException.class); // May want to change to something more specific. - addInfo(config, badGridSet); + assertThrows(IllegalArgumentException.class, () -> addInfo(config, badGridSet)); } @Test @@ -154,8 +144,8 @@ public void testGetNotExists() throws Exception { @Test public void testRemoveNotExists() throws Exception { - exception.expect(NoSuchElementException.class); - removeInfo(config, "GridSetThatDoesntExist"); + assertThrows( + NoSuchElementException.class, () -> removeInfo(config, "GridSetThatDoesntExist")); } @Test @@ -172,10 +162,7 @@ public void testModify() throws Exception { public void testModifyBadGridSetException() throws Exception { testAdd(); I badGridSet = getBadInfo("test", 2); - - exception.expect(IllegalArgumentException.class); // Could be more specific - - modifyInfo(config, badGridSet); + assertThrows(IllegalArgumentException.class, () -> modifyInfo(config, badGridSet)); } @Test @@ -211,8 +198,7 @@ public void testPersistModify() throws Exception { @Test public void testModifyNotExistsExcpetion() throws Exception { I goodGridSet = getGoodInfo("test", 2); - exception.expect(NoSuchElementException.class); - modifyInfo(config, goodGridSet); + assertThrows(NoSuchElementException.class, () -> modifyInfo(config, goodGridSet)); } @Test @@ -302,21 +288,17 @@ public void testNoChangeOnPersistExceptionOnAdd() throws Exception { // Force a failure failNextWrite(); - exception.expect(ConfigurationPersistenceException.class); - try { - addInfo(config, goodGridSet); - } finally { - // Should be unchanged - Optional retrieved = getInfo(config, "test"); - assertThat(retrieved, notPresent()); - - // Persistence should also be unchanged - C config2 = getSecondConfig(); - Optional retrieved2 = getInfo(config2, "test"); - assertThat(retrieved2, notPresent()); - assertNameSetMatchesCollection(config2); - } + assertThrows(ConfigurationPersistenceException.class, () -> addInfo(config, goodGridSet)); + // Should be unchanged + Optional retrieved = getInfo(config, "test"); + assertThat(retrieved, notPresent()); + + // Persistence should also be unchanged + C config2 = getSecondConfig(); + Optional retrieved2 = getInfo(config2, "test"); + assertThat(retrieved2, notPresent()); + assertNameSetMatchesCollection(config2); } @Test diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/DefaultGridsetsConfigurationGridsetConformanceTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/DefaultGridsetsConfigurationGridsetConformanceTest.java index efb7674f4..436092e8d 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/DefaultGridsetsConfigurationGridsetConformanceTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/DefaultGridsetsConfigurationGridsetConformanceTest.java @@ -14,8 +14,8 @@ */ package org.geowebcache.config; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; import org.geowebcache.grid.GridSet; import org.hamcrest.CustomMatcher; diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/FileBlobStoreConfigTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/FileBlobStoreConfigTest.java index e9df72d9f..df7e73f9a 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/FileBlobStoreConfigTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/FileBlobStoreConfigTest.java @@ -14,7 +14,10 @@ */ package org.geowebcache.config; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; import com.google.common.base.Preconditions; @@ -26,7 +29,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; public class FileBlobStoreConfigTest { @@ -35,8 +37,6 @@ public class FileBlobStoreConfigTest { @Rule public TemporaryFolder tmp = new TemporaryFolder(); - @Rule public ExpectedException ex = ExpectedException.none(); - private TileLayerDispatcher layers; private LockProvider lockProvider; @@ -50,27 +50,33 @@ public void before() { @Test public void testCreateInstanceNoId() throws StorageException { - ex.expect(IllegalStateException.class); - ex.expectMessage("id not set"); - config.createInstance(layers, lockProvider); + IllegalStateException exception = + assertThrows( + IllegalStateException.class, + () -> config.createInstance(layers, lockProvider)); + assertThat(exception.getMessage(), containsString("id not set")); } @Test public void testCreateInstanceNotEnabled() throws StorageException { config.setName("myblobstore"); config.setEnabled(false); - ex.expect(IllegalStateException.class); - ex.expectMessage("store is not enabled"); - config.createInstance(layers, lockProvider); + IllegalStateException exception = + assertThrows( + IllegalStateException.class, + () -> config.createInstance(layers, lockProvider)); + assertThat(exception.getMessage(), containsString("store is not enabled")); } @Test public void testCreateInstanceNoBaseDirectory() throws StorageException { config.setName("myblobstore"); config.setEnabled(true); - ex.expect(IllegalStateException.class); - ex.expectMessage("baseDirectory not provided"); - config.createInstance(layers, lockProvider); + IllegalStateException exception = + assertThrows( + IllegalStateException.class, + () -> config.createInstance(layers, lockProvider)); + assertThat(exception.getMessage(), containsString("baseDirectory not provided")); } @Test @@ -79,9 +85,11 @@ public void testCreateInstanceIllegalBlockSize() throws StorageException { config.setEnabled(true); config.setFileSystemBlockSize(-2048); config.setBaseDirectory(tmp.getRoot().getAbsolutePath()); - ex.expect(IllegalStateException.class); - ex.expectMessage("must be a positive integer"); - config.createInstance(layers, lockProvider); + IllegalStateException exception = + assertThrows( + IllegalStateException.class, + () -> config.createInstance(layers, lockProvider)); + assertThat(exception.getMessage(), containsString("must be a positive integer")); } @Test diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/GridSetConfigurationTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/GridSetConfigurationTest.java index 1c7737764..9e71c2de4 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/GridSetConfigurationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/GridSetConfigurationTest.java @@ -14,8 +14,8 @@ */ package org.geowebcache.config; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; import java.util.Collection; import java.util.Optional; diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/LayerConfigurationTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/LayerConfigurationTest.java index 99fc1a465..b25d49ef3 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/LayerConfigurationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/LayerConfigurationTest.java @@ -14,8 +14,8 @@ */ package org.geowebcache.config; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; import java.util.Collection; import java.util.Optional; diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/ListenerCollectionTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/ListenerCollectionTest.java index ce238b843..b5f7e0944 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/ListenerCollectionTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/ListenerCollectionTest.java @@ -14,22 +14,20 @@ */ package org.geowebcache.config; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.sameInstance; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.fail; import org.easymock.EasyMock; import org.easymock.IMocksControl; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class ListenerCollectionTest { - @Rule public ExpectedException exception = ExpectedException.none(); - @Test public void testEmpty() throws Exception { ListenerCollection collection = new ListenerCollection<>(); @@ -117,13 +115,11 @@ public void testException() throws Exception { control.replay(); - try { - collection.add(l1); - exception.expect(sameInstance(e1)); - collection.safeForEach(Runnable::run); - } finally { - control.verify(); - } + collection.add(l1); + Exception exception = + assertThrows(Exception.class, () -> collection.safeForEach(Runnable::run)); + assertThat(exception, sameInstance(e1)); + control.verify(); } @Test @@ -143,14 +139,12 @@ public void testExceptionDoesntPreventOthers() throws Exception { control.replay(); - try { - collection.add(l1); - collection.add(l2); - exception.expect(sameInstance(e1)); - collection.safeForEach(Runnable::run); - } finally { - control.verify(); - } + collection.add(l1); + collection.add(l2); + Exception exception = + assertThrows(Exception.class, () -> collection.safeForEach(Runnable::run)); + assertThat(exception, sameInstance(e1)); + control.verify(); } @SuppressWarnings("unchecked") @@ -172,15 +166,14 @@ public void testSuppressedExceptionsRecorded() throws Exception { control.replay(); - try { - collection.add(l1); - collection.add(l2); - exception.expect( - both(sameInstance(e2)) - .and(hasProperty("suppressed", arrayContaining(sameInstance(e1))))); - collection.safeForEach(Runnable::run); - } finally { - control.verify(); - } + collection.add(l1); + collection.add(l2); + Exception exception = + assertThrows(Exception.class, () -> collection.safeForEach(Runnable::run)); + assertThat( + exception, + both(sameInstance(e2)) + .and(hasProperty("suppressed", arrayContaining(sameInstance(e1))))); + control.verify(); } } diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/ServerConfigurationTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/ServerConfigurationTest.java index 3cf82ca5b..bca5a1a94 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/ServerConfigurationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/ServerConfigurationTest.java @@ -14,12 +14,12 @@ */ package org.geowebcache.config; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasProperty; 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.assertTrue; import java.io.File; diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationConstructorsTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationConstructorsTest.java index 29ddcd7bd..b73f576fb 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationConstructorsTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationConstructorsTest.java @@ -21,7 +21,7 @@ import static org.easymock.EasyMock.verify; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.File; import java.io.IOException; diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationLayerConformanceTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationLayerConformanceTest.java index 8ffc3b09f..35179594d 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationLayerConformanceTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationLayerConformanceTest.java @@ -15,8 +15,8 @@ package org.geowebcache.config; import static org.geowebcache.util.TestUtils.isPresent; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasProperty; -import static org.junit.Assert.assertThat; import java.io.File; import java.io.IOException; diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationTest.java index 5ca6b1e7f..bc8ddb76b 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationTest.java @@ -17,6 +17,7 @@ import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -27,7 +28,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationXSchemaTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationXSchemaTest.java index 154138aeb..3fa8dc99a 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationXSchemaTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationXSchemaTest.java @@ -14,8 +14,9 @@ */ package org.geowebcache.config; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import com.thoughtworks.xstream.XStream; import java.util.Collections; @@ -26,14 +27,11 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.StaticWebApplicationContext; public class XMLConfigurationXSchemaTest { - @Rule public ExpectedException exception = ExpectedException.none(); - @Rule public PropertyRule whitelistProperty = PropertyRule.system("GEOWEBCACHE_XSTREAM_WHITELIST"); @@ -42,15 +40,12 @@ public void testNotAllowNonGWCClass() throws Exception { // Check that classes from other packages on the class path can't be serialized ContextualConfigurationProvider.Context pc = ContextualConfigurationProvider.Context.REST; try (StaticWebApplicationContext wac = new StaticWebApplicationContext()) { - - XStream xs = new GeoWebCacheXStream(); - - xs = XMLConfiguration.getConfiguredXStreamWithContext(xs, wac, pc); - - exception.expect(com.thoughtworks.xstream.security.ForbiddenClassException.class); - - @SuppressWarnings("unused") - Object o = xs.fromXML("<" + org.easymock.Capture.class.getCanonicalName() + " />"); + XStream xs = + XMLConfiguration.getConfiguredXStreamWithContext( + new GeoWebCacheXStream(), wac, pc); + assertThrows( + com.thoughtworks.xstream.security.ForbiddenClassException.class, + () -> xs.fromXML("<" + org.easymock.Capture.class.getCanonicalName() + " />")); } } @@ -60,16 +55,16 @@ public void testNotAllowNonXMLGWCClass() throws Exception { // Check that a class in GWC that shouldn't be serialized to XML can't be ContextualConfigurationProvider.Context pc = ContextualConfigurationProvider.Context.REST; try (StaticWebApplicationContext wac = new StaticWebApplicationContext()) { - - XStream xs = new GeoWebCacheXStream(); - - xs = XMLConfiguration.getConfiguredXStreamWithContext(xs, wac, pc); - - exception.expect(com.thoughtworks.xstream.security.ForbiddenClassException.class); - - @SuppressWarnings("unused") - Object o = - xs.fromXML("<" + XMLConfigurationXSchemaTest.class.getCanonicalName() + " />"); + XStream xs = + XMLConfiguration.getConfiguredXStreamWithContext( + new GeoWebCacheXStream(), wac, pc); + assertThrows( + com.thoughtworks.xstream.security.ForbiddenClassException.class, + () -> + xs.fromXML( + "<" + + XMLConfigurationXSchemaTest.class.getCanonicalName() + + " />")); } } diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/legends/LegendInfoBuilderTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/legends/LegendInfoBuilderTest.java index 01e49f63a..9b8d58770 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/legends/LegendInfoBuilderTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/legends/LegendInfoBuilderTest.java @@ -14,9 +14,9 @@ */ package org.geowebcache.config.legends; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; import org.junit.Test; diff --git a/geowebcache/core/src/test/java/org/geowebcache/conveyor/ConveyorTileTest.java b/geowebcache/core/src/test/java/org/geowebcache/conveyor/ConveyorTileTest.java index 094d46026..136931660 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/conveyor/ConveyorTileTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/conveyor/ConveyorTileTest.java @@ -14,9 +14,8 @@ */ package org.geowebcache.conveyor; -import org.geowebcache.grid.GridSubset; -import org.hamcrest.Matchers; -import org.junit.Assert; +import static org.junit.Assert.assertNull; + import org.junit.Test; public class ConveyorTileTest { @@ -26,7 +25,6 @@ public void testGetGridSubsetWithNullGridsetId() { // All these nulls may need to be replace with mocks eventually. ConveyorTile tile = new ConveyorTile(null, null, null, null); tile.setGridSetId(null); // Should be this already but just to make sure. - GridSubset result = tile.getGridSubset(); - Assert.assertThat(result, Matchers.nullValue()); + assertNull(tile.getGridSubset()); } } diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/FloatParameterFilterTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/FloatParameterFilterTest.java index c6e060fe6..625af935a 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/FloatParameterFilterTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/FloatParameterFilterTest.java @@ -14,12 +14,12 @@ */ package org.geowebcache.filter.parameters; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import com.thoughtworks.xstream.XStream; diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/IntegerParameterFilterTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/IntegerParameterFilterTest.java index 627ac9673..5d1b5bcb6 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/IntegerParameterFilterTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/IntegerParameterFilterTest.java @@ -14,12 +14,12 @@ */ package org.geowebcache.filter.parameters; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import com.thoughtworks.xstream.XStream; diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/ParametersUtilsTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/ParametersUtilsTest.java index 5c4efcd9b..50804784a 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/ParametersUtilsTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/ParametersUtilsTest.java @@ -14,10 +14,10 @@ */ package org.geowebcache.filter.parameters; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.isEmptyString; -import static org.junit.Assert.assertThat; import java.util.Collections; import java.util.Map; diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/RegexParameterFilterTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/RegexParameterFilterTest.java index fa68f88da..5bb9665cb 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/RegexParameterFilterTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/RegexParameterFilterTest.java @@ -14,6 +14,7 @@ */ package org.geowebcache.filter.parameters; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; @@ -21,7 +22,6 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/StringParameterFilterTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/StringParameterFilterTest.java index cf4bc98b3..ff32968d4 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/StringParameterFilterTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/StringParameterFilterTest.java @@ -14,13 +14,13 @@ */ package org.geowebcache.filter.parameters; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import com.thoughtworks.xstream.XStream; diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/security/SecurityDispatcherTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/security/SecurityDispatcherTest.java index b597edcc4..28acf6596 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/security/SecurityDispatcherTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/security/SecurityDispatcherTest.java @@ -14,7 +14,7 @@ */ package org.geowebcache.filter.security; -import static org.hamcrest.Matchers.instanceOf; +import static org.junit.Assert.assertThrows; import org.easymock.EasyMock; import org.geowebcache.MockExtensionRule; @@ -25,14 +25,11 @@ import org.geowebcache.layer.TileLayer; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class SecurityDispatcherTest { @Rule public MockExtensionRule extensions = new MockExtensionRule(); - @Rule public ExpectedException exception = ExpectedException.none(); - @Test public void testOneFilterPass() throws Exception { @@ -94,12 +91,8 @@ public void testOneFilterFail() throws Exception { EasyMock.replay(conv, layer, subset, srs, filter); - exception.expect(instanceOf(SecurityException.class)); - try { - secDispatcher.checkSecurity(conv); - } finally { - EasyMock.verify(conv, layer, subset, srs, filter); - } + assertThrows(SecurityException.class, () -> secDispatcher.checkSecurity(conv)); + EasyMock.verify(conv, layer, subset, srs, filter); } @Test @@ -171,12 +164,8 @@ public void testTwoFilterFail() throws Exception { EasyMock.replay(conv, layer, subset, srs, filter1, filter2); - exception.expect(instanceOf(SecurityException.class)); - try { - secDispatcher.checkSecurity(conv); - } finally { - EasyMock.verify(conv, layer, subset, srs, filter1, filter2); - } + assertThrows(SecurityException.class, () -> secDispatcher.checkSecurity(conv)); + EasyMock.verify(conv, layer, subset, srs, filter1, filter2); } @Test diff --git a/geowebcache/core/src/test/java/org/geowebcache/grid/DefaultGridSetsTest.java b/geowebcache/core/src/test/java/org/geowebcache/grid/DefaultGridSetsTest.java index 862d43b1c..f5e1e9edd 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/grid/DefaultGridSetsTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/grid/DefaultGridSetsTest.java @@ -14,10 +14,10 @@ */ package org.geowebcache.grid; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import java.util.Arrays; import org.geowebcache.config.DefaultGridsets; diff --git a/geowebcache/core/src/test/java/org/geowebcache/grid/GridSetBrokerTest.java b/geowebcache/core/src/test/java/org/geowebcache/grid/GridSetBrokerTest.java index eda5ebdbd..c58479295 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/grid/GridSetBrokerTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/grid/GridSetBrokerTest.java @@ -16,6 +16,7 @@ import static org.geowebcache.util.TestUtils.isPresent; import static org.geowebcache.util.TestUtils.notPresent; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasProperty; @@ -24,7 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; diff --git a/geowebcache/core/src/test/java/org/geowebcache/grid/GridSetTest.java b/geowebcache/core/src/test/java/org/geowebcache/grid/GridSetTest.java index 0f0be92d2..3895c5e3b 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/grid/GridSetTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/grid/GridSetTest.java @@ -1,23 +1,20 @@ package org.geowebcache.grid; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import java.util.Collections; import org.geowebcache.config.DefaultGridsets; import org.hamcrest.Matcher; import org.hamcrest.Matchers; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class GridSetTest { - public @Rule ExpectedException exception = ExpectedException.none(); - GridSetBroker gridSetBroker = new GridSetBroker(Collections.singletonList(new DefaultGridsets(false, false))); @@ -174,14 +171,12 @@ public void testGetLeftTopCorner() throws Exception { @Test public void testClosestIndexInvalidBounds1() throws Exception { BoundingBox box = new BoundingBox(0, -180, 180.0, 0); - exception.expect(GridAlignmentMismatchException.class); - gridSetTL.closestIndex(box); + assertThrows(GridAlignmentMismatchException.class, () -> gridSetTL.closestIndex(box)); } @Test public void testClosestIndexInvalidBounds2() throws Exception { BoundingBox box = new BoundingBox(0, 0, 180.0, 180); - exception.expect(GridAlignmentMismatchException.class); - gridSetTL.closestIndex(box); + assertThrows(GridAlignmentMismatchException.class, () -> gridSetTL.closestIndex(box)); } } diff --git a/geowebcache/core/src/test/java/org/geowebcache/layer/wms/TileLayerTest.java b/geowebcache/core/src/test/java/org/geowebcache/layer/wms/TileLayerTest.java index cb9ef3fac..69572b58c 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/layer/wms/TileLayerTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/layer/wms/TileLayerTest.java @@ -1,11 +1,11 @@ package org.geowebcache.layer.wms; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalToIgnoringCase; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; import java.util.Arrays; import java.util.Collection; diff --git a/geowebcache/core/src/test/java/org/geowebcache/layer/wms/WMSLayerTest.java b/geowebcache/core/src/test/java/org/geowebcache/layer/wms/WMSLayerTest.java index 353bbdaea..10bf8d4b1 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/layer/wms/WMSLayerTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/layer/wms/WMSLayerTest.java @@ -22,10 +22,10 @@ import static org.geowebcache.TestHelpers.createRequest; import static org.geowebcache.TestHelpers.createWMSLayer; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.awt.Color; diff --git a/geowebcache/core/src/test/java/org/geowebcache/seed/TruncateBboxRequestTest.java b/geowebcache/core/src/test/java/org/geowebcache/seed/TruncateBboxRequestTest.java index f408ca56a..779fa8c25 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/seed/TruncateBboxRequestTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/seed/TruncateBboxRequestTest.java @@ -15,12 +15,12 @@ package org.geowebcache.seed; import static org.easymock.EasyMock.eq; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.any; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; import java.util.Arrays; import java.util.Collections; diff --git a/geowebcache/core/src/test/java/org/geowebcache/storage/AbstractBlobStoreTest.java b/geowebcache/core/src/test/java/org/geowebcache/storage/AbstractBlobStoreTest.java index 1f8c0cc5c..5f298eb06 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/storage/AbstractBlobStoreTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/storage/AbstractBlobStoreTest.java @@ -21,6 +21,7 @@ import static org.easymock.EasyMock.geq; import static org.easymock.EasyMock.isNull; import static org.geowebcache.util.FileMatchers.resource; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.describedAs; import static org.hamcrest.Matchers.empty; @@ -30,7 +31,6 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; import java.nio.charset.StandardCharsets; import java.util.Arrays; diff --git a/geowebcache/core/src/test/java/org/geowebcache/storage/BlobStoreSuitabilityTest.java b/geowebcache/core/src/test/java/org/geowebcache/storage/BlobStoreSuitabilityTest.java index a553c74dc..42d4148bc 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/storage/BlobStoreSuitabilityTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/storage/BlobStoreSuitabilityTest.java @@ -14,17 +14,17 @@ */ package org.geowebcache.storage; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.either; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import static org.junit.Assume.assumeThat; import org.hamcrest.Matcher; import org.junit.Rule; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; /** @@ -45,7 +45,6 @@ public abstract class BlobStoreSuitabilityTest { public abstract BlobStore create(Object dir) throws Exception; - @Rule public ExpectedException exception = ExpectedException.none(); static final Class EXCEPTION_CLASS = StorageException.class; public BlobStoreSuitabilityTest() { @@ -65,10 +64,7 @@ public void emptyOk(Object persistenceLocation) throws Exception { public void emptyFail(Object persistenceLocation) throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EMPTY); assumeThat(persistenceLocation, not(empty())); - - exception.expect(EXCEPTION_CLASS); - @SuppressWarnings("unused") - BlobStore store = create(persistenceLocation); + assertThrows(EXCEPTION_CLASS, () -> create(persistenceLocation)); } @Theory @@ -84,10 +80,7 @@ public void existingOk(Object persistenceLocation) throws Exception { public void existingFail(Object persistenceLocation) throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EXISTING); assumeThat(persistenceLocation, not(either(empty()).or(existing()))); - - exception.expect(EXCEPTION_CLASS); - @SuppressWarnings("unused") - BlobStore store = create(persistenceLocation); + assertThrows(EXCEPTION_CLASS, () -> create(persistenceLocation)); } @Theory diff --git a/geowebcache/core/src/test/java/org/geowebcache/storage/CompositeBlobStoreConfigurationIntegrationTest.java b/geowebcache/core/src/test/java/org/geowebcache/storage/CompositeBlobStoreConfigurationIntegrationTest.java index 672465a34..9a7f0b410 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/storage/CompositeBlobStoreConfigurationIntegrationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/storage/CompositeBlobStoreConfigurationIntegrationTest.java @@ -14,10 +14,6 @@ */ package org.geowebcache.storage; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -27,15 +23,11 @@ import org.geowebcache.GeoWebCacheException; import org.geowebcache.MockWepAppContextRule; import org.geowebcache.config.BlobStoreInfo; -import org.geowebcache.config.ConfigurationException; -import org.geowebcache.config.ConfigurationPersistenceException; import org.geowebcache.config.FileBlobStoreInfo; import org.geowebcache.config.GWCConfigIntegrationTest; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; /** @@ -54,8 +46,6 @@ public class CompositeBlobStoreConfigurationIntegrationTest extends GWCConfigInt @Rule public MockWepAppContextRule context = new MockWepAppContextRule(); - @Rule public ExpectedException exception = ExpectedException.none(); - @Override @Before public void setUpTest() throws Exception { @@ -199,25 +189,4 @@ public void testRemove() throws IOException { blobStoreAggregator.removeBlobStore("newFileBlobStore"); assertFalse(compositeBlobStore.blobStores.containsKey("newFileBlobStore")); } - - @Ignore // The state of not having a default blobstore is allowed, so removing it should be - // allowed. - @Test - public void testRemoveDefault() throws IOException { - testAddDefault(); - - try { - exception.expect(ConfigurationPersistenceException.class); - exception.expectCause( - allOf( - instanceOf(ConfigurationException.class), - hasProperty( - "message", - containsString("default blob store can't be removed")))); - blobStoreAggregator.removeBlobStore("newFileBlobStore"); - } finally { - assertTrue(compositeBlobStore.blobStores.containsKey("newFileBlobStore")); - assertTrue(blobStoreAggregator.blobStoreExists("newFileBlobStore")); - } - } } diff --git a/geowebcache/core/src/test/java/org/geowebcache/storage/CompositeBlobStoreTest.java b/geowebcache/core/src/test/java/org/geowebcache/storage/CompositeBlobStoreTest.java index 5b229946e..4f32513de 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/storage/CompositeBlobStoreTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/storage/CompositeBlobStoreTest.java @@ -14,13 +14,15 @@ */ package org.geowebcache.storage; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; @@ -45,7 +47,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; @@ -74,8 +75,6 @@ public boolean matches(Object argument) { @Rule public TemporaryFolder tmpFolder = new TemporaryFolder(); - @Rule public ExpectedException ex = ExpectedException.none(); - @Rule public SuitabilityCheckRule suitability = SuitabilityCheckRule.system(); TileLayerDispatcher layers; @@ -157,9 +156,8 @@ public void duplicateDefaultStoreFails() throws Exception { configs.add( config("store2", isDefault, true, tmpFolder.newFolder().getAbsolutePath(), 2048)); - ex.expect(ConfigurationException.class); - ex.expectMessage("Duplicate default blob store"); - store = create(); + Exception ex = assertThrows(ConfigurationException.class, () -> store = create()); + assertThat(ex.getMessage(), containsString("Duplicate default blob store")); } @Test @@ -167,9 +165,8 @@ public void nullStoreIdFails() throws Exception { String id = null; configs.add(config(id, true, true, tmpFolder.newFolder().getAbsolutePath(), 1024)); - ex.expect(ConfigurationException.class); - ex.expectMessage("No id provided for blob store"); - store = create(); + Exception ex = assertThrows(ConfigurationException.class, () -> store = create()); + assertThat(ex.getMessage(), containsString("No id provided for blob store")); } @Test @@ -178,9 +175,8 @@ public void duplicateStoreIdFails() throws Exception { configs.add(config(id, true, true, tmpFolder.newFolder().getAbsolutePath(), 1024)); configs.add(config(id, true, true, tmpFolder.newFolder().getAbsolutePath(), 1024)); - ex.expect(ConfigurationException.class); - ex.expectMessage("Duplicate blob store id"); - store = create(); + Exception ex = assertThrows(ConfigurationException.class, () -> store = create()); + assertThat(ex.getMessage(), containsString("Duplicate blob store id")); } @Test @@ -195,9 +191,8 @@ public void defaultAndDisaledFails() throws Exception { tmpFolder.newFolder().getAbsolutePath(), 1024)); - ex.expect(ConfigurationException.class); - ex.expectMessage("The default blob store can't be disabled"); - store = create(); + Exception ex = assertThrows(ConfigurationException.class, () -> store = create()); + assertThat(ex.getMessage(), containsString("The default blob store can't be disabled")); } @Test @@ -216,9 +211,8 @@ public void reservedDefaultIdInvalidInConfig() throws Exception { String id = CompositeBlobStore.DEFAULT_STORE_DEFAULT_ID; configs.add(config(id, true, true, tmpFolder.newFolder().getAbsolutePath(), 1024)); - ex.expect(ConfigurationException.class); - ex.expectMessage(id + " is a reserved identifier"); - store = create(); + Exception ex = assertThrows(ConfigurationException.class, () -> store = create()); + assertThat(ex.getMessage(), containsString(id + " is a reserved identifier")); } @Test @@ -252,9 +246,9 @@ public void getTileInvalidBlobStore() throws Exception { store = create(); when(defaultLayer.getBlobStoreId()).thenReturn("nonExistentStore"); - ex.expect(StorageException.class); - ex.expectMessage("No BlobStore with id 'nonExistentStore' found"); - store.get(queryTile(0, 0, 0)); + Exception ex = assertThrows(StorageException.class, () -> store.get(queryTile(0, 0, 0))); + assertThat( + ex.getMessage(), containsString("No BlobStore with id 'nonExistentStore' found")); } @Test @@ -280,9 +274,8 @@ public void getTileInvalidLayer() throws Exception { when(defaultLayer.getBlobStoreId()).thenReturn(null); TileObject tile = queryTile("someLayer", DEFAULT_GRIDSET, DEFAULT_FORMAT, 0, 0, 0); - ex.expect(StorageException.class); - ex.expectMessage("layer not found"); - store.get(tile); + Exception ex = assertThrows(StorageException.class, () -> store.get(tile)); + assertThat(ex.getMessage(), containsString("layer not found")); } @Test @@ -296,9 +289,9 @@ public void getTileDisabledStore() throws Exception { when(defaultLayer.getBlobStoreId()).thenReturn("store1"); TileObject tile = queryTile(0, 0, 0); - ex.expect(StorageException.class); - ex.expectMessage("Attempted to use a blob store that's disabled"); - store.get(tile); + Exception ex = assertThrows(StorageException.class, () -> store.get(tile)); + assertThat( + ex.getMessage(), containsString("Attempted to use a blob store that's disabled")); } @Test diff --git a/geowebcache/core/src/test/java/org/geowebcache/storage/TransientCacheTest.java b/geowebcache/core/src/test/java/org/geowebcache/storage/TransientCacheTest.java index d1a045eb2..12808cf4d 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/storage/TransientCacheTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/storage/TransientCacheTest.java @@ -19,7 +19,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import com.google.common.base.Ticker; import java.io.InputStream; diff --git a/geowebcache/core/src/test/java/org/geowebcache/util/FileUtilsTest.java b/geowebcache/core/src/test/java/org/geowebcache/util/FileUtilsTest.java index 4876b67b2..b687312bd 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/util/FileUtilsTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/util/FileUtilsTest.java @@ -14,9 +14,9 @@ */ package org.geowebcache.util; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.io.File; diff --git a/geowebcache/diskquota/bdb/src/test/java/org/geowebcache/diskquota/BDBQuotaStoreTest.java b/geowebcache/diskquota/bdb/src/test/java/org/geowebcache/diskquota/BDBQuotaStoreTest.java index cc0fee112..c9a252341 100644 --- a/geowebcache/diskquota/bdb/src/test/java/org/geowebcache/diskquota/BDBQuotaStoreTest.java +++ b/geowebcache/diskquota/bdb/src/test/java/org/geowebcache/diskquota/BDBQuotaStoreTest.java @@ -1,6 +1,7 @@ package org.geowebcache.diskquota; import static org.easymock.EasyMock.newCapture; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; @@ -8,7 +9,7 @@ import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import java.io.File; import java.math.BigInteger; @@ -56,7 +57,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; public class BDBQuotaStoreTest { @@ -75,7 +75,6 @@ public class BDBQuotaStoreTest { @Rule public TemporaryFolder targetDir = new TemporaryFolder(); - @Rule public ExpectedException exception = ExpectedException.none(); @Rule public MockWepAppContextRule context = new MockWepAppContextRule(); Map> parameterIdsMap; @@ -507,10 +506,8 @@ public void testGetLeastRecentlyUsedPage() throws Exception { @Test public void testGetTileSetById() throws Exception { assertThat(store.getTileSetById(testTileSet.getId()), equalTo(testTileSet)); - - exception.expect(IllegalArgumentException.class); - - store.getTileSetById("NonExistentTileSetId"); + assertThrows( + IllegalArgumentException.class, () -> store.getTileSetById("NonExistentTileSetId")); } @Test diff --git a/geowebcache/diskquota/core/src/test/java/org/geowebcache/diskquota/ConfigLoaderXSchemaTest.java b/geowebcache/diskquota/core/src/test/java/org/geowebcache/diskquota/ConfigLoaderXSchemaTest.java index 43cfba1a7..20e74241b 100644 --- a/geowebcache/diskquota/core/src/test/java/org/geowebcache/diskquota/ConfigLoaderXSchemaTest.java +++ b/geowebcache/diskquota/core/src/test/java/org/geowebcache/diskquota/ConfigLoaderXSchemaTest.java @@ -14,43 +14,31 @@ */ package org.geowebcache.diskquota; +import static org.junit.Assert.assertThrows; + import com.thoughtworks.xstream.XStream; import org.geowebcache.io.GeoWebCacheXStream; import org.junit.Ignore; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class ConfigLoaderXSchemaTest { - @Rule public ExpectedException exception = ExpectedException.none(); - @Test public void testNotAllowNonGWCClass() throws Exception { // Check that classes from other packages on the class path can't be serialized - - XStream xs = new GeoWebCacheXStream(); - - xs = ConfigLoader.getConfiguredXStream(xs); - - exception.expect(com.thoughtworks.xstream.security.ForbiddenClassException.class); - - @SuppressWarnings("unused") - Object o = xs.fromXML("<" + org.easymock.Capture.class.getCanonicalName() + " />"); + XStream xs = ConfigLoader.getConfiguredXStream(new GeoWebCacheXStream()); + assertThrows( + com.thoughtworks.xstream.security.ForbiddenClassException.class, + () -> xs.fromXML("<" + org.easymock.Capture.class.getCanonicalName() + " />")); } @Ignore // Need to tighten the XStream permissions to get this to pass @Test public void testNotAllowNonXMLGWCClass() throws Exception { // Check that a class in GWC that shouldn't be serialized to XML can't be - - XStream xs = new GeoWebCacheXStream(); - - xs = ConfigLoader.getConfiguredXStream(xs); - - exception.expect(com.thoughtworks.xstream.security.ForbiddenClassException.class); - - @SuppressWarnings("unused") - Object o = xs.fromXML("<" + ConfigLoaderXSchemaTest.class.getCanonicalName() + " />"); + XStream xs = ConfigLoader.getConfiguredXStream(new GeoWebCacheXStream()); + assertThrows( + com.thoughtworks.xstream.security.ForbiddenClassException.class, + () -> xs.fromXML("<" + ConfigLoaderXSchemaTest.class.getCanonicalName() + " />")); } } diff --git a/geowebcache/diskquota/jdbc/src/test/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStoreTest.java b/geowebcache/diskquota/jdbc/src/test/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStoreTest.java index 42f718c8d..68681994b 100644 --- a/geowebcache/diskquota/jdbc/src/test/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStoreTest.java +++ b/geowebcache/diskquota/jdbc/src/test/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStoreTest.java @@ -1,12 +1,12 @@ package org.geowebcache.diskquota.jdbc; import static org.easymock.EasyMock.newCapture; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; diff --git a/geowebcache/mbtiles/src/test/java/org/geowebcache/mbtiles/layer/MBTilesLayerTest.java b/geowebcache/mbtiles/src/test/java/org/geowebcache/mbtiles/layer/MBTilesLayerTest.java index f5d8d27aa..3c0790a24 100644 --- a/geowebcache/mbtiles/src/test/java/org/geowebcache/mbtiles/layer/MBTilesLayerTest.java +++ b/geowebcache/mbtiles/src/test/java/org/geowebcache/mbtiles/layer/MBTilesLayerTest.java @@ -14,9 +14,12 @@ */ package org.geowebcache.mbtiles.layer; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import com.google.common.io.ByteStreams; @@ -53,7 +56,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; public class MBTilesLayerTest { @@ -70,8 +72,6 @@ public class MBTilesLayerTest { public @Rule MockWepAppContextRule extensions = new MockWepAppContextRule(); - @Rule public ExpectedException exception = ExpectedException.none(); - protected TileLayerConfiguration config; @Before @@ -244,10 +244,12 @@ public void testOutsideRange() throws GeoWebCacheException, IOException { null, null, null); - exception.expect(OutsideCoverageException.class); - exception.expectMessage( - "Coverage [minx,miny,maxx,maxy] is [38, 39, 39, 39, 6], index [x,y,z] is [38, 42, 6]"); - testLayer.getTile(conveyorTile); + OutsideCoverageException exception = + assertThrows(OutsideCoverageException.class, () -> testLayer.getTile(conveyorTile)); + assertThat( + exception.getMessage(), + containsString( + "Coverage [minx,miny,maxx,maxy] is [38, 39, 39, 39, 6], index [x,y,z] is [38, 42, 6]")); } @Test diff --git a/geowebcache/pom.xml b/geowebcache/pom.xml index 5289dd93c..ecfce958b 100644 --- a/geowebcache/pom.xml +++ b/geowebcache/pom.xml @@ -271,7 +271,7 @@ junit junit - 4.12 + 4.13.2 test diff --git a/geowebcache/rest/src/test/java/org/geowebcache/rest/controller/ByteStreamControllerTest.java b/geowebcache/rest/src/test/java/org/geowebcache/rest/controller/ByteStreamControllerTest.java index 5dc52a4b8..dd4c133e1 100644 --- a/geowebcache/rest/src/test/java/org/geowebcache/rest/controller/ByteStreamControllerTest.java +++ b/geowebcache/rest/src/test/java/org/geowebcache/rest/controller/ByteStreamControllerTest.java @@ -22,9 +22,7 @@ import org.apache.commons.lang3.SystemUtils; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -41,8 +39,6 @@ public class ByteStreamControllerTest { ByteStreamController bsc; - @Rule public ExpectedException exception = ExpectedException.none(); - @Before public void setUp() throws Exception { bsc = new ByteStreamController(); diff --git a/geowebcache/s3storage/src/test/java/org/geowebcache/s3/OnlineS3BlobStoreIntegrationTest.java b/geowebcache/s3storage/src/test/java/org/geowebcache/s3/OnlineS3BlobStoreIntegrationTest.java index 4f2d61eb8..ded8a671a 100644 --- a/geowebcache/s3storage/src/test/java/org/geowebcache/s3/OnlineS3BlobStoreIntegrationTest.java +++ b/geowebcache/s3storage/src/test/java/org/geowebcache/s3/OnlineS3BlobStoreIntegrationTest.java @@ -12,8 +12,8 @@ */ package org.geowebcache.s3; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; import org.junit.Assume; import org.junit.Rule; diff --git a/geowebcache/s3storage/src/test/java/org/geowebcache/s3/S3BlobStoreConfigSerializeTest.java b/geowebcache/s3storage/src/test/java/org/geowebcache/s3/S3BlobStoreConfigSerializeTest.java index 77b3ba395..ac4309765 100644 --- a/geowebcache/s3storage/src/test/java/org/geowebcache/s3/S3BlobStoreConfigSerializeTest.java +++ b/geowebcache/s3storage/src/test/java/org/geowebcache/s3/S3BlobStoreConfigSerializeTest.java @@ -14,10 +14,11 @@ */ package org.geowebcache.s3; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import com.amazonaws.services.s3.model.CannedAccessControlList; import com.thoughtworks.xstream.XStream; @@ -25,7 +26,6 @@ import org.geowebcache.util.PropertyRule; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class S3BlobStoreConfigSerializeTest { @@ -93,15 +93,15 @@ public void testPublicAccessLowerCase() throws Exception { config, hasProperty("accessControlList", is(CannedAccessControlList.PublicRead))); } - @Rule public ExpectedException exception = ExpectedException.none(); - @Test public void testInvalidAccess() throws Exception { S3BlobStoreConfigProvider provider = new S3BlobStoreConfigProvider(); XStream xs = provider.getConfiguredXStream(new XStream()); - exception.expect(XStreamException.class); - xs.fromXML( - "testfalseNOT_A_REAL_ACCESS_TYPEtrue"); + assertThrows( + XStreamException.class, + () -> + xs.fromXML( + "testfalseNOT_A_REAL_ACCESS_TYPEtrue")); } @Rule public PropertyRule envParametrization = PropertyRule.system("ALLOW_ENV_PARAMETRIZATION"); diff --git a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/FileManagerTest.java b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/FileManagerTest.java index f617c457e..a87d8c3c3 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/FileManagerTest.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/FileManagerTest.java @@ -17,10 +17,10 @@ import static org.geowebcache.sqlite.Utils.Tuple; import static org.geowebcache.sqlite.Utils.Tuple.tuple; import static org.geowebcache.sqlite.Utils.tuplesToMap; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; import java.io.File; import java.util.Collections; diff --git a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/MbtilesBlobStoreTest.java b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/MbtilesBlobStoreTest.java index c802e1e4e..4c96eba65 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/MbtilesBlobStoreTest.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/MbtilesBlobStoreTest.java @@ -15,12 +15,12 @@ package org.geowebcache.sqlite; import static org.geowebcache.sqlite.Utils.Tuple.tuple; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; import java.io.File; import java.util.ArrayList; diff --git a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/MbtilesPBFTest.java b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/MbtilesPBFTest.java index f32335bcc..dee3cd857 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/MbtilesPBFTest.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/MbtilesPBFTest.java @@ -14,8 +14,8 @@ */ package org.geowebcache.sqlite; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.io.File; diff --git a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/OperationsRestTest.java b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/OperationsRestTest.java index 36ff6e9c8..5e9452bc9 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/OperationsRestTest.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/OperationsRestTest.java @@ -15,9 +15,9 @@ package org.geowebcache.sqlite; import static org.geowebcache.sqlite.Utils.Tuple.tuple; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.io.File; diff --git a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteBlobStoreTest.java b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteBlobStoreTest.java index 8c9cc418f..ffe8d517f 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteBlobStoreTest.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteBlobStoreTest.java @@ -14,9 +14,9 @@ */ package org.geowebcache.sqlite; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; import java.io.File; import java.nio.file.Files; diff --git a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java index d472f3d07..365159b50 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java @@ -16,10 +16,10 @@ import static org.geowebcache.sqlite.Utils.Tuple; import static org.geowebcache.sqlite.Utils.Tuple.tuple; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; import java.io.File; import java.sql.Connection; diff --git a/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftBlobStoreTest.java b/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftBlobStoreTest.java index 69bd95161..f57025c84 100644 --- a/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftBlobStoreTest.java +++ b/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftBlobStoreTest.java @@ -15,11 +15,11 @@ package org.geowebcache.swift; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.any; diff --git a/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftTileTest.java b/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftTileTest.java index 39467aca8..484c6c6e7 100644 --- a/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftTileTest.java +++ b/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftTileTest.java @@ -15,7 +15,7 @@ package org.geowebcache.swift; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyLong; diff --git a/geowebcache/web/src/test/java/org/geowebcache/jetty/RestIntegrationTest.java b/geowebcache/web/src/test/java/org/geowebcache/jetty/RestIntegrationTest.java index 8c458010d..1cd0ef6b5 100644 --- a/geowebcache/web/src/test/java/org/geowebcache/jetty/RestIntegrationTest.java +++ b/geowebcache/web/src/test/java/org/geowebcache/jetty/RestIntegrationTest.java @@ -16,6 +16,7 @@ */ package org.geowebcache.jetty; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.describedAs; import static org.hamcrest.Matchers.either; @@ -23,7 +24,6 @@ import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import java.io.File; import java.io.IOException; diff --git a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesConfigurationTest.java b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesConfigurationTest.java index deb6615c1..dd0e012a0 100644 --- a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesConfigurationTest.java +++ b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesConfigurationTest.java @@ -21,12 +21,12 @@ import static org.easymock.EasyMock.newCapture; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.beans.HasPropertyWithValue.hasProperty; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase; -import static org.junit.Assert.assertThat; import com.google.common.collect.Sets; import java.util.Collections; diff --git a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesGridSetConfigurationConformanceTest.java b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesGridSetConfigurationConformanceTest.java index 31d463070..2c2f5b55d 100644 --- a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesGridSetConfigurationConformanceTest.java +++ b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesGridSetConfigurationConformanceTest.java @@ -18,8 +18,8 @@ import static org.easymock.EasyMock.expect; import static org.geowebcache.util.TestUtils.assertPresent; import static org.geowebcache.util.TestUtils.requirePresent; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; import com.google.common.base.Objects; import java.util.Collections; diff --git a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesLayerConfigurationConformanceTest.java b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesLayerConfigurationConformanceTest.java index b35af388b..2b6ab66c9 100644 --- a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesLayerConfigurationConformanceTest.java +++ b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesLayerConfigurationConformanceTest.java @@ -16,8 +16,8 @@ import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.expect; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; import java.util.Collections; import java.util.LinkedList; diff --git a/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSGetCapabilitiesTest.java b/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSGetCapabilitiesTest.java index 2e1adfc23..f7df04eec 100644 --- a/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSGetCapabilitiesTest.java +++ b/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSGetCapabilitiesTest.java @@ -3,9 +3,9 @@ import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; import java.io.StringReader; import java.nio.charset.StandardCharsets; diff --git a/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSServiceTest.java b/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSServiceTest.java index 4a672d0c8..3b2d3239d 100644 --- a/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSServiceTest.java +++ b/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSServiceTest.java @@ -1,5 +1,6 @@ package org.geowebcache.service.wms; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; @@ -9,7 +10,6 @@ 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.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.eq; diff --git a/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSTileFuserTest.java b/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSTileFuserTest.java index 9fdab6a17..7ec56c63a 100644 --- a/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSTileFuserTest.java +++ b/geowebcache/wms/src/test/java/org/geowebcache/service/wms/WMSTileFuserTest.java @@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; @@ -57,9 +58,7 @@ import org.geowebcache.storage.TileObject; import org.geowebcache.storage.TransientCache; import org.geowebcache.storage.blobstore.file.FileBlobStore; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -68,8 +67,6 @@ public class WMSTileFuserTest { - @Rule public ExpectedException exception = ExpectedException.none(); - GridSetBroker gridSetBroker = new GridSetBroker(Collections.singletonList(new DefaultGridsets(false, false))); SecurityDispatcher secDisp = mock(SecurityDispatcher.class); @@ -204,8 +201,7 @@ public void testTileFuserSecurity() throws Exception { MockHttpServletResponse response = new MockHttpServletResponse(); RuntimeStats stats = mock(RuntimeStats.class); - exception.expect(SecurityException.class); - tileFuser.writeResponse(response, stats); + assertThrows(SecurityException.class, () -> tileFuser.writeResponse(response, stats)); } @Test