From f195d2d6790c85165cf8b765b25a119a7339939d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Wed, 13 Dec 2023 18:23:10 +0200 Subject: [PATCH] Use assertThrows in tests --- .../osgicompiler/test/OsgiCompilerTest.java | 33 +++--- ...PlatformFilterConfigurationReaderTest.java | 46 +++----- .../core/osgitools/OsgiManifestTest.java | 43 +++---- ...TargetPlatformConfigurationReaderTest.java | 72 ++++-------- .../core/test/DefaultBundleReaderTest.java | 47 +++----- .../eclipse/tycho/core/test/TychoTest.java | 110 ++++++------------ .../plugins/p2/extras/MirrorMojoTest.java | 14 +-- .../tycho/test/DocumentBundlePluginTest.java | 16 +-- .../ValidateVersionTest.java | 33 ++---- .../test/compiler/FailOnWarningTest.java | 24 ++-- .../compiler/MavenCompilerPluginTest.java | 67 +++++------ .../test/compiler/MisconfigurationTest.java | 20 ++-- .../RequireJREPackagesImportTest.java | 12 +- .../test/compiler/TestErrorMessages.java | 22 ++-- .../tycho/test/issue1093/Issue1093Test.java | 12 +- .../limitations/MixedTychoVersionsTest.java | 22 ++-- .../test/surefire/FailIfNoTestsTest.java | 10 +- .../tycho/test/surefire/TrimStackTrace.java | 23 ++-- ...argetDependenciesAccrossLocationsTest.java | 12 +- .../IncludeValidationHelperTest.java | 36 +++--- 20 files changed, 250 insertions(+), 424 deletions(-) diff --git a/tycho-compiler-plugin/src/test/java/org/eclipse/tycho/osgicompiler/test/OsgiCompilerTest.java b/tycho-compiler-plugin/src/test/java/org/eclipse/tycho/osgicompiler/test/OsgiCompilerTest.java index 2fcf7d21f0..e97cb8db02 100644 --- a/tycho-compiler-plugin/src/test/java/org/eclipse/tycho/osgicompiler/test/OsgiCompilerTest.java +++ b/tycho-compiler-plugin/src/test/java/org/eclipse/tycho/osgicompiler/test/OsgiCompilerTest.java @@ -16,6 +16,7 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertThrows; import java.io.File; import java.io.IOException; @@ -527,18 +528,15 @@ public void testBreeCompilerTargetCompatibilityIsChecked() throws Exception { List projects = getSortedProjects(basedir); MavenProject project = projects.get(0); - try { - getMojo(projects, project).execute(); - fail(); - } catch (MojoExecutionException e) { - // assert that the compiler mojo checks the target levels of all BREEs (and not just the first or "minimal" one) - assertThat(e.getMessage(), containsString( - "The effective compiler target level 1.5 is incompatible with the following OSGi execution environments")); - assertThat(e.getMessage(), containsString("J2SE-1.2")); - assertThat(e.getMessage(), containsString("CDC-1.0/Foundation-1.0")); - assertThat(e.getMessage(), containsString("OSGi/Minimum-1.2")); - assertThat(e.getMessage(), not(containsString("JavaSE-1.6"))); - } + MojoExecutionException e = assertThrows(MojoExecutionException.class, + () -> getMojo(projects, project).execute()); + // assert that the compiler mojo checks the target levels of all BREEs (and not just the first or "minimal" one) + assertThat(e.getMessage(), containsString( + "The effective compiler target level 1.5 is incompatible with the following OSGi execution environments")); + assertThat(e.getMessage(), containsString("J2SE-1.2")); + assertThat(e.getMessage(), containsString("CDC-1.0/Foundation-1.0")); + assertThat(e.getMessage(), containsString("OSGi/Minimum-1.2")); + assertThat(e.getMessage(), not(containsString("JavaSE-1.6"))); } public void test386210_compilerConfigurationCrosstalk() throws Exception { @@ -587,13 +585,10 @@ public void testCompilerLogWithCustomComilerArgsAndLog() throws Exception { File basedir = getBasedir("projects/logs/customCompilerArgsAndLog"); List projects = getSortedProjects(basedir); MavenProject project = projects.get(0); - try { - lookupConfiguredMojo(project, "compile").execute(); - fail(); - } catch (MojoFailureException e) { - assertThat(e.getMessage(), containsString("Compiler logging is configured by the 'log' compiler" - + " plugin parameter and the custom compiler argument '-log'. Only either of them is allowed.")); - } + MojoFailureException e = assertThrows(MojoFailureException.class, + () -> lookupConfiguredMojo(project, "compile").execute()); + assertThat(e.getMessage(), containsString("Compiler logging is configured by the 'log' compiler" + + " plugin parameter and the custom compiler argument '-log'. Only either of them is allowed.")); } public void testJreCompilationProfile() throws Exception { diff --git a/tycho-core/src/test/java/org/eclipse/tycho/artifacts/configuration/TargetPlatformFilterConfigurationReaderTest.java b/tycho-core/src/test/java/org/eclipse/tycho/artifacts/configuration/TargetPlatformFilterConfigurationReaderTest.java index 16a03a6cde..e5771f874f 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/artifacts/configuration/TargetPlatformFilterConfigurationReaderTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/artifacts/configuration/TargetPlatformFilterConfigurationReaderTest.java @@ -17,6 +17,7 @@ import static org.eclipse.tycho.targetplatform.TargetPlatformFilter.CapabilityPattern.patternWithoutVersion; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertThrows; import java.io.File; import java.io.IOException; @@ -35,9 +36,9 @@ import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.tycho.core.test.utils.ResourceUtil; import org.eclipse.tycho.targetplatform.TargetPlatformFilter; -import org.eclipse.tycho.targetplatform.TargetPlatformFilterSyntaxException; import org.eclipse.tycho.targetplatform.TargetPlatformFilter.CapabilityType; import org.eclipse.tycho.targetplatform.TargetPlatformFilter.FilterAction; +import org.eclipse.tycho.targetplatform.TargetPlatformFilterSyntaxException; import org.eclipse.tycho.version.TychoVersion; public class TargetPlatformFilterConfigurationReaderTest extends AbstractMojoTestCase { @@ -51,30 +52,18 @@ protected void setUp() throws Exception { } public void testMissingTypeException() throws Exception { - try { - Xpp3Dom filterConfig = getTargetFilters("targetfilter/missing_scope_type/pom.xml"); - subject.parseFilterConfiguration(filterConfig); - fail(); - } catch (TargetPlatformFilterSyntaxException e) { - } + Xpp3Dom filterConfig = getTargetFilters("targetfilter/missing_scope_type/pom.xml"); + assertThrows(TargetPlatformFilterSyntaxException.class, () -> subject.parseFilterConfiguration(filterConfig)); } public void testMissingIdException() throws Exception { - try { - Xpp3Dom filterConfig = getTargetFilters("targetfilter/missing_scope_id/pom.xml"); - subject.parseFilterConfiguration(filterConfig); - fail(); - } catch (TargetPlatformFilterSyntaxException e) { - } + Xpp3Dom filterConfig = getTargetFilters("targetfilter/missing_scope_id/pom.xml"); + assertThrows(TargetPlatformFilterSyntaxException.class, () -> subject.parseFilterConfiguration(filterConfig)); } public void testMissingActionException() throws Exception { - try { - Xpp3Dom filterConfig = getTargetFilters("targetfilter/missing_action/pom.xml"); - subject.parseFilterConfiguration(filterConfig); - fail(); - } catch (TargetPlatformFilterSyntaxException e) { - } + Xpp3Dom filterConfig = getTargetFilters("targetfilter/missing_action/pom.xml"); + assertThrows(TargetPlatformFilterSyntaxException.class, () -> subject.parseFilterConfiguration(filterConfig)); } public void testValidRemoveAllFilters() throws Exception { @@ -94,12 +83,8 @@ public void testValidRemoveAllFilters() throws Exception { } public void testDuplicateVersionException() throws Exception { - try { - Xpp3Dom filterConfig = getTargetFilters("targetfilter/duplicate_scope_version/pom.xml"); - subject.parseFilterConfiguration(filterConfig); - fail(); - } catch (TargetPlatformFilterSyntaxException e) { - } + Xpp3Dom filterConfig = getTargetFilters("targetfilter/duplicate_scope_version/pom.xml"); + assertThrows(TargetPlatformFilterSyntaxException.class, () -> subject.parseFilterConfiguration(filterConfig)); } public void testValidRestrictToFilters() throws Exception { @@ -134,12 +119,8 @@ public void testValidRestrictToFilters() throws Exception { } public void testDuplicateActionException() throws Exception { - try { - Xpp3Dom filterConfig = getTargetFilters("targetfilter/duplicate_action/pom.xml"); - subject.parseFilterConfiguration(filterConfig); - fail(); - } catch (TargetPlatformFilterSyntaxException e) { - } + Xpp3Dom filterConfig = getTargetFilters("targetfilter/duplicate_action/pom.xml"); + assertThrows(TargetPlatformFilterSyntaxException.class, () -> subject.parseFilterConfiguration(filterConfig)); } private Xpp3Dom getTargetFilters(String pomFile) throws IOException, Exception, ProjectBuildingException { @@ -184,8 +165,7 @@ Xpp3Dom getPluginConfiguration(MavenProject project, String artifactId) { List plugins = project.getBuild().getPlugins(); for (Plugin plugin : plugins) { if (artifactId.equals(plugin.getArtifactId())) { - Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration(); - return config; + return (Xpp3Dom) plugin.getConfiguration(); } } return null; 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 18f52c903e..fec814cdb0 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 @@ -4,7 +4,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.io.InputStream; import java.net.URISyntaxException; @@ -29,12 +29,10 @@ public void testInvalidManifest() throws OsgiManifestParserException, URISyntaxE @Test public void testMissingSymbolicName() throws Exception { - try { - parseManifest("noBsn.mf"); - fail(); - } catch (OsgiManifestParserException e) { - assertThat(e.getMessage(), containsString("Bundle-SymbolicName header is required")); - } + OsgiManifestParserException e = assertThrows(OsgiManifestParserException.class, + () -> parseManifest("noBsn.mf")); + assertThat(e.getMessage(), containsString("Bundle-SymbolicName header is required")); + } @Test @@ -44,34 +42,25 @@ public void testMissingVersion() throws Exception { @Test public void testInvalidVersion() throws Exception { - try { - parseManifest("invalidVersion.mf"); - fail(); - } catch (OsgiManifestParserException e) { - assertThat(e.getMessage(), - containsString("Invalid Manifest header \"Bundle-Version\": 1.0.0.%invalidQualifier")); - } + OsgiManifestParserException e = assertThrows(OsgiManifestParserException.class, + () -> parseManifest("invalidVersion.mf")); + assertThat(e.getMessage(), + containsString("Invalid Manifest header \"Bundle-Version\": 1.0.0.%invalidQualifier")); } @Test public void testDuplicateImport() throws Exception { - try { - parseManifest("duplicateImport.mf"); - fail(); - } catch (OsgiManifestParserException e) { - assertThat(e.getMessage(), containsString( - "Invalid manifest header Import-Package: \"org.w3c.dom\" : Cannot import a package more than once \"org.w3c.dom\"")); - } + OsgiManifestParserException e = assertThrows(OsgiManifestParserException.class, + () -> parseManifest("duplicateImport.mf")); + assertThat(e.getMessage(), containsString( + "Invalid manifest header Import-Package: \"org.w3c.dom\" : Cannot import a package more than once \"org.w3c.dom\"")); } @Test public void testInvalidVersionQualifier() throws Exception { - try { - parseManifest("invalidVersionQualifier.mf"); - fail(); - } catch (OsgiManifestParserException e) { - assertThat(e.getMessage(), containsString("Invalid Manifest header \"Bundle-Version\"")); - } + OsgiManifestParserException e = assertThrows(OsgiManifestParserException.class, + () -> parseManifest("invalidVersionQualifier.mf")); + assertThat(e.getMessage(), containsString("Invalid Manifest header \"Bundle-Version\"")); } @Test diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/resolver/DefaultTargetPlatformConfigurationReaderTest.java b/tycho-core/src/test/java/org/eclipse/tycho/core/resolver/DefaultTargetPlatformConfigurationReaderTest.java index 34de153dfa..a5fc5156f4 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/core/resolver/DefaultTargetPlatformConfigurationReaderTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/core/resolver/DefaultTargetPlatformConfigurationReaderTest.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.tycho.core.resolver; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -47,36 +48,26 @@ protected void tearDown() throws Exception { @Test public void testExtraRequirementMissingVersionRange() throws Exception { Xpp3Dom dom = createConfigurationDom("type", "id"); - try { - configurationReader.readExtraRequirements(new TargetPlatformConfiguration(), dom); - fail(); - } catch (BuildFailureException e) { - assertTrue(e.getMessage() - .contains("Element is missing in section.")); - } + BuildFailureException e = assertThrows(BuildFailureException.class, + () -> configurationReader.readExtraRequirements(new TargetPlatformConfiguration(), dom)); + assertTrue(e.getMessage() + .contains("Element is missing in section.")); } @Test public void testExtraRequirementMissingType() throws Exception { Xpp3Dom dom = createConfigurationDom("id", "versionRange"); - try { - configurationReader.readExtraRequirements(new TargetPlatformConfiguration(), dom); - fail(); - } catch (BuildFailureException e) { - assertTrue( - e.getMessage().contains("Element is missing in section.")); - } + BuildFailureException e = assertThrows(BuildFailureException.class, + () -> configurationReader.readExtraRequirements(new TargetPlatformConfiguration(), dom)); + assertTrue(e.getMessage().contains("Element is missing in section.")); } @Test public void testExtraRequirementId() throws Exception { Xpp3Dom dom = createConfigurationDom("type", "versionRange"); - try { - configurationReader.readExtraRequirements(new TargetPlatformConfiguration(), dom); - fail(); - } catch (BuildFailureException e) { - assertTrue(e.getMessage().contains("Element is missing in section.")); - } + BuildFailureException e = assertThrows(BuildFailureException.class, + () -> configurationReader.readExtraRequirements(new TargetPlatformConfiguration(), dom)); + assertTrue(e.getMessage().contains("Element is missing in section.")); } @Test() @@ -84,11 +75,9 @@ public void testAddTargetWithValidMissingTargetDefinition() { Xpp3Dom dom = createGavConfiguration("myGroupId", "myArtifactId", "myVersion"); MavenSession session = setupMockSession(); TargetPlatformConfiguration configuration = new TargetPlatformConfiguration(); - try { - configurationReader.addTargetArtifact(configuration, session, new MavenProject(), dom); - } catch (TargetPlatformConfigurationException e) { - assertMessageContains(e, "No target definition file(s) found in project"); - } + TargetPlatformConfigurationException e = assertThrows(TargetPlatformConfigurationException.class, + () -> configurationReader.addTargetArtifact(configuration, session, new MavenProject(), dom)); + assertMessageContains(e, "No target definition file(s) found in project"); } private void assertMessageContains(Throwable throwable, String string) { @@ -106,12 +95,9 @@ public void testAddTargetWithMissingVersionInTargetDefinition() throws MojoExecu Xpp3Dom dom = createGavConfiguration("myGroupId", "myArtifactId", null); MavenSession session = setupMockSession(); TargetPlatformConfiguration configuration = new TargetPlatformConfiguration(); - try { - configurationReader.addTargetArtifact(configuration, session, null, dom); - fail(); - } catch (TargetPlatformConfigurationException e) { - assertTrue(e.getMessage().contains("The target artifact configuration is invalid")); - } + TargetPlatformConfigurationException e = assertThrows(TargetPlatformConfigurationException.class, + () -> configurationReader.addTargetArtifact(configuration, session, null, dom)); + assertTrue(e.getMessage().contains("The target artifact configuration is invalid")); } @Test @@ -119,12 +105,9 @@ public void testAddTargetWithMissingGroupInTargetDefinition() throws MojoExecuti Xpp3Dom dom = createGavConfiguration(null, "myArtifactId", "myVersion"); MavenSession session = setupMockSession(); TargetPlatformConfiguration configuration = new TargetPlatformConfiguration(); - try { - configurationReader.addTargetArtifact(configuration, session, null, dom); - fail(); - } catch (TargetPlatformConfigurationException e) { - assertTrue(e.getMessage().contains("The target artifact configuration is invalid")); - } + TargetPlatformConfigurationException e = assertThrows(TargetPlatformConfigurationException.class, + () -> configurationReader.addTargetArtifact(configuration, session, null, dom)); + assertTrue(e.getMessage().contains("The target artifact configuration is invalid")); } @Test @@ -132,12 +115,9 @@ public void testAddTargetWithMissingArtifactIdInTargetDefinition() throws MojoEx Xpp3Dom dom = createGavConfiguration("myGroupId", null, "myVersion"); MavenSession session = setupMockSession(); TargetPlatformConfiguration configuration = new TargetPlatformConfiguration(); - try { - configurationReader.addTargetArtifact(configuration, session, null, dom); - fail(); - } catch (TargetPlatformConfigurationException e) { - assertTrue(e.getMessage().contains("The target artifact configuration is invalid")); - } + TargetPlatformConfigurationException e = assertThrows(TargetPlatformConfigurationException.class, + () -> configurationReader.addTargetArtifact(configuration, session, null, dom)); + assertTrue(e.getMessage().contains("The target artifact configuration is invalid")); } @Test @@ -148,11 +128,7 @@ public void testOptionalResolution() throws MojoExecutionException { opt.setValue("optional"); res.addChild(opt); dom.addChild(res); - try { - configurationReader.readDependencyResolutionConfiguration(new TargetPlatformConfiguration(), dom, null); - } catch (BuildFailureException e) { - fail(e.getMessage()); - } + configurationReader.readDependencyResolutionConfiguration(new TargetPlatformConfiguration(), dom, null); } private MavenSession setupMockSession() { diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/test/DefaultBundleReaderTest.java b/tycho-core/src/test/java/org/eclipse/tycho/core/test/DefaultBundleReaderTest.java index 3a347271cb..579d8d7a31 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/core/test/DefaultBundleReaderTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/core/test/DefaultBundleReaderTest.java @@ -15,8 +15,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.File; @@ -129,51 +129,38 @@ public void testLoadManifestFromJar() throws Exception { public void testLoadManifestFromInvalidDir() throws Exception { // dir has no META-INF/MANIFEST.MF nor plugin.xml/fragment.xml File dir = new File("src/test/resources/bundlereader/invalid"); - try { - bundleReader.loadManifest(dir); - fail(); - } catch (OsgiManifestParserException e) { - assertTrue(e.getMessage().contains("Manifest file not found")); - } + OsgiManifestParserException e = assertThrows(OsgiManifestParserException.class, + () -> bundleReader.loadManifest(dir)); + assertTrue(e.getMessage().contains("Manifest file not found")); } @Test public void testLoadManifestFromCorruptedJar() throws Exception { File jar = new File("src/test/resources/bundlereader/invalid/corrupt.jar"); - try { - bundleReader.loadManifest(jar); - fail(); - } catch (OsgiManifestParserException e) { - if (System.getProperty("java.specification.version").compareTo("11") >= 0) { - assertTrue(e.getMessage().contains("zip END header not found")); - } else { - assertTrue(e.getMessage().contains("error in opening zip file")); - } - + OsgiManifestParserException e = assertThrows(OsgiManifestParserException.class, + () -> bundleReader.loadManifest(jar)); + if (System.getProperty("java.specification.version").compareTo("11") >= 0) { + assertTrue(e.getMessage().contains("zip END header not found")); + } else { + assertTrue(e.getMessage().contains("error in opening zip file")); } } @Test public void testLoadManifestFromNonexistingFile() throws Exception { File jar = new File("NON_EXISTING.jar"); - try { - bundleReader.loadManifest(jar); - fail(); - } catch (OsgiManifestParserException e) { - assertTrue(e.getMessage().contains("Manifest file not found")); - } + OsgiManifestParserException e = assertThrows(OsgiManifestParserException.class, + () -> bundleReader.loadManifest(jar)); + assertTrue(e.getMessage().contains("Manifest file not found")); } @Test public void testLoadManifestFromPlainJar() throws Exception { File plainJar = new File("src/test/resources/bundlereader/jarshape/plain.jar"); - try { - bundleReader.loadManifest(plainJar); - fail(); - } catch (OsgiManifestParserException e) { - assertTrue(e.getMessage().contains("Exception parsing OSGi MANIFEST")); - assertTrue(e.getMessage().contains("is missing")); - } + OsgiManifestParserException e = assertThrows(OsgiManifestParserException.class, + () -> bundleReader.loadManifest(plainJar)); + assertTrue(e.getMessage().contains("Exception parsing OSGi MANIFEST")); + assertTrue(e.getMessage().contains("is missing")); } private File getTestJar() { diff --git a/tycho-core/src/test/java/org/eclipse/tycho/core/test/TychoTest.java b/tycho-core/src/test/java/org/eclipse/tycho/core/test/TychoTest.java index a5de9c7016..e4a0fba98f 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/core/test/TychoTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/core/test/TychoTest.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.tycho.core.test; +import static org.junit.Assert.assertThrows; + import java.io.File; import java.io.IOException; import java.util.List; @@ -73,13 +75,9 @@ public void testModuleOrder() throws Exception { public void testResolutionError() throws Exception { File basedir = getBasedir("projects/resolutionerror/p001"); - try { - getSortedProjects(basedir); - fail(); - } catch (Exception e) { - assertResolveError(e, - "Missing requirement: moduleorder.p001 0.0.1 requires 'java.package; moduleorder.p002 0.0.0' but it could not be found"); - } + Exception e = assertThrows(Exception.class, () -> getSortedProjects(basedir)); + assertResolveError(e, + "Missing requirement: moduleorder.p001 0.0.1 requires 'java.package; moduleorder.p002 0.0.0' but it could not be found"); } private void assertResolveError(Throwable e, String string) { @@ -97,24 +95,16 @@ private void assertResolveError(Throwable e, String string) { public void testFeatureMissingFeature() throws Exception { File basedir = getBasedir("projects/resolutionerror/feature_missing_feature"); - try { - getSortedProjects(basedir); - fail(); - } catch (Exception e) { - assertResolveError(e, - "feature_missing_feature.feature.group 1.0.0 requires 'org.eclipse.equinox.p2.iu; feature.not.found.feature.group 0.0.0' but it could not be found"); - } + Exception e = assertThrows(Exception.class, () -> getSortedProjects(basedir)); + assertResolveError(e, + "feature_missing_feature.feature.group 1.0.0 requires 'org.eclipse.equinox.p2.iu; feature.not.found.feature.group 0.0.0' but it could not be found"); } public void testFeatureMissingPlugin() throws Exception { File basedir = getBasedir("projects/resolutionerror/feature_missing_plugin"); - try { - getSortedProjects(basedir); - fail(); - } catch (Exception e) { - assertResolveError(e, - "feature_missing_feature.feature.group 1.0.0 requires 'org.eclipse.equinox.p2.iu; plugin.not.found 0.0.0' but it could not be found"); - } + Exception e = assertThrows(Exception.class, () -> getSortedProjects(basedir)); + assertResolveError(e, + "feature_missing_feature.feature.group 1.0.0 requires 'org.eclipse.equinox.p2.iu; plugin.not.found 0.0.0' but it could not be found"); } public void testProjectPriority() throws Exception { @@ -248,68 +238,44 @@ public void testWithValidExplicitTargetEnvironment() throws Exception { public void testWithMissingOsInExplicitTargetEnvironment() throws Exception { File basedir = getBasedir("projects/explicitenvironment/missingOs"); - try { - getSortedProjects(basedir); - fail("RuntimeException must be thrown when is missing in the target configuration (environment element)"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains( - "target-platform-configuration error in project explicitenvironment:missingos:eclipse-plugin")); - Throwable cause = e; - while (cause.getCause() != null) { - cause = cause.getCause(); - } - assertTrue(cause instanceof TargetPlatformConfigurationException); - assertEquals(" element is missing within target-platform-configuration (element )", - cause.getMessage()); + RuntimeException e = assertThrows(RuntimeException.class, () -> getSortedProjects(basedir)); + assertTrue(e.getMessage().contains( + "target-platform-configuration error in project explicitenvironment:missingos:eclipse-plugin")); + Throwable cause = e; + while (cause.getCause() != null) { + cause = cause.getCause(); } + assertTrue(cause instanceof TargetPlatformConfigurationException); + assertEquals(" element is missing within target-platform-configuration (element )", + cause.getMessage()); } public void testWithMissingWsInExplicitTargetEnvironment() throws Exception { File basedir = getBasedir("projects/explicitenvironment/missingWs"); - try { - getSortedProjects(basedir); - fail("RuntimeException must be thrown when is missing in the target configuration (environment element)"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains( - "target-platform-configuration error in project explicitenvironment:missingws:eclipse-plugin")); - Throwable cause = e; - while (cause.getCause() != null) { - cause = cause.getCause(); - } - assertTrue(cause instanceof TargetPlatformConfigurationException); - assertEquals(" element is missing within target-platform-configuration (element )", - cause.getMessage()); + RuntimeException e = assertThrows(RuntimeException.class, () -> getSortedProjects(basedir)); + assertTrue(e.getMessage().contains( + "target-platform-configuration error in project explicitenvironment:missingws:eclipse-plugin")); + Throwable cause = e; + while (cause.getCause() != null) { + cause = cause.getCause(); } + assertTrue(cause instanceof TargetPlatformConfigurationException); + assertEquals(" element is missing within target-platform-configuration (element )", + cause.getMessage()); } public void testWithMissingArchInExplicitTargetEnvironment() throws Exception { File basedir = getBasedir("projects/explicitenvironment/missingArch"); - try { - getSortedProjects(basedir); - fail("RuntimeException must be thrown when is missing in the target configuration (environment element)"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains( - "target-platform-configuration error in project explicitenvironment:missingarch:eclipse-plugin")); - Throwable cause = e; - while (cause.getCause() != null) { - cause = cause.getCause(); - } - assertTrue(cause instanceof TargetPlatformConfigurationException); - assertEquals(" element is missing within target-platform-configuration (element )", - cause.getMessage()); + RuntimeException e = assertThrows(RuntimeException.class, () -> getSortedProjects(basedir)); + assertTrue(e.getMessage().contains( + "target-platform-configuration error in project explicitenvironment:missingarch:eclipse-plugin")); + Throwable cause = e; + while (cause.getCause() != null) { + cause = cause.getCause(); } - } - - public void testWithProjectReferencesItself() throws Exception { - //Does not work anymore -// File basedir = getBasedir("projects/referencesItself"); -// try { -// getSortedProjects(basedir); -// fail(); -// } catch (Exception e) { -// assertTrue(e.getMessage().contains("Bundle referencesItself cannot be resolved")); -// } - + assertTrue(cause instanceof TargetPlatformConfigurationException); + assertEquals(" element is missing within target-platform-configuration (element )", + cause.getMessage()); } } diff --git a/tycho-extras/tycho-p2-extras-plugin/src/test/java/org/eclipse/tycho/plugins/p2/extras/MirrorMojoTest.java b/tycho-extras/tycho-p2-extras-plugin/src/test/java/org/eclipse/tycho/plugins/p2/extras/MirrorMojoTest.java index 658f6a5d5b..55084f0c74 100644 --- a/tycho-extras/tycho-p2-extras-plugin/src/test/java/org/eclipse/tycho/plugins/p2/extras/MirrorMojoTest.java +++ b/tycho-extras/tycho-p2-extras-plugin/src/test/java/org/eclipse/tycho/plugins/p2/extras/MirrorMojoTest.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.tycho.plugins.p2.extras; +import static org.junit.Assert.assertThrows; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -142,14 +144,10 @@ public void testTargetPlatformAsSource() throws Exception { featureIU.id = "test.feature.feature.group"; setVariableValueToObject(mirrorMojo, "ius", Collections.singletonList(featureIU)); setVariableValueToObject(mirrorMojo, "targetPlatformAsSource", Boolean.TRUE); - try { - // Source is allowed to be empty, for example when targetPlatformAsSource is set, but in this test - // project we have no target platform so it should fail gracefully instead of throwing a NPE - mirrorMojo.execute(); - fail(); - } catch (MojoExecutionException e) { - assertEquals(e.getMessage(), "No repository provided as 'source'"); - } + // Source is allowed to be empty, for example when targetPlatformAsSource is set, but in this test + // project we have no target platform so it should fail gracefully instead of throwing a NPE + MojoExecutionException e = assertThrows(MojoExecutionException.class, () -> mirrorMojo.execute()); + assertEquals(e.getMessage(), "No repository provided as 'source'"); } private static void assertMirroredBundle(File publishedContentDir, String bundleID, String version) { diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/DocumentBundlePluginTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/DocumentBundlePluginTest.java index 7a2a6a59b2..257d9d125f 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/DocumentBundlePluginTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/DocumentBundlePluginTest.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.tycho.test; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.io.File; import java.nio.file.Files; @@ -26,15 +26,11 @@ public class DocumentBundlePluginTest extends AbstractTychoIntegrationTest { @Test public void testGenerateIndex() throws Exception { Verifier verifier = getVerifier("document-bundle-plugin/build-help-index", true, true); - try { - verifier.executeGoal("package"); - fail(); - } catch (VerificationException e) { - // a full test seems rather complex, so what we can do here is call the test and - // check that the mojo was executed successful (even though it produces an - // error) - verifier.verifyTextInLog("Help documentation could not be indexed completely"); - } + assertThrows(VerificationException.class, () -> verifier.executeGoal("package")); + // a full test seems rather complex, so what we can do here is call the test and + // check that the mojo was executed successful (even though it produces an + // error) + verifier.verifyTextInLog("Help documentation could not be indexed completely"); } @Test diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO330validateVersion/ValidateVersionTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO330validateVersion/ValidateVersionTest.java index 657f937ecc..0641d7047a 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO330validateVersion/ValidateVersionTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO330validateVersion/ValidateVersionTest.java @@ -12,34 +12,25 @@ *******************************************************************************/ package org.eclipse.tycho.test.TYCHO330validateVersion; +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 ValidateVersionTest extends AbstractTychoIntegrationTest { - @Test - public void testPlugin() throws Exception { - Verifier verifier = getVerifier("/TYCHO330validateVersion/bundle", false); - try { - verifier.executeGoal("verify"); - Assert.fail(); - } catch (VerificationException e) { - // good enough for now - } + @Test + public void testPlugin() throws Exception { + Verifier verifier = getVerifier("/TYCHO330validateVersion/bundle", false); + assertThrows(VerificationException.class, () -> verifier.executeGoal("verify")); - } + } - @Test - public void testFeature() throws Exception { - Verifier verifier = getVerifier("/TYCHO330validateVersion/feature", false); - try { - verifier.executeGoal("verify"); - Assert.fail(); - } catch (VerificationException e) { - // good enough for now - } - } + @Test + public void testFeature() throws Exception { + Verifier verifier = getVerifier("/TYCHO330validateVersion/feature", false); + assertThrows(VerificationException.class, () -> verifier.executeGoal("verify")); + } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/FailOnWarningTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/FailOnWarningTest.java index 5d299a4592..90d34d6bb6 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/FailOnWarningTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/FailOnWarningTest.java @@ -13,7 +13,7 @@ package org.eclipse.tycho.test.compiler; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; @@ -22,17 +22,13 @@ public class FailOnWarningTest extends AbstractTychoIntegrationTest { - @Test - public void testCompilerFailOnWarning() throws Exception { - Verifier verifier = getVerifier("compiler.failOnWarning", false); - try { - verifier.executeGoal("compile"); - fail(); - } catch (VerificationException e) { - // expected - verifier.verifyTextInLog("The value of the local variable a is not used"); - verifier.verifyTextInLog("1 problem (1 warning)"); - verifier.verifyTextInLog("error: warnings found and -failOnWarning specified"); - } - } + @Test + public void testCompilerFailOnWarning() throws Exception { + Verifier verifier = getVerifier("compiler.failOnWarning", false); + assertThrows(VerificationException.class, () -> verifier.executeGoal("compile")); + // expected + verifier.verifyTextInLog("The value of the local variable a is not used"); + verifier.verifyTextInLog("1 problem (1 warning)"); + verifier.verifyTextInLog("error: warnings found and -failOnWarning specified"); + } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/MavenCompilerPluginTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/MavenCompilerPluginTest.java index 568ab6219a..c411dcff0d 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/MavenCompilerPluginTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/MavenCompilerPluginTest.java @@ -13,47 +13,44 @@ package org.eclipse.tycho.test.compiler; +import static org.junit.Assert.assertThrows; + +import java.util.List; + 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; -import java.util.List; public class MavenCompilerPluginTest extends AbstractTychoIntegrationTest { - @Test - public void testJDTCompilerId() throws Exception { - Verifier verifier = getVerifier("compiler.mavenCompilerPlugin", false); - try { - verifier.executeGoal("compile"); - Assert.fail(); - } catch (VerificationException e) { - // expected - verifier.verifyTextInLog("field Foo.unused is not used"); - } - } - - @Test - public void testAdditionalBundles() throws Exception { - Verifier verifier = getVerifier("compiler.additional.bundles", true); - verifier.executeGoal("compile"); - verifier.verifyErrorFreeLog(); - } - - - @Test - public void testAdditionalBundles2() throws Exception { - Verifier verifier = getVerifier("compiler.additional.bundles2", false, false); - verifier.executeGoals(List.of("clean","install")); - verifier.verifyErrorFreeLog(); - } - - @Test - public void testLimitModules() throws Exception { - Verifier verifier = getVerifier("compiler.limit.modules", true); - verifier.executeGoal("compile"); - verifier.verifyErrorFreeLog(); - } + @Test + public void testJDTCompilerId() throws Exception { + Verifier verifier = getVerifier("compiler.mavenCompilerPlugin", false); + assertThrows(VerificationException.class, () -> verifier.executeGoal("compile")); + // expected + verifier.verifyTextInLog("field Foo.unused is not used"); + } + + @Test + public void testAdditionalBundles() throws Exception { + Verifier verifier = getVerifier("compiler.additional.bundles", true); + verifier.executeGoal("compile"); + verifier.verifyErrorFreeLog(); + } + + @Test + public void testAdditionalBundles2() throws Exception { + Verifier verifier = getVerifier("compiler.additional.bundles2", false, false); + verifier.executeGoals(List.of("clean", "install")); + verifier.verifyErrorFreeLog(); + } + + @Test + public void testLimitModules() throws Exception { + Verifier verifier = getVerifier("compiler.limit.modules", true); + verifier.executeGoal("compile"); + verifier.verifyErrorFreeLog(); + } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/MisconfigurationTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/MisconfigurationTest.java index f40eb526bb..5ea5cf6b59 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/MisconfigurationTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/MisconfigurationTest.java @@ -13,7 +13,7 @@ package org.eclipse.tycho.test.compiler; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; @@ -22,15 +22,11 @@ public class MisconfigurationTest extends AbstractTychoIntegrationTest { - @Test - public void testCompilerMisconfigured() throws Exception { - Verifier verifier = getVerifier("compiler.misconfiguration", false); - try { - verifier.executeGoal("compile"); - fail(); - } catch (VerificationException e) { - // expected - verifier.verifyTextInLog("org.codehaus.plexus.compiler.CompilerException: Unrecognized option : -boo boo"); - } - } + @Test + public void testCompilerMisconfigured() throws Exception { + Verifier verifier = getVerifier("compiler.misconfiguration", false); + assertThrows(VerificationException.class, () -> verifier.executeGoal("compile")); + // expected + verifier.verifyTextInLog("org.codehaus.plexus.compiler.CompilerException: Unrecognized option : -boo boo"); + } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/RequireJREPackagesImportTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/RequireJREPackagesImportTest.java index 51a2138255..7cbce1620b 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/RequireJREPackagesImportTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/RequireJREPackagesImportTest.java @@ -13,7 +13,7 @@ package org.eclipse.tycho.test.compiler; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; @@ -27,12 +27,8 @@ public class RequireJREPackagesImportTest extends AbstractTychoIntegrationTest { @Test public void testStrictImportJREPackages() throws Exception { Verifier verifier = getVerifier("compiler.requireJREPackageImports", false); - try { - verifier.executeGoal("compile"); - fail(); - } catch (VerificationException e) { - // expected - verifier.verifyTextInLog("[ERROR] Access restriction: The type 'InitialContext' is not API"); - } + assertThrows(VerificationException.class, () -> verifier.executeGoal("compile")); + // expected + verifier.verifyTextInLog("[ERROR] Access restriction: The type 'InitialContext' is not API"); } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/TestErrorMessages.java b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/TestErrorMessages.java index 5c6b6720f2..546fd664fa 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/TestErrorMessages.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/compiler/TestErrorMessages.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.tycho.test.compiler; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; @@ -44,13 +44,9 @@ public void testBREEWithoutProfile() throws Exception { public void testMissingBREEWithPlainProfile() throws Exception { Verifier verifier = getVerifier("compiler.messages/missing-bree", false); verifier.addCliOption("-Pplain"); - try { - verifier.executeGoal("compile"); - fail(); - } catch (VerificationException e) { - verifier.verifyTextInLog("java17.bundle 1.0.0 requires Execution Environment that matches"); - verifier.verifyTextInLog("but the current resolution context uses"); - } + assertThrows(VerificationException.class, () -> verifier.executeGoal("compile")); + verifier.verifyTextInLog("java17.bundle 1.0.0 requires Execution Environment that matches"); + verifier.verifyTextInLog("but the current resolution context uses"); } /** @@ -62,12 +58,8 @@ public void testMissingBREEWithPlainProfile() throws Exception { public void testMissingBREEWithJustJProfile() throws Exception { Verifier verifier = getVerifier("compiler.messages/missing-bree", false); verifier.addCliOption("-Pjustj"); - try { - verifier.executeGoal("compile"); - fail(); - } catch (VerificationException e) { - verifier.verifyTextInLog( - "The following Execution Environments are currently known but are ignored by configuration"); - } + assertThrows(VerificationException.class, () -> verifier.executeGoal("compile")); + verifier.verifyTextInLog( + "The following Execution Environments are currently known but are ignored by configuration"); } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/issue1093/Issue1093Test.java b/tycho-its/src/test/java/org/eclipse/tycho/test/issue1093/Issue1093Test.java index cf0498e504..2524f15c13 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/issue1093/Issue1093Test.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/issue1093/Issue1093Test.java @@ -10,7 +10,7 @@ package org.eclipse.tycho.test.issue1093; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.util.List; @@ -24,12 +24,8 @@ public class Issue1093Test extends AbstractTychoIntegrationTest { @Test public void test() throws Exception { Verifier verifier = getVerifier("issue1093", false); - try { - verifier.executeGoals(List.of("clean", "verify")); - fail(); - } catch (VerificationException e) { - // expected - verifier.verifyTextInLog("bin.includes value(s) [non-existing-file.txt] do not match any files"); - } + assertThrows(VerificationException.class, () -> verifier.executeGoals(List.of("clean", "verify"))); + // expected + verifier.verifyTextInLog("bin.includes value(s) [non-existing-file.txt] do not match any files"); } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/limitations/MixedTychoVersionsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/limitations/MixedTychoVersionsTest.java index ea33a2b2f7..51246a3333 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/limitations/MixedTychoVersionsTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/limitations/MixedTychoVersionsTest.java @@ -13,7 +13,7 @@ package org.eclipse.tycho.test.limitations; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; @@ -23,17 +23,13 @@ public class MixedTychoVersionsTest extends AbstractTychoIntegrationTest { - @Test - public void testSeveralTychoVersionsConfigured() throws Exception { - Verifier verifier = getVerifier("limitations.tychoVersions", false); - try { - verifier.executeGoal("compile"); - fail(); - } catch (VerificationException e) { - // expected - verifier.verifyTextInLog("[ERROR] Several versions of Tycho plugins are configured [0.13.0, 0.14.0, " - + TychoVersion.getTychoVersion() + "]:"); - } - } + @Test + public void testSeveralTychoVersionsConfigured() throws Exception { + Verifier verifier = getVerifier("limitations.tychoVersions", false); + assertThrows(VerificationException.class, () -> verifier.executeGoal("compile")); + // expected + verifier.verifyTextInLog("[ERROR] Several versions of Tycho plugins are configured [0.13.0, 0.14.0, " + + TychoVersion.getTychoVersion() + "]:"); + } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/FailIfNoTestsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/FailIfNoTestsTest.java index f4728341c7..0c2fe535ce 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/FailIfNoTestsTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/FailIfNoTestsTest.java @@ -12,10 +12,11 @@ *******************************************************************************/ package org.eclipse.tycho.test.surefire; +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 FailIfNoTestsTest extends AbstractTychoIntegrationTest { @@ -33,12 +34,7 @@ public void testNoTestsNoFailure() throws Exception { @Test public void testNoTestsFailureDefaultCase() throws Exception { Verifier verifier = getVerifier("surefire.noTests"); - try { - verifier.executeGoal("integration-test"); - Assert.fail(); - } catch (VerificationException e) { - // expected - } + assertThrows(VerificationException.class, () -> verifier.executeGoal("integration-test")); verifier.verifyTextInLog("No tests found"); } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/TrimStackTrace.java b/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/TrimStackTrace.java index 2795609e2f..570a85c25f 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/TrimStackTrace.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/TrimStackTrace.java @@ -13,25 +13,20 @@ *******************************************************************************/ package org.eclipse.tycho.test.surefire; +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 TrimStackTrace extends AbstractTychoIntegrationTest { - @Test - public void testTrimStackTraceFalse() throws Exception { - Verifier verifier = getVerifier("surefire.trimstacktrace"); - try { - verifier.executeGoal("integration-test"); - Assert.fail(); - } catch (VerificationException e) { - // expected - verifier.verifyTextInLog("org.junit.Assert.fail"); - } - - } - + @Test + public void testTrimStackTraceFalse() throws Exception { + Verifier verifier = getVerifier("surefire.trimstacktrace"); + assertThrows(VerificationException.class, () -> verifier.executeGoal("integration-test")); + // expected + verifier.verifyTextInLog("org.junit.Assert.fail"); + } } diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetDependenciesAccrossLocationsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetDependenciesAccrossLocationsTest.java index 7ba645be82..9daf7afb0b 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetDependenciesAccrossLocationsTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/target/TargetDependenciesAccrossLocationsTest.java @@ -1,6 +1,6 @@ package org.eclipse.tycho.test.target; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.io.File; import java.io.IOException; @@ -53,13 +53,9 @@ public void slicerDoesNotFailWhenDependenciesExistInDifferentTargetLocation() th public void slicerDoesNotFailWhenDependenciesDoNotExistInAnyLocation() throws Exception { Verifier verifier = getVerifier("target.slicerWithMissingDependencies", false); fillInTargetUrls(verifier); - try { - verifier.executeGoals(Arrays.asList("package")); - fail(); - } catch (VerificationException e) { - verifier.verifyTextInLog( - "Missing requirement: bundle2 1.0.0 requires 'osgi.bundle; bundle1 0.0.0' but it could not be found"); - } + assertThrows(VerificationException.class, () -> verifier.executeGoals(Arrays.asList("package"))); + verifier.verifyTextInLog( + "Missing requirement: bundle2 1.0.0 requires 'osgi.bundle; bundle1 0.0.0' but it could not be found"); } @Test diff --git a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/IncludeValidationHelperTest.java b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/IncludeValidationHelperTest.java index 43cdcac582..42658f04e4 100644 --- a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/IncludeValidationHelperTest.java +++ b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/IncludeValidationHelperTest.java @@ -14,6 +14,7 @@ package org.eclipse.tycho.packaging; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -50,35 +51,26 @@ public void testCheckBinIncludesExistAntPatterns() throws Exception { @Test public void testCheckBinIncludesDontExist() throws Exception { - BuildPropertiesImpl buildProperties = createBuildProperties("bin.includes", "foo2.txt, bar2*,**/*.me"); - try { - subject.checkBinIncludesExist(createMockProject(), buildProperties, true); - fail(); - } catch (MojoExecutionException e) { - assertStringContains("bin.includes value(s) [foo2.txt, bar2*] do not match any files.", e.getMessage()); - } - } + BuildPropertiesImpl buildProperties = createBuildProperties("bin.includes", "foo2.txt, bar2*,**/*.me"); + MojoExecutionException e = assertThrows(MojoExecutionException.class, + () -> subject.checkBinIncludesExist(createMockProject(), buildProperties, true)); + assertStringContains("bin.includes value(s) [foo2.txt, bar2*] do not match any files.", e.getMessage()); + } @Test public void testCheckBinIncludesNotSpecified() throws Exception { - BuildPropertiesImpl buildProperties = createBuildProperties("no.bin.includes", "bin.includes is not specified"); - try { - subject.checkBinIncludesExist(createMockProject(), buildProperties, true); - fail(); - } catch (MojoExecutionException e) { - assertStringContains("bin.includes value(s) must be specified", e.getMessage()); - } + BuildPropertiesImpl buildProperties = createBuildProperties("no.bin.includes", "bin.includes is not specified"); + MojoExecutionException e = assertThrows(MojoExecutionException.class, + () -> subject.checkBinIncludesExist(createMockProject(), buildProperties, true)); + assertStringContains("bin.includes value(s) must be specified", e.getMessage()); } @Test public void testCheckSourceIncludesDontExist() throws Exception { - BuildPropertiesImpl buildProperties = createBuildProperties("src.includes", "foo3, bar3*,**/*.me"); - try { - subject.checkSourceIncludesExist(createMockProject(), buildProperties, true); - fail(); - } catch (MojoExecutionException e) { - assertStringContains("src.includes value(s) [foo3, bar3*] do not match any files.", e.getMessage()); - } + BuildPropertiesImpl buildProperties = createBuildProperties("src.includes", "foo3, bar3*,**/*.me"); + MojoExecutionException e = assertThrows(MojoExecutionException.class, + () -> subject.checkSourceIncludesExist(createMockProject(), buildProperties, true)); + assertStringContains("src.includes value(s) [foo3, bar3*] do not match any files.", e.getMessage()); } @Test