diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/ee/StandardExecutionEnvironmentTest.java b/tycho-core/src/test/java/org/eclipse/tycho/core/ee/StandardExecutionEnvironmentTest.java index b2bba65883..820280ffc6 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/core/ee/StandardExecutionEnvironmentTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/core/ee/StandardExecutionEnvironmentTest.java @@ -15,6 +15,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -196,9 +197,10 @@ public void testCompilerTargetCompatibility() throws Exception { } } - @Test(expected = UnknownEnvironmentException.class) + @Test public void testUnknownEnv() throws Throwable { - ExecutionEnvironmentUtils.getExecutionEnvironment("foo", null, null, new SilentLog()); + assertThrows(UnknownEnvironmentException.class, + () -> ExecutionEnvironmentUtils.getExecutionEnvironment("foo", null, null, new SilentLog())); } @Test diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/locking/FileLockServiceTest.java b/tycho-core/src/test/java/org/eclipse/tycho/core/locking/FileLockServiceTest.java index 7a3ca09bbd..cdc74cd489 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/core/locking/FileLockServiceTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/core/locking/FileLockServiceTest.java @@ -15,8 +15,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; @@ -54,9 +54,9 @@ public void testIsLocked() throws IOException { assertFalse(isLocked(file)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNegativeTimeout() throws IOException { - subject.lock(newTestFile(), -1L); + assertThrows(IllegalArgumentException.class, () -> subject.lock(newTestFile(), -1L)); } @Test @@ -87,12 +87,11 @@ private void lockAndRelease(File file) throws IOException { @Test public void testLockReentranceDifferentLocker() throws IOException { final File testFile = newTestFile(); - try (var locked = subject.lock(testFile)) { - subject.lock(testFile, 0L); - fail("lock already held by same VM but could be acquired a second time"); - } catch (LockTimeoutException e) { - // expected - } + assertThrows("lock already held by same VM but could be acquired a second time", LockTimeoutException.class, + () -> { + subject.lock(testFile); + subject.lock(testFile, 0L); + }); } @Test @@ -100,11 +99,8 @@ public void testLockedByOtherProcess() throws Exception { File testFile = newTestFile(); LockProcess lockProcess = new LockProcess(testFile, 200L); lockProcess.lockFileInForkedProcess(); - try (var locked = subject.lock(testFile, 0L)) { - fail("lock already held by other VM but could be acquired a second time"); - } catch (LockTimeoutException e) { - // expected - } + assertThrows("lock already held by other VM but could be acquired a second time", LockTimeoutException.class, + () -> subject.lock(testFile, 0L)); lockProcess.cleanup(); } diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/osgitools/OsgiManifestTest.java b/tycho-core/src/test/java/org/eclipse/tycho/core/osgitools/OsgiManifestTest.java index fec814cdb0..65ed44cbb1 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/core/osgitools/OsgiManifestTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/core/osgitools/OsgiManifestTest.java @@ -22,9 +22,9 @@ public void testValidOSGiManifest() throws OsgiManifestParserException, URISynta assertEquals(13, manifest.getHeaders().size()); } - @Test(expected = OsgiManifestParserException.class) + @Test public void testInvalidManifest() throws OsgiManifestParserException, URISyntaxException { - parseManifest("invalid.mf"); + assertThrows(OsgiManifestParserException.class, () -> parseManifest("invalid.mf")); } @Test diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/CompositeArtifactProviderTestBase.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/CompositeArtifactProviderTestBase.java index a8c25ccd7b..da59e7b7d5 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/CompositeArtifactProviderTestBase.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/CompositeArtifactProviderTestBase.java @@ -37,6 +37,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.net.URI; @@ -191,9 +192,9 @@ public void testGetArtifactWithNonRestartableSink() throws Exception { assertThat(status.getMessage(), containsString("An error occurred while transferring artifact")); // original message from p2 as top-level status } - @Test(expected = IllegalArgumentException.class) + @Test public void testGetArtifactToClosedSink() throws Exception { - subject.getArtifact(new NonStartableArtifactSink(), null); + assertThrows(IllegalArgumentException.class, () -> subject.getArtifact(new NonStartableArtifactSink(), null)); } @Test @@ -233,9 +234,10 @@ public void testGetRawArtifactWithNonRestartableSink() throws Exception { assertTrue(status.isOK()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testGetRawArtifactToClosedSink() throws Exception { - subject.getRawArtifact(new NonStartableArtifactSink(), null); + assertThrows(IllegalArgumentException.class, + () -> subject.getRawArtifact(new NonStartableArtifactSink(), null)); } @Test diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FeatureRootfileArtifactRepositoryTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FeatureRootfileArtifactRepositoryTest.java index 4389ce1917..5a2a1dc283 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FeatureRootfileArtifactRepositoryTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FeatureRootfileArtifactRepositoryTest.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.tycho.p2resolver; +import static org.junit.Assert.assertThrows; + import java.util.Map; import java.util.Properties; import java.util.Set; @@ -78,14 +80,14 @@ public void testRepoWithAttachedArtifactsAndConfigurations() throws Exception { assertMavenProperties(descriptor, "root.win32.win32.x86"); } - @Test(expected = ProvisionException.class) + @Test public void testRepoWithoutMavenAdvice() throws Exception { FeatureRootfileArtifactRepository subject = new FeatureRootfileArtifactRepository(createPublisherInfo(false), tempFolder.newFolder("testrootfiles")); IArtifactDescriptor artifactDescriptor = createArtifactDescriptor(PublisherHelper.BINARY_ARTIFACT_CLASSIFIER, "org.eclipse.tycho.test.p2"); - subject.getOutputStream(artifactDescriptor).close(); + assertThrows(ProvisionException.class, () -> subject.getOutputStream(artifactDescriptor).close()); } @Test diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FileRepositoryArtifactProviderTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FileRepositoryArtifactProviderTest.java index 978ecea3f4..d41e122f56 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FileRepositoryArtifactProviderTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/FileRepositoryArtifactProviderTest.java @@ -16,6 +16,7 @@ import static org.eclipse.tycho.test.util.TestRepositoryContent.BUNDLE_A_KEY; import static org.eclipse.tycho.test.util.TestRepositoryContent.REPO_BUNDLE_AB; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; import java.io.File; @@ -56,12 +57,12 @@ public void testGetArtifactFile() { assertEquals(artifactInLocalRepo(BUNDLE_A_KEY, TestRepositoryContent.REPO2_BUNDLE_A, ".jar"), result); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructionWithNonArtifactFileRepository() throws Exception { IArtifactRepository repository = mock(IArtifactRepository.class); // i.e. not an IFileArtifactRepository subject = new FileRepositoryArtifactProvider(loaderFor(repository), TRANSFER_POLICY); - subject.getArtifactFile(BUNDLE_A_KEY); + assertThrows(IllegalArgumentException.class, () -> subject.getArtifactFile(BUNDLE_A_KEY)); } private static File artifactInLocalRepo(IArtifactKey key, URI localRepository, String extension) { diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/LocalArtifactRepositoryFactoryTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/LocalArtifactRepositoryFactoryTest.java index 76e43a133f..04098da5a6 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/LocalArtifactRepositoryFactoryTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/LocalArtifactRepositoryFactoryTest.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.tycho.p2resolver; +import static org.junit.Assert.assertThrows; + import java.net.URI; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; @@ -46,9 +48,9 @@ protected LocalRepositoryP2Indices lookupLocalRepoIndices() { }; } - @Test(expected = ProvisionException.class) + @Test public void testCreate() throws ProvisionException { - subject.create(null, null, null, null); + assertThrows(ProvisionException.class, () -> subject.create(null, null, null, null)); } @Test diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublisherServiceTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublisherServiceTest.java index 1a127c02f7..e6ca60ed9d 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublisherServiceTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublisherServiceTest.java @@ -14,6 +14,7 @@ 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 java.io.File; @@ -116,9 +117,10 @@ public void testProfilePublishing() throws Exception { assertTrue(unitsById(seeds).keySet().contains("config.a.jre.virgo")); } - @Test(expected = FacadeException.class) + @Test public void testValidateProfileFile() throws Exception { - ((PublisherServiceImpl) subject).validateProfile(resourceFile("publishers/inconsistentname-1.0.profile")); + assertThrows(FacadeException.class, () -> ((PublisherServiceImpl) subject) + .validateProfile(resourceFile("publishers/inconsistentname-1.0.profile"))); } /** diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/RemoteAgentCompositeLoadingTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/RemoteAgentCompositeLoadingTest.java index c4916cca63..640510d7f8 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/RemoteAgentCompositeLoadingTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/RemoteAgentCompositeLoadingTest.java @@ -13,7 +13,7 @@ package org.eclipse.tycho.p2resolver; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.io.IOException; @@ -50,15 +50,11 @@ public void testLoadingCompositeRepositoryWithMissingChildFailsByDefault() throw * In Tycho, we want composite repositories to fail if they have missing children (and don't * explicitly specify the "p2.atomic.composite.loading" property). */ - try { - subject.getService(IArtifactRepositoryManager.class).loadRepository( - ResourceUtil.resourceFile("repositories/composite/missingChildAndAtomicUnset").toURI(), - new NullProgressMonitor()); - fail("Exception was not thrown!"); - } catch (ProvisionException e) { - assertEquals(ProvisionException.REPOSITORY_FAILED_READ, e.getStatus().getCode()); - } - + ProvisionException e = assertThrows(ProvisionException.class, + () -> subject.getService(IArtifactRepositoryManager.class).loadRepository( + ResourceUtil.resourceFile("repositories/composite/missingChildAndAtomicUnset").toURI(), + new NullProgressMonitor())); + assertEquals(ProvisionException.REPOSITORY_FAILED_READ, e.getStatus().getCode()); } } diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/RemoteAgentMetadataRepositoryOfflineCache.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/RemoteAgentMetadataRepositoryOfflineCache.java index c9f8bcee4c..fbbbb9d397 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/RemoteAgentMetadataRepositoryOfflineCache.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/RemoteAgentMetadataRepositoryOfflineCache.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.tycho.p2resolver; +import static org.junit.Assert.assertThrows; + import java.io.File; import java.net.URI; @@ -56,10 +58,10 @@ protected void modifySession(MavenSession mavenSession) { mavenSession.getRequest().setOffline(true); } - @Test(expected = ProvisionException.class) + @Test public void testOfflineLoadingWithoutCacheFails() throws Exception { IProvisioningAgent offlineAgent = newOfflineAgent(); - loadHttpRepository(offlineAgent); + assertThrows(ProvisionException.class, () -> loadHttpRepository(offlineAgent)); } private IProvisioningAgent newOfflineAgent() throws Exception { diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/limitations/NonUniqueBasedirsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/limitations/NonUniqueBasedirsTest.java index ff2250ce85..c892dbd24f 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/limitations/NonUniqueBasedirsTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/limitations/NonUniqueBasedirsTest.java @@ -12,26 +12,22 @@ *******************************************************************************/ package org.eclipse.tycho.test.limitations; +import static org.junit.Assert.assertThrows; + import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; import org.eclipse.tycho.test.AbstractTychoIntegrationTest; -import org.junit.Assert; import org.junit.Test; public class NonUniqueBasedirsTest extends AbstractTychoIntegrationTest { - @Test - public void testNonUniqueBasedirFailure() throws Exception { - Verifier verifier = getVerifier("limitations.uniqueBaseDirs", false); - try { - verifier.executeGoal("clean"); - Assert.fail("build failure expected"); - } catch (VerificationException e) { - // expected - } + @Test + public void testNonUniqueBasedirFailure() throws Exception { + Verifier verifier = getVerifier("limitations.uniqueBaseDirs", false); + assertThrows(VerificationException.class, () -> verifier.executeGoal("clean")); - // expect a clear error message -> requested in bug 366967 - verifier.verifyTextInLog("Multiple modules within the same basedir are not supported"); - } + // expect a clear error message -> requested in bug 366967 + verifier.verifyTextInLog("Multiple modules within the same basedir are not supported"); + } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryDownloadTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryDownloadTest.java index ab891cc4dd..a729482949 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryDownloadTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryDownloadTest.java @@ -9,6 +9,7 @@ *******************************************************************************/ package org.eclipse.tycho.test.p2Repository; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -61,12 +62,9 @@ public void testDownloadOnlyOnce() throws Exception { verifier.executeGoals(List.of("clean", "install")); verifier.verifyErrorFreeLog(); for (String bundle : bundles) { - try { - verifier.verifyTextInLog("Writing P2 metadata for osgi.bundle," + bundle); - fail(bundle + " is fetched twice!"); - } catch (VerificationException e) { - assertTrue(e.getMessage().contains("Text not found")); - } + VerificationException e = assertThrows(bundle + " is fetched twice!", VerificationException.class, + () -> verifier.verifyTextInLog("Writing P2 metadata for osgi.bundle," + bundle)); + assertTrue(e.getMessage().contains("Text not found")); } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryValidateTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryValidateTest.java index aaabd66da7..6edb544640 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryValidateTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/P2RepositoryValidateTest.java @@ -13,7 +13,7 @@ package org.eclipse.tycho.test.p2Repository; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.io.File; import java.util.Arrays; @@ -30,15 +30,10 @@ public class P2RepositoryValidateTest extends AbstractTychoIntegrationTest { public void testValidate() throws Exception { Verifier verifier = getVerifier("p2Repository.unresolvableIU", false); verifier.addCliOption("-Dtest-data-repo=" + P2Repositories.ECLIPSE_352.toString()); - try { - // validate is not always enough here as only in the prepare-package there is - // the first mojo that requires classpath resolving and we want to delay it - // until there... - verifier.executeGoal("prepare-package"); - fail("Expected build failure"); - } catch (VerificationException ex) { - // expected - } + // validate is not always enough here as only in the prepare-package there is + // the first mojo that requires classpath resolving and we want to delay it + // until there... + assertThrows(VerificationException.class, () -> verifier.executeGoal("prepare-package")); verifier.verifyTextInLog("non.existing.iu"); } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/packaging/BaselineValidateAndReplaceTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/packaging/BaselineValidateAndReplaceTest.java index e3493fff1f..61fef20f19 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/packaging/BaselineValidateAndReplaceTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/packaging/BaselineValidateAndReplaceTest.java @@ -1,5 +1,6 @@ package org.eclipse.tycho.test.packaging; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.io.File; @@ -97,11 +98,7 @@ public void testCorruptedBaselineRepo() throws Exception { File corruptedBaselineRepo = new File("projects/packaging.reproducibleArtifacts/baseline/repository_corrupted") .getCanonicalFile(); Verifier verifier = getVerifier("baseline/src", corruptedBaselineRepo); - try { - verifier.executeGoals(List.of("clean", "package")); - Assert.fail("should not reach here"); - } catch (VerificationException expected) { - } + assertThrows(VerificationException.class, () -> verifier.executeGoals(List.of("clean", "package"))); File locallyBuiltJar = new File(verifier.getBasedir(), "bundle01/target/baseline.bundle01-1.0.0-SNAPSHOT.jar"); assertTrue(locallyBuiltJar.isFile()); // locally built jar must not be replaced with corrupted 0-byte baseline jar diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/product/InvalidProductTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/product/InvalidProductTest.java index 2f6912ea73..05e1f9db7c 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/product/InvalidProductTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/product/InvalidProductTest.java @@ -9,7 +9,7 @@ *******************************************************************************/ package org.eclipse.tycho.test.product; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; @@ -25,11 +25,8 @@ public void testInvalidProductFile() throws Exception { verifier.addCliOption("-Dtest-data-repo=" + P2Repositories.ECLIPSE_342.toString()); // run build and verify we get a proper error message instead of an NPE - try { - verifier.executeGoal("package"); - fail("We expect to fail on malformed product definitions"); - } catch (VerificationException e) { - verifier.verifyTextInLog("The product file invalid.product does not contain the mandatory attribute"); - } + assertThrows("We expect to fail on malformed product definitions", VerificationException.class, + () -> verifier.executeGoal("package")); + verifier.verifyTextInLog("The product file invalid.product does not contain the mandatory attribute"); } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/reactor/makeBehaviour/MavenReactorMakeOptionsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/reactor/makeBehaviour/MavenReactorMakeOptionsTest.java index 46677defe8..8d3b695722 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/reactor/makeBehaviour/MavenReactorMakeOptionsTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/reactor/makeBehaviour/MavenReactorMakeOptionsTest.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.tycho.test.reactor.makeBehaviour; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.util.List; @@ -136,14 +136,11 @@ public void testBoth() throws Exception { @Test public void testSingleProjectNoOptionFails() throws Exception { - try { - verifier.addCliOption("-pl feature1"); - verifier.executeGoals(List.of("clean", "verify")); - fail("Build should fail due to missing reactor dependency"); - } catch (VerificationException e) { - verifier.verifyTextInLog( - "Missing requirement: feature1.feature.group 1.0.0.qualifier requires 'org.eclipse.equinox.p2.iu; bundle1 0.0.0' but it could not be found"); - } + verifier.addCliOption("-pl feature1"); + assertThrows("Build should fail due to missing reactor dependency", VerificationException.class, + () -> verifier.executeGoals(List.of("clean", "verify"))); + verifier.verifyTextInLog( + "Missing requirement: feature1.feature.group 1.0.0.qualifier requires 'org.eclipse.equinox.p2.iu; bundle1 0.0.0' but it could not be found"); } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/sourceBundle/AutoNoSourceBundleTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/sourceBundle/AutoNoSourceBundleTest.java index 559c1ce09e..7944f463da 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/sourceBundle/AutoNoSourceBundleTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/sourceBundle/AutoNoSourceBundleTest.java @@ -12,25 +12,25 @@ *******************************************************************************/ package org.eclipse.tycho.test.sourceBundle; +import static org.junit.Assert.assertThrows; + import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; import org.eclipse.tycho.test.AbstractTychoIntegrationTest; -import org.junit.Assert; import org.junit.Test; public class AutoNoSourceBundleTest extends AbstractTychoIntegrationTest { - @Test - public void test() throws Exception { - // the point of the test is to make sure Tycho does NOT allow references to missing source bundles (see bug 367637) + @Test + public void test() throws Exception { + // the point of the test is to make sure Tycho does NOT allow references to + // missing source bundles (see bug 367637) - Verifier verifier = getVerifier("/sourceBundle.autoSkip", false); - try { - verifier.executeGoal("verify"); - Assert.fail("Reference to a missing source bundle did not fail the build"); - } catch (VerificationException expected) { - verifier.verifyTextInLog("feature.feature.group 1.0.0.qualifier requires 'org.eclipse.equinox.p2.iu; bundle.source 0.0.0' but it could not be found"); - } - } + Verifier verifier = getVerifier("/sourceBundle.autoSkip", false); + assertThrows("Reference to a missing source bundle did not fail the build", VerificationException.class, + () -> verifier.executeGoal("verify")); + verifier.verifyTextInLog( + "feature.feature.group 1.0.0.qualifier requires 'org.eclipse.equinox.p2.iu; bundle.source 0.0.0' but it could not be found"); + } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/TestsInBundleTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/TestsInBundleTest.java index febfa5ba90..b29ef141aa 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/TestsInBundleTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/TestsInBundleTest.java @@ -12,8 +12,8 @@ *******************************************************************************/ package org.eclipse.tycho.test.surefire; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.File; import java.util.Arrays; @@ -70,13 +70,9 @@ public void testIntegrationTest() throws Exception { @Test public void testVerify() throws Exception { Verifier verifier = getVerifier("surefire.combinedtests/bundle.test"); - try { - verifier.executeGoals(Arrays.asList("clean", "verify")); - fail("the build succeed but test-failures are expected!"); - } catch (VerificationException e) { - // thats good indeed... - verifier.verifyTextInLog("There are test failures"); - } + assertThrows(VerificationException.class, () -> verifier.executeGoals(Arrays.asList("clean", "verify"))); + // thats good indeed... + verifier.verifyTextInLog("There are test failures"); } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java index fb6a63e5bf..2aed914678 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetPlatformLocationsTest.java @@ -119,13 +119,10 @@ public void testTargetPlatformArtifactCaching() throws Exception { Files.write(annotBundleManifestFile.toPath(), out, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); - try { - verifier.executeGoal("verify"); - Assert.fail("Reference to the not exported package did not fail the build"); - } catch (VerificationException expected) { - verifier.verifyTextInLog( - " Missing requirement: test.bundle 0.0.1.qualifier requires 'java.package; tycho.test.package 0.0.0' but it could not be found"); - } + assertThrows("Reference to the not exported package did not fail the build", VerificationException.class, + () -> verifier.executeGoal("verify")); + verifier.verifyTextInLog( + " Missing requirement: test.bundle 0.0.1.qualifier requires 'java.package; tycho.test.package 0.0.0' but it could not be found"); } @Test diff --git a/tycho-surefire/tycho-surefire-plugin/src/test/java/org/eclipse/tycho/surefire/TestMojoTest.java b/tycho-surefire/tycho-surefire-plugin/src/test/java/org/eclipse/tycho/surefire/TestMojoTest.java index 7370b3c24f..9a9361c2c7 100644 --- a/tycho-surefire/tycho-surefire-plugin/src/test/java/org/eclipse/tycho/surefire/TestMojoTest.java +++ b/tycho-surefire/tycho-surefire-plugin/src/test/java/org/eclipse/tycho/surefire/TestMojoTest.java @@ -16,8 +16,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.File; import java.lang.reflect.Field; @@ -58,12 +58,7 @@ public void testSplitArgLineMultipleArgs() throws Exception { @Test public void testSplitArgLineUnbalancedQuotes() throws Exception { AbstractEclipseTestMojo testMojo = new TestPluginMojo(); - try { - testMojo.splitArgLine("\"'missing closing double-quote'"); - fail("unreachable code"); - } catch (MojoExecutionException e) { - assertTrue(e.getMessage().contains("unbalanced quotes")); - } + assertThrows(MojoExecutionException.class, () -> testMojo.splitArgLine("\"'missing closing double-quote'")); } @Test @@ -138,12 +133,8 @@ public void testIncludes() throws Exception { public void testParallelModeMissingThreadCountParameter() throws Exception { AbstractEclipseTestMojo testMojo = new TestPluginMojo(); setParameter(testMojo, "parallel", ParallelMode.both); - try { - testMojo.getMergedProviderProperties(); - fail("MojoExecutionException expected since threadCount parameter is missing"); - } catch (MojoExecutionException e) { - // Success - } + assertThrows("MojoExecutionException expected since threadCount parameter is missing", + MojoExecutionException.class, () -> testMojo.getMergedProviderProperties()); } @Test @@ -151,12 +142,8 @@ public void testParallelModeThreadCountSetTo1() throws Exception { AbstractEclipseTestMojo testMojo = new TestPluginMojo(); setParameter(testMojo, "parallel", ParallelMode.both); setParameter(testMojo, "threadCount", 1); - try { - testMojo.getMergedProviderProperties(); - fail("MojoExecutionException expected since threadCount parameter is missing"); - } catch (MojoExecutionException e) { - // Success - } + assertThrows("MojoExecutionException expected since threadCount parameter is missing", + MojoExecutionException.class, () -> testMojo.getMergedProviderProperties()); } @Test