From 3439ebc333eaac7f2803e7af201b9a3e45339185 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Mon, 4 Dec 2023 12:51:27 +0100 Subject: [PATCH] Replace calls to CoreTest.assertEquals() with matcher statements #903 Replaces all calls to CoreTest.assertEquals() for comparing array contents with matcher statements. This makes the assertions independent from JUnit 3 and improves the provided error messages in case of a test failure. The change also improves the other assertions in the touched test classes. Contributes to https://github.com/eclipse-platform/eclipse.platform/issues/903 --- .../internal/builders/BuildContextTest.java | 110 +++++----- .../internal/builders/ContextBuilder.java | 19 +- .../ModelObjectReaderWriterTest.java | 197 ++++++++---------- .../resources/ProjectBuildConfigsTest.java | 54 +++-- .../ProjectDynamicReferencesTest.java | 163 ++++++++------- .../resources/ProjectReferencesTest.java | 91 ++++---- .../resources/WorkspacePreferencesTest.java | 7 +- .../core/tests/resources/NatureTest.java | 16 +- .../ProjectDescriptionDynamicTest.java | 32 +-- .../session/WorkspaceDescriptionTest.java | 19 +- 10 files changed, 377 insertions(+), 331 deletions(-) diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuildContextTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuildContextTest.java index 65ccfe03882..f20622b11d0 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuildContextTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuildContextTest.java @@ -13,6 +13,10 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.builders; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.emptyArray; + import org.eclipse.core.internal.events.BuildContext; import org.eclipse.core.internal.resources.BuildConfiguration; import org.eclipse.core.resources.IBuildConfiguration; @@ -91,8 +95,8 @@ private IBuildConfiguration changeActiveBuildConfig(IProject project) throws Cor return config; } } - assertTrue(false); - return null; + throw new IllegalStateException( + "No build config other than the active one could be found for project: " + project); } /** @@ -129,22 +133,22 @@ public void testBuildContext() { IBuildContext context; context = new BuildContext(p0v0, new IBuildConfiguration[] {p0v0, p1v0}, buildOrder); - assertEquals("1.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs()); - assertEquals("1.1", new IBuildConfiguration[] {p0v1, p1v0}, context.getAllReferencingBuildConfigs()); - assertEquals("1.2", new IBuildConfiguration[] {p0v0, p1v0}, context.getRequestedConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), emptyArray()); + assertThat(context.getAllReferencingBuildConfigs(), arrayContaining(p0v1, p1v0)); + assertThat(context.getRequestedConfigs(), arrayContaining(p0v0, p1v0)); context = new BuildContext(p0v1, buildOrder, buildOrder); - assertEquals("2.0", new IBuildConfiguration[] {p0v0}, context.getAllReferencedBuildConfigs()); - assertEquals("2.1", new IBuildConfiguration[] {p1v0}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), arrayContaining(p0v0)); + assertThat(context.getAllReferencingBuildConfigs(), arrayContaining(p1v0)); context = new BuildContext(p1v0, buildOrder, buildOrder); - assertEquals("3.0", new IBuildConfiguration[] {p0v0, p0v1}, context.getAllReferencedBuildConfigs()); - assertEquals("3.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), arrayContaining(p0v0, p0v1)); + assertThat(context.getAllReferencingBuildConfigs(), emptyArray()); // And it works with no build context too context = new BuildContext(p1v0); - assertEquals("4.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs()); - assertEquals("4.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), emptyArray()); + assertThat(context.getAllReferencingBuildConfigs(), emptyArray()); } public void testSingleProjectBuild() throws CoreException { @@ -153,20 +157,20 @@ public void testSingleProjectBuild() throws CoreException { setupSimpleReferences(); ContextBuilder.clearStats(); project0.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor()); - assertTrue("1.0", ContextBuilder.checkValid()); + ContextBuilder.assertValid(); IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig()); - assertEquals("2.0", 0, context.getAllReferencedBuildConfigs().length); - assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length); + assertThat(context.getAllReferencedBuildConfigs(), emptyArray()); + assertThat(context.getAllReferencingBuildConfigs(), emptyArray()); // Change the active build configuration will cause the project to be rebuilt ContextBuilder.clearStats(); IBuildConfiguration newActive = changeActiveBuildConfig(project0); waitForBuild(); - assertTrue("3.0", ContextBuilder.checkValid()); + ContextBuilder.assertValid(); context = ContextBuilder.getContext(newActive); - assertEquals("3.1", 0, context.getAllReferencedBuildConfigs().length); + assertThat(context.getAllReferencedBuildConfigs(), emptyArray()); } /** @@ -178,28 +182,30 @@ public void testWorkspaceBuildProject() throws CoreException { // Build project and resolve references getWorkspace().build(new IBuildConfiguration[] {project0.getActiveBuildConfig()}, IncrementalProjectBuilder.FULL_BUILD, true, getMonitor()); - assertTrue("1.0", ContextBuilder.checkValid()); + ContextBuilder.assertValid(); IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig()); - assertEquals("2.0", new IBuildConfiguration[] {project2.getActiveBuildConfig(), project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs()); - assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length); + assertThat(context.getAllReferencedBuildConfigs(), + arrayContaining(project2.getActiveBuildConfig(), project1.getActiveBuildConfig())); + assertThat(context.getAllReferencingBuildConfigs(), emptyArray()); context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild; - assertEquals("3.0", new IBuildConfiguration[] {project2.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs()); - assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), arrayContaining(project2.getActiveBuildConfig())); + assertThat(context.getAllReferencingBuildConfigs(), arrayContaining(project0.getActiveBuildConfig())); context = ContextBuilder.getBuilder(project2.getActiveBuildConfig()).contextForLastBuild; - assertEquals("4.0", 0, context.getAllReferencedBuildConfigs().length); - assertEquals("4.1", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), emptyArray()); + assertThat(context.getAllReferencingBuildConfigs(), + arrayContaining(project1.getActiveBuildConfig(), project0.getActiveBuildConfig())); // Build just project0 ContextBuilder.clearStats(); getWorkspace().build(new IBuildConfiguration[] {project0.getActiveBuildConfig()}, IncrementalProjectBuilder.FULL_BUILD, false, getMonitor()); - assertTrue("5.0", ContextBuilder.checkValid()); + ContextBuilder.assertValid(); context = ContextBuilder.getContext(project0.getActiveBuildConfig()); - assertTrue("5.1", context.getAllReferencedBuildConfigs().length == 0); - assertTrue("5.2", context.getAllReferencingBuildConfigs().length == 0); + assertThat(context.getAllReferencedBuildConfigs(), emptyArray()); + assertThat(context.getAllReferencingBuildConfigs(), emptyArray()); } /** @@ -210,19 +216,21 @@ public void testWorkspaceBuildProjects() throws CoreException { ContextBuilder.clearStats(); // build project0 & project2 ; project1 will end up being built too. getWorkspace().build(new IBuildConfiguration[] {project0.getActiveBuildConfig(), project2.getActiveBuildConfig()}, IncrementalProjectBuilder.FULL_BUILD, true, getMonitor()); - assertTrue("1.0", ContextBuilder.checkValid()); + ContextBuilder.assertValid(); IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig()); - assertEquals("2.0", new IBuildConfiguration[] {project2.getActiveBuildConfig(), project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs()); - assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length); + assertThat(context.getAllReferencedBuildConfigs(), + arrayContaining(project2.getActiveBuildConfig(), project1.getActiveBuildConfig())); + assertThat(context.getAllReferencingBuildConfigs(), emptyArray()); context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild; - assertEquals("3.0", new IBuildConfiguration[] {project2.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs()); - assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), arrayContaining(project2.getActiveBuildConfig())); + assertThat(context.getAllReferencingBuildConfigs(), arrayContaining(project0.getActiveBuildConfig())); context = ContextBuilder.getBuilder(project2.getActiveBuildConfig()).contextForLastBuild; - assertEquals("4.0", 0, context.getAllReferencedBuildConfigs().length); - assertEquals("4.1", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), emptyArray()); + assertThat(context.getAllReferencingBuildConfigs(), + arrayContaining(project1.getActiveBuildConfig(), project0.getActiveBuildConfig())); } /** @@ -235,19 +243,21 @@ public void testReferenceActiveVariant() throws CoreException { ContextBuilder.clearStats(); getWorkspace().build(new IBuildConfiguration[] {project0.getActiveBuildConfig()}, IncrementalProjectBuilder.FULL_BUILD, true, getMonitor()); - assertTrue("1.0", ContextBuilder.checkValid()); + ContextBuilder.assertValid(); IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig()); - assertEquals("2.0", new IBuildConfiguration[] {project2.getActiveBuildConfig(), project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs()); - assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length); + assertThat(context.getAllReferencedBuildConfigs(), + arrayContaining(project2.getActiveBuildConfig(), project1.getActiveBuildConfig())); + assertThat(context.getAllReferencingBuildConfigs(), emptyArray()); context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild; - assertEquals("3.0", new IBuildConfiguration[] {project2.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs()); - assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), arrayContaining(project2.getActiveBuildConfig())); + assertThat(context.getAllReferencingBuildConfigs(), arrayContaining(project0.getActiveBuildConfig())); context = ContextBuilder.getBuilder(project2.getActiveBuildConfig()).contextForLastBuild; - assertEquals("4.0", 0, context.getAllReferencedBuildConfigs().length); - assertEquals("4.1", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), emptyArray()); + assertThat(context.getAllReferencingBuildConfigs(), + arrayContaining(project1.getActiveBuildConfig(), project0.getActiveBuildConfig())); } /** @@ -262,27 +272,27 @@ public void testReferenceVariantTwice() throws CoreException { ContextBuilder.clearStats(); getWorkspace().build(new IBuildConfiguration[] {project0.getActiveBuildConfig()}, IncrementalProjectBuilder.FULL_BUILD, true, getMonitor()); - assertTrue("1.0", ContextBuilder.checkValid()); + ContextBuilder.assertValid(); IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig()); - assertEquals("2.0", new IBuildConfiguration[] {project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs()); - assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length); - assertEquals("2.2", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getRequestedConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), arrayContaining(project1.getActiveBuildConfig())); + assertThat(context.getAllReferencingBuildConfigs(), emptyArray()); + assertThat(context.getRequestedConfigs(), arrayContaining(project0.getActiveBuildConfig())); context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild; - assertEquals("3.0", 0, context.getAllReferencedBuildConfigs().length); - assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), emptyArray()); + assertThat(context.getAllReferencingBuildConfigs(), arrayContaining(project0.getActiveBuildConfig())); // Change the active configuration of project1, and test that two configurations are built ContextBuilder.clearStats(); IBuildConfiguration project1PreviousActive = project1.getActiveBuildConfig(); IBuildConfiguration project1NewActive = changeActiveBuildConfig(project1); getWorkspace().build(new IBuildConfiguration[] {project0.getActiveBuildConfig()}, IncrementalProjectBuilder.FULL_BUILD, true, getMonitor()); - assertTrue("4.0", ContextBuilder.checkValid()); + ContextBuilder.assertValid(); context = ContextBuilder.getContext(project0.getActiveBuildConfig()); - assertEquals("4.1", new IBuildConfiguration[] {project1PreviousActive, project1NewActive}, context.getAllReferencedBuildConfigs()); - assertEquals("4.2", 0, context.getAllReferencingBuildConfigs().length); - assertEquals("4.3", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getRequestedConfigs()); + assertThat(context.getAllReferencedBuildConfigs(), arrayContaining(project1PreviousActive, project1NewActive)); + assertThat(context.getAllReferencingBuildConfigs(), emptyArray()); + assertThat(context.getRequestedConfigs(), arrayContaining(project0.getActiveBuildConfig())); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/ContextBuilder.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/ContextBuilder.java index 42cbe2ed449..10c1c4569ee 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/ContextBuilder.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/ContextBuilder.java @@ -13,9 +13,15 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.builders; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + import java.util.HashMap; import java.util.Map; -import org.eclipse.core.resources.*; +import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.resources.IBuildContext; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; @@ -53,16 +59,13 @@ public static IBuildContext getContext(IBuildConfiguration variant) { return getBuilder(variant).contextForLastBuild; } - public static boolean checkValid() { + public static void assertValid() { for (ContextBuilder builder : builders.values()) { - if (builder.getRuleCalledForLastBuild && !builder.contextForLastBuild.equals(builder.contextForLastBuildInGetRule)) { - return false; - } - if (builder.getRuleCalledForLastBuild && !builder.buildConfigurationForLastBuild.equals(builder.buildConfigurationForLastBuildInGetRule)) { - return false; + if (builder.getRuleCalledForLastBuild) { + assertThat(builder.contextForLastBuild, is(builder.contextForLastBuildInGetRule)); + assertThat(builder.buildConfigurationForLastBuild, is(builder.buildConfigurationForLastBuildInGetRule)); } } - return true; } public static void clearStats() { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java index 7b45cb41f77..b9eb3095392 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java @@ -15,6 +15,16 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.resources; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.anEmptyMap; +import static org.hamcrest.Matchers.arrayWithSize; +import static org.hamcrest.Matchers.emptyArray; +import static org.hamcrest.Matchers.emptyString; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -160,88 +170,63 @@ private HashMap buildBaselineDescriptors() { return result; } - private void compareBuildSpecs(int errorTag, ICommand[] commands, ICommand[] commands2) { + private void compareBuildSpecs(ICommand[] commands, ICommand[] commands2) { // ASSUMPTION: commands and commands2 are non-null - assertEquals(errorTag + ".2.0", commands.length, commands2.length); + assertThat("different number of commands", commands, arrayWithSize(commands2.length)); for (int i = 0; i < commands.length; i++) { - assertTrue(errorTag + ".2." + (i + 1) + "0", commands[i].getBuilderName().equals(commands2[i].getBuilderName())); + assertThat("names of builders at index " + i + " are different", commands[i].getBuilderName(), + is(commands2[i].getBuilderName())); Map args = commands[i].getArguments(); Map args2 = commands2[i].getArguments(); - assertEquals(errorTag + ".2." + (i + 1) + "0", args.size(), args2.size()); - int x = 1; + assertThat("different number of arguments for builder at index " + i, args.entrySet(), + hasSize(args2.size())); for (Entry entry : args.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); String value2 = args2.get(key); if (value == null) { - assertNull(errorTag + ".2." + (i + 1) + x, value2); + assertThat("value for key '" + key + "' should be null", value2, nullValue()); } else { - assertTrue(errorTag + ".3." + (i + 1) + x, args.get(key).equals((args2.get(key)))); + assertThat("unequal values for key: " + key, args.get(key), is(args2.get(key))); } - x++; } } } - private void compareLinks(int errorTag, HashMap links, HashMap links2) { - if (links == null) { - assertNull(errorTag + ".4.0", links2); - return; - } - assertEquals(errorTag + ".4.01", links.size(), links2.size()); - int x = 1; - for (Entry entry : links.entrySet()) { - IPath key = entry.getKey(); - LinkDescription value = entry.getValue(); - LinkDescription value2 = links2.get(key); - assertTrue(errorTag + ".4." + x, value.getProjectRelativePath().equals(value2.getProjectRelativePath())); - assertEquals(errorTag + ".5." + x, value.getType(), value2.getType()); - assertEquals(errorTag + ".6." + x, value.getLocationURI(), value2.getLocationURI()); - x++; - } - } - - private void compareNatures(int errorTag, String[] natures, String[] natures2) { - // ASSUMPTION: natures and natures2 are non-null - assertEquals(errorTag + ".3.0", natures.length, natures2.length); - for (int i = 0; i < natures.length; i++) { - assertTrue(errorTag + ".3." + (i + 1), natures[i].equals(natures2[i])); - } - } - private void compareProjectDescriptions(int errorTag, ProjectDescription description, ProjectDescription description2) { - assertTrue(errorTag + ".0", description.getName().equals(description2.getName())); + assertThat(description.getName(), is(description2.getName())); String comment = description.getComment(); if (comment == null) { // The old reader previously returned null for an empty comment. We // are changing this so it now returns an empty string. - assertEquals(errorTag + ".1", 0, description2.getComment().length()); + assertThat(description2.getComment(), emptyString()); } else { - assertTrue(errorTag + ".2", description.getComment().equals(description2.getComment())); + assertThat(description.getComment(), is(description2.getComment())); } IProject[] projects = description.getReferencedProjects(); IProject[] projects2 = description2.getReferencedProjects(); - compareProjects(errorTag, projects, projects2); + compareProjects(projects, projects2); ICommand[] commands = description.getBuildSpec(); ICommand[] commands2 = description2.getBuildSpec(); - compareBuildSpecs(errorTag, commands, commands2); + compareBuildSpecs(commands, commands2); String[] natures = description.getNatureIds(); String[] natures2 = description2.getNatureIds(); - compareNatures(errorTag, natures, natures2); + assertThat(natures, is(natures2)); HashMap links = description.getLinks(); HashMap links2 = description2.getLinks(); - compareLinks(errorTag, links, links2); + assertThat(links, is(links2)); } - private void compareProjects(int errorTag, IProject[] projects, IProject[] projects2) { + private void compareProjects(IProject[] projects, IProject[] projects2) { // ASSUMPTION: projects and projects2 are non-null - assertEquals(errorTag + ".1.0", projects.length, projects2.length); + assertThat("different number of projects", projects, arrayWithSize(projects2.length)); for (int i = 0; i < projects.length; i++) { - assertTrue(errorTag + ".1." + (i + 1), projects[i].getName().equals(projects2[i].getName())); + assertThat("names of projects at index " + i + " are different", projects[i].getName(), + is(projects2[i].getName())); } } @@ -328,7 +313,7 @@ public void testConsistentWrite() throws Throwable { String result = buffer.toString(); // order of keys in serialized file should be exactly the same as expected - assertEquals("1.0", expected, result); + assertThat(result, is(expected)); } public void testInvalidProjectDescription1() throws Throwable { @@ -345,7 +330,7 @@ public void testInvalidProjectDescription1() throws Throwable { InputStream stream = new ByteArrayInputStream(invalidProjectDescription.getBytes()); createFileInFileSystem(location, stream); ProjectDescription projDesc = reader.read(location); - assertNull(projDesc); + assertThat(projDesc, nullValue()); } public void testInvalidProjectDescription2() throws Throwable { @@ -356,14 +341,14 @@ public void testInvalidProjectDescription2() throws Throwable { InputStream stream = new ByteArrayInputStream(invalidProjectDescription.getBytes()); createFileInFileSystem(store, stream); ProjectDescription projDesc = readDescription(store); - assertNotNull("2.0", projDesc); - assertNull("2.1", projDesc.getName()); - assertEquals("2.2", 0, projDesc.getComment().length()); - assertNull("2.3", projDesc.getLocationURI()); - assertEquals("2.4", new IProject[0], projDesc.getReferencedProjects()); - assertEquals("2.5", new String[0], projDesc.getNatureIds()); - assertEquals("2.6", new ICommand[0], projDesc.getBuildSpec()); - assertNull("2.7", projDesc.getLinks()); + assertThat(projDesc, not(nullValue())); + assertThat(projDesc.getName(), nullValue()); + assertThat(projDesc.getComment(), emptyString()); + assertThat(projDesc.getLocationURI(), nullValue()); + assertThat(projDesc.getReferencedProjects(), emptyArray()); + assertThat(projDesc.getNatureIds(), emptyArray()); + assertThat(projDesc.getBuildSpec(), emptyArray()); + assertThat(projDesc.getLinks(), nullValue()); } public void testInvalidProjectDescription3() throws Throwable { @@ -375,14 +360,14 @@ public void testInvalidProjectDescription3() throws Throwable { createFileInFileSystem(store, stream); ProjectDescription projDesc = readDescription(store); - assertNotNull("3.0", projDesc); - assertTrue("3.1", projDesc.getName().equals("abc")); - assertEquals("3.2", 0, projDesc.getComment().length()); - assertNull("3.3", projDesc.getLocationURI()); - assertEquals("3.4", new IProject[0], projDesc.getReferencedProjects()); - assertEquals("3.5", new String[0], projDesc.getNatureIds()); - assertEquals("3.6", new ICommand[0], projDesc.getBuildSpec()); - assertNull("3.7", projDesc.getLinks()); + assertThat(projDesc, not(nullValue())); + assertThat(projDesc.getName(), is("abc")); + assertThat(projDesc.getComment(), emptyString()); + assertThat(projDesc.getLocationURI(), nullValue()); + assertThat(projDesc.getReferencedProjects(), emptyArray()); + assertThat(projDesc.getNatureIds(), emptyArray()); + assertThat(projDesc.getBuildSpec(), emptyArray()); + assertThat(projDesc.getLinks(), nullValue()); } public void testInvalidProjectDescription4() throws Throwable { @@ -393,16 +378,16 @@ public void testInvalidProjectDescription4() throws Throwable { InputStream stream = new ByteArrayInputStream(invalidProjectDescription.getBytes()); createFileInFileSystem(store, stream); ProjectDescription projDesc = readDescription(store); - assertNotNull("3.0", projDesc); - assertTrue("3.1", projDesc.getName().equals("abc")); - assertEquals("3.2", 0, projDesc.getComment().length()); - assertNull("3.3", projDesc.getLocationURI()); - assertEquals("3.4", new IProject[0], projDesc.getReferencedProjects()); - assertEquals("3.5", new String[0], projDesc.getNatureIds()); - assertEquals("3.6", new ICommand[0], projDesc.getBuildSpec()); + assertThat(projDesc, not(nullValue())); + assertThat(projDesc.getName(), is("abc")); + assertThat(projDesc.getComment(), emptyString()); + assertThat(projDesc.getLocationURI(), nullValue()); + assertThat(projDesc.getReferencedProjects(), emptyArray()); + assertThat(projDesc.getNatureIds(), emptyArray()); + assertThat(projDesc.getBuildSpec(), emptyArray()); LinkDescription link = projDesc.getLinks().values().iterator().next(); - assertEquals("3.7", IPath.fromOSString("newLink"), link.getProjectRelativePath()); - assertEquals("3.8", PATH_STRING, URIUtil.toPath(link.getLocationURI()).toString()); + assertThat(link.getProjectRelativePath(), is(IPath.fromOSString("newLink"))); + assertThat(URIUtil.toPath(link.getLocationURI()).toString(), is(PATH_STRING)); } /** @@ -422,7 +407,8 @@ public void testLongProjectDescription() throws Throwable { ProjectDescription projDesc = reader.read(location); ensureDoesNotExistInFileSystem(location.toFile()); for (LinkDescription link : projDesc.getLinks().values()) { - assertEquals("1.0." + link.getProjectRelativePath(), LONG_LOCATION_URI, link.getLocationURI()); + assertThat("Unexpected location URI for link with relative path: " + link.getProjectRelativePath(), + link.getLocationURI(), is(LONG_LOCATION_URI)); } } @@ -442,7 +428,8 @@ public void testLongProjectDescriptionURI() throws Throwable { ProjectDescription projDesc = reader.read(location); ensureDoesNotExistInFileSystem(location.toFile()); for (LinkDescription link : projDesc.getLinks().values()) { - assertEquals("1.0." + link.getProjectRelativePath(), LONG_LOCATION_URI, link.getLocationURI()); + assertThat("Unexpected location URI for link with relative path: " + link.getProjectRelativePath(), + link.getLocationURI(), is(LONG_LOCATION_URI)); } } @@ -517,21 +504,21 @@ public void testProjectDescription() throws Throwable { /* test read */ ProjectDescription description2 = readDescription(tempStore); - assertTrue("1.1", description.getName().equals(description2.getName())); - assertEquals("1.2", location, description.getLocationURI()); + assertThat(description.getName(), is(description2.getName())); + assertThat(location, is(description.getLocationURI())); ICommand[] commands2 = description2.getBuildSpec(); - assertEquals("2.00", 2, commands2.length); - assertEquals("2.01", "MyCommand", commands2[0].getBuilderName()); - assertEquals("2.02", "ARGH!", commands2[0].getArguments().get("ArgOne")); - assertEquals("2.03", "2 x ARGH!", commands2[0].getArguments().get("ArgTwo")); - assertEquals("2.04", "", commands2[0].getArguments().get("NullArg")); - assertEquals("2.05", "", commands2[0].getArguments().get("EmptyArg")); - assertEquals("2.06", "MyOtherCommand", commands2[1].getBuilderName()); - assertEquals("2.07", "ARGH!", commands2[1].getArguments().get("ArgOne")); - assertEquals("2.08", "2 x ARGH!", commands2[1].getArguments().get("ArgTwo")); - assertEquals("2.09", "", commands2[0].getArguments().get("NullArg")); - assertEquals("2.10", "", commands2[0].getArguments().get("EmptyArg")); + assertThat(commands2, arrayWithSize(2)); + assertThat(commands2[0].getBuilderName(), is("MyCommand")); + assertThat(commands2[0].getArguments().get("ArgOne"), is("ARGH!")); + assertThat(commands2[0].getArguments().get("ArgTwo"), is("2 x ARGH!")); + assertThat(commands2[0].getArguments().get("NullArg"), emptyString()); + assertThat(commands2[0].getArguments().get("EmptyArg"), emptyString()); + assertThat(commands2[1].getBuilderName(), is("MyOtherCommand")); + assertThat(commands2[1].getArguments().get("ArgOne"), is("ARGH!")); + assertThat(commands2[1].getArguments().get("ArgTwo"), is("2 x ARGH!")); + assertThat(commands2[0].getArguments().get("NullArg"), emptyString()); + assertThat(commands2[0].getArguments().get("EmptyArg"), emptyString()); } public void testProjectDescription2() throws Throwable { @@ -572,22 +559,22 @@ public void testProjectDescription2() throws Throwable { description2 = reader.read(in); } - assertTrue("1.1", description.getName().equals(description2.getName())); - assertTrue("1.2", location.equals(description.getLocationURI())); + assertThat(description.getName(), is(description2.getName())); + assertThat(location, is(description.getLocationURI())); ICommand[] commands2 = description2.getBuildSpec(); - assertEquals("2.00", 1, commands2.length); - assertEquals("2.01", "MyCommand", commands2[0].getBuilderName()); - assertEquals("2.02", "ARGH!", commands2[0].getArguments().get("ArgOne")); + assertThat(commands2, arrayWithSize(1)); + assertThat(commands2[0].getBuilderName(), is("MyCommand")); + assertThat(commands2[0].getArguments().get("ArgOne"), is("ARGH!")); - assertTrue("3.0", description.getComment().equals(description2.getComment())); + assertThat(description.getComment(), is(description2.getComment())); IProject[] ref = description.getReferencedProjects(); IProject[] ref2 = description2.getReferencedProjects(); - assertEquals("4.0", 3, ref2.length); - assertTrue("4.1", ref[0].getName().equals(ref2[0].getName())); - assertTrue("4.2", ref[1].getName().equals(ref2[1].getName())); - assertTrue("4.3", ref[2].getName().equals(ref2[2].getName())); + assertThat(ref2, arrayWithSize(3)); + assertThat(ref[0].getName(), is(ref2[0].getName())); + assertThat(ref[1].getName(), is(ref2[1].getName())); + assertThat(ref[2].getName(), is(ref2[2].getName())); } // see bug 274437 @@ -608,13 +595,13 @@ public void testProjectDescription3() throws Throwable { /* test read */ ProjectDescription description2 = readDescription(tempStore); - assertTrue("1.0", description.getName().equals(description2.getName())); - assertEquals("2.0", location, description.getLocationURI()); + assertThat(description.getName(), is(description2.getName())); + assertThat(description.getLocationURI(), is(location)); ICommand[] commands2 = description2.getBuildSpec(); - assertEquals("3.0", 1, commands2.length); - assertEquals("4.0", "MyCommand", commands2[0].getBuilderName()); - assertEquals("5.0", 0, commands2[0].getArguments().size()); + assertThat(commands2, arrayWithSize(1)); + assertThat(commands2[0].getBuilderName(), is("MyCommand")); + assertThat(commands2[0].getArguments(), anEmptyMap()); } public void testProjectDescriptionWithSpaces() throws Throwable { @@ -633,9 +620,9 @@ public void testProjectDescriptionWithSpaces() throws Throwable { /* test read */ ProjectDescription description2 = readDescription(store); - assertTrue("1.1", description.getName().equals(description2.getName())); - assertEquals("1.2", location, description.getLocationURI()); - assertEquals("1.3", locationWithSpaces, description2.getLinkLocationURI(path)); + assertThat(description.getName(), is(description2.getName())); + assertThat(description.getLocationURI(), is(location)); + assertThat(description2.getLinkLocationURI(path), is(locationWithSpaces)); } protected URI uriFromPortableString(String pathString) { @@ -689,6 +676,6 @@ public void testProjectDescriptionWithFiltersAndNullProject() throws Exception { InputStream stream = new ByteArrayInputStream(projectDescription.getBytes()); createFileInFileSystem(location, stream); ProjectDescription projDesc = reader.read(location); - assertNotNull(projDesc); + assertThat(projDesc, not(nullValue())); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectBuildConfigsTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectBuildConfigsTest.java index e1029f07971..914a97735d5 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectBuildConfigsTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectBuildConfigsTest.java @@ -13,6 +13,10 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.resources; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.is; + import org.eclipse.core.internal.resources.BuildConfiguration; import org.eclipse.core.resources.IBuildConfiguration; import org.eclipse.core.resources.IProject; @@ -51,34 +55,37 @@ public void testBasics() throws CoreException { desc.setBuildConfigs(configs); project.setDescription(desc, getMonitor()); - assertEquals("1.0", new IBuildConfiguration[] {variant0, variant1}, project.getBuildConfigs()); - assertEquals("1.1", variant0, project.getBuildConfig(variantId0)); - assertEquals("1.2", variant1, project.getBuildConfig(variantId1)); + assertThat(project.getBuildConfigs(), arrayContaining(variant0, variant1)); + assertThat(project.getBuildConfig(variantId0), is(variant0)); + assertThat(project.getBuildConfig(variantId1), is(variant1)); // Build configuration names don't contribute to equality - assertTrue("2.0", project.hasBuildConfig(variant0.getName())); - assertTrue("2.1", project.hasBuildConfig(variant1.getName())); - assertFalse("2.2", project.hasBuildConfig(variant2.getName())); - - assertEquals("3.0", variant0, project.getActiveBuildConfig()); + assertThat("project '" + project + "' is missing build config: " + variant0, + project.hasBuildConfig(variant0.getName())); + assertThat("project '" + project + "' is missing build config: " + variant1, + project.hasBuildConfig(variant1.getName())); + assertThat("project '" + project + "' unexpectedly has build config: " + variant2, + !project.hasBuildConfig(variant2.getName())); + + assertThat(project.getActiveBuildConfig(), is(variant0)); desc = project.getDescription(); desc.setActiveBuildConfig(variantId1); project.setDescription(desc, getMonitor()); - assertEquals("3.1", variant1, project.getActiveBuildConfig()); + assertThat(project.getActiveBuildConfig(), is(variant1)); // test that setting the variant to an invalid id has no effect desc.setActiveBuildConfig(variantId2); - assertEquals("3.2", variant1, project.getActiveBuildConfig()); + assertThat(project.getActiveBuildConfig(), is(variant1)); IBuildConfiguration variant = project.getBuildConfigs()[0]; - assertEquals("4.0", project, variant.getProject()); - assertEquals("4.1", variantId0, variant.getName()); + assertThat(variant.getProject(), is(project)); + assertThat(variant.getName(), is(variantId0)); } public void testDuplicates() throws CoreException { IProjectDescription desc = project.getDescription(); desc.setBuildConfigs(new String[] {variantId0, variantId1, variantId0}); project.setDescription(desc, getMonitor()); - assertEquals("1.0", new IBuildConfiguration[] {variant0, variant1}, project.getBuildConfigs()); + assertThat(project.getBuildConfigs(), arrayContaining(variant0, variant1)); } public void testDefaultVariant() throws CoreException { @@ -86,14 +93,15 @@ public void testDefaultVariant() throws CoreException { desc.setBuildConfigs(new String[] {}); project.setDescription(desc, getMonitor()); - assertEquals("1.0", new IBuildConfiguration[] {defaultVariant}, project.getBuildConfigs()); - assertTrue("1.1", project.hasBuildConfig(defaultVariant.getName())); + assertThat(project.getBuildConfigs(), arrayContaining(defaultVariant)); + assertThat("project '" + project + "' is missing build config: " + defaultVariant, + project.hasBuildConfig(defaultVariant.getName())); - assertEquals("2.0", defaultVariant, project.getActiveBuildConfig()); + assertThat(project.getActiveBuildConfig(), is(defaultVariant)); desc = project.getDescription(); desc.setActiveBuildConfig(IBuildConfiguration.DEFAULT_CONFIG_NAME); project.setDescription(desc, getMonitor()); - assertEquals("2.1", defaultVariant, project.getActiveBuildConfig()); + assertThat(project.getActiveBuildConfig(), is(defaultVariant)); } public void testRemoveActiveVariant() throws CoreException { @@ -101,16 +109,16 @@ public void testRemoveActiveVariant() throws CoreException { desc.setBuildConfigs(new String[0]); desc.setBuildConfigs(new String[] {variant0.getName(), variant1.getName()}); project.setDescription(desc, getMonitor()); - assertEquals("1.0", variant0, project.getActiveBuildConfig()); + assertThat(project.getActiveBuildConfig(), is(variant0)); desc.setBuildConfigs(new String[] {variant0.getName(), variant2.getName()}); project.setDescription(desc, getMonitor()); - assertEquals("2.0", variant0, project.getActiveBuildConfig()); + assertThat(project.getActiveBuildConfig(), is(variant0)); desc = project.getDescription(); desc.setActiveBuildConfig(variantId2); project.setDescription(desc, getMonitor()); desc.setBuildConfigs(new String[] {variant0.getName(), variant1.getName()}); project.setDescription(desc, getMonitor()); - assertEquals("3.0", variant0, project.getActiveBuildConfig()); + assertThat(project.getActiveBuildConfig(), is(variant0)); } /** @@ -129,12 +137,12 @@ public void testProjectMove() throws CoreException { project.move(desc, false, getMonitor()); IProject newProject = getWorkspace().getRoot().getProject(newProjectName); - assertTrue("1.0", newProject.exists()); + assertThat("project does not exist: " + newProject, newProject.exists()); IBuildConfiguration[] newConfigs = newProject.getBuildConfigs(); for (int i = 0; i < configs.length; i++) { - assertEquals("2." + i * 3, newProject, newConfigs[i].getProject()); - assertEquals("2." + i * 3 + 1, configs[i].getName(), newConfigs[i].getName()); + assertThat("unexpected project at index " + i, newConfigs[i].getProject(), is(newProject)); + assertThat("unexpected project name at index " + i, newConfigs[i].getName(), is(configs[i].getName())); } } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java index f917ac9e3bf..dc18552e4b1 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java @@ -13,6 +13,11 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.resources; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.emptyArray; +import static org.hamcrest.Matchers.is; + import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -38,9 +43,6 @@ public class ProjectDynamicReferencesTest extends ResourceTest { private static final String PROJECT_0_NAME = "ProjectDynamicReferencesTest_p0"; - private static final IProject[] EMPTY_PROJECTS = new IProject[0]; - private static final IBuildConfiguration[] EMPTY_BUILD_CONFIGURATIONS = new IBuildConfiguration[0]; - private IProject project0; private IProject project1; private IProject project2; @@ -72,56 +74,55 @@ protected void tearDown() throws Exception { } public void testReferencedProjects() throws CoreException { - assertEquals("Project0 must not have referenced projects", EMPTY_PROJECTS, project0.getReferencedProjects()); - assertEquals("Project1 must not have referenced projects", EMPTY_PROJECTS, project1.getReferencedProjects()); - assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + assertThat("Project0 must not have referenced projects", project0.getReferencedProjects(), emptyArray()); + assertThat("Project1 must not have referenced projects", project1.getReferencedProjects(), emptyArray()); + assertThat("Project2 must not have referenced projects", project2.getReferencedProjects(), emptyArray()); DynamicReferenceProvider.addReference(project0, project1); - assertEquals("Project0 must not have referenced projects", EMPTY_PROJECTS, project0.getReferencedProjects()); - assertEquals("Project1 must not have referenced projects", EMPTY_PROJECTS, project1.getReferencedProjects()); - assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + assertThat("Project0 must not have referenced projects", project0.getReferencedProjects(), emptyArray()); + assertThat("Project1 must not have referenced projects", project1.getReferencedProjects(), emptyArray()); + assertThat("Project2 must not have referenced projects", project2.getReferencedProjects(), emptyArray()); clearCache(); - assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); - assertEquals("Project1 must not have referenced projects", EMPTY_PROJECTS, project1.getReferencedProjects()); - assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + assertThat("Project0 must reference Project1", project0.getReferencedProjects(), arrayContaining(project1)); + assertThat("Project1 must not have referenced projects", project1.getReferencedProjects(), emptyArray()); + assertThat("Project2 must not have referenced projects", project2.getReferencedProjects(), emptyArray()); DynamicReferenceProvider.addReference(project1, project2); - assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); - assertEquals("Project1 must not have referenced projects", EMPTY_PROJECTS, project1.getReferencedProjects()); - assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + assertThat("Project0 must reference Project1", project0.getReferencedProjects(), arrayContaining(project1)); + assertThat("Project1 must not have referenced projects", project1.getReferencedProjects(), emptyArray()); + assertThat("Project2 must not have referenced projects", project2.getReferencedProjects(), emptyArray()); clearCache(); - assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); - assertEquals("Project1 must reference Project2", new IProject[] { project2 }, project1.getReferencedProjects()); - assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + assertThat("Project0 must reference Project1", project0.getReferencedProjects(), arrayContaining(project1)); + assertThat("Project1 must reference Project2", project1.getReferencedProjects(), arrayContaining(project2)); + assertThat("Project2 must not have referenced projects", project2.getReferencedProjects(), emptyArray()); DynamicReferenceProvider.addReference(project0, project2); - assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); - assertEquals("Project1 must reference Project2", new IProject[] { project2 }, project1.getReferencedProjects()); - assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + assertThat("Project0 must reference Project1", project0.getReferencedProjects(), arrayContaining(project1)); + assertThat("Project1 must reference Project2", project1.getReferencedProjects(), arrayContaining(project2)); + assertThat("Project2 must not have referenced projects", project2.getReferencedProjects(), emptyArray()); clearCache(); - assertEquals("Project0 must reference Project1 and Project2", new IProject[] { project1, project2 }, - project0.getReferencedProjects()); - assertEquals("Project1 must reference Project2", new IProject[] { project2 }, - project1.getReferencedProjects()); - assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + assertThat("Project0 must reference Project1 and Project2", project0.getReferencedProjects(), + arrayContaining(project1, project2)); + assertThat("Project1 must reference Project2", project1.getReferencedProjects(), arrayContaining(project2)); + assertThat("Project2 must not have referenced projects", project2.getReferencedProjects(), emptyArray()); } public void testReferencedBuildConfigs() throws CoreException { - assertEquals("Project0 must not have referenced projects", EMPTY_BUILD_CONFIGURATIONS, - project0.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false)); - assertEquals("Project1 must not have referenced projects", EMPTY_BUILD_CONFIGURATIONS, - project1.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false)); - assertEquals("Project2 must not have referenced projects", EMPTY_BUILD_CONFIGURATIONS, - project2.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false)); + assertThat("Project0 must not have referenced projects", + project0.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false), emptyArray()); + assertThat("Project1 must not have referenced projects", + project1.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false), emptyArray()); + assertThat("Project2 must not have referenced projects", + project2.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false), emptyArray()); DynamicReferenceProvider.addReference(project0, project1); DynamicReferenceProvider.addReference(project1, project2); @@ -130,64 +131,64 @@ public void testReferencedBuildConfigs() throws CoreException { IBuildConfiguration buildConfigProject1 = project1.getBuildConfig(IBuildConfiguration.DEFAULT_CONFIG_NAME); IBuildConfiguration buildConfigProject2 = project2.getBuildConfig(IBuildConfiguration.DEFAULT_CONFIG_NAME); - assertEquals("Build configuration of Project0 must reference build configuration of project1 and project2", - new IBuildConfiguration[] { buildConfigProject1, buildConfigProject2 }, - project0.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false)); - assertEquals("Build configuration of Project1 must reference build configuration of Project2", - new IBuildConfiguration[] { buildConfigProject2 }, - project1.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false)); - assertEquals("Project2 must not have referenced projects", EMPTY_BUILD_CONFIGURATIONS, - project2.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false)); + assertThat("Build configuration of Project0 must reference build configuration of project1 and project2", + project0.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false), + arrayContaining(buildConfigProject1, buildConfigProject2)); + assertThat("Build configuration of Project1 must reference build configuration of Project2", + project1.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false), + arrayContaining(buildConfigProject2)); + assertThat("Project2 must not have referenced projects", + project2.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false), emptyArray()); } public void testReferencingProjects() throws CoreException { - assertEquals("Project0 must not have referencing projects", EMPTY_PROJECTS, project0.getReferencingProjects()); - assertEquals("Project1 must not have referencing projects", EMPTY_PROJECTS, project1.getReferencingProjects()); - assertEquals("Project2 must not have referencing projects", EMPTY_PROJECTS, project2.getReferencingProjects()); + assertThat("Project0 must not have referencing projects", project0.getReferencingProjects(), emptyArray()); + assertThat("Project1 must not have referencing projects", project1.getReferencingProjects(), emptyArray()); + assertThat("Project2 must not have referencing projects", project2.getReferencingProjects(), emptyArray()); DynamicReferenceProvider.addReference(project0, project1); - assertEquals("Project0 must not have referencing projects", EMPTY_PROJECTS, project0.getReferencingProjects()); - assertEquals("Project1 must not have referencing projects", EMPTY_PROJECTS, project1.getReferencingProjects()); - assertEquals("Project2 must not have referencing projects", EMPTY_PROJECTS, project2.getReferencingProjects()); + assertThat("Project0 must not have referencing projects", project0.getReferencingProjects(), emptyArray()); + assertThat("Project1 must not have referencing projects", project1.getReferencingProjects(), emptyArray()); + assertThat("Project2 must not have referencing projects", project2.getReferencingProjects(), emptyArray()); clearCache(); - assertEquals("Project0 must not have referencing projects", EMPTY_PROJECTS, project0.getReferencingProjects()); - assertEquals("Project1 must be referenced by Project0", new IProject[] { project0 }, - project1.getReferencingProjects()); - assertEquals("Project2 must not have referencing projects", EMPTY_PROJECTS, project2.getReferencingProjects()); + assertThat("Project0 must not have referencing projects", project0.getReferencingProjects(), emptyArray()); + assertThat("Project1 must be referenced by Project0", project1.getReferencingProjects(), + arrayContaining(project0)); + assertThat("Project2 must not have referencing projects", project2.getReferencingProjects(), emptyArray()); DynamicReferenceProvider.addReference(project1, project2); - assertEquals("Project0 must not have referencing projects", EMPTY_PROJECTS, project0.getReferencingProjects()); - assertEquals("Project1 must must be referenced by Project0", new IProject[] { project0 }, - project1.getReferencingProjects()); - assertEquals("Project2 must not have referencing projects", EMPTY_PROJECTS, project2.getReferencingProjects()); + assertThat("Project0 must not have referencing projects", project0.getReferencingProjects(), emptyArray()); + assertThat("Project1 must must be referenced by Project0", project1.getReferencingProjects(), + arrayContaining(project0)); + assertThat("Project2 must not have referencing projects", project2.getReferencingProjects(), emptyArray()); clearCache(); - assertEquals("Project0 must not have referencing projects", EMPTY_PROJECTS, project0.getReferencingProjects()); - assertEquals("Project1 must be referenced by Project0", new IProject[] { project0 }, - project1.getReferencingProjects()); - assertEquals("Project2 must be referenced by Project1", new IProject[] { project1 }, - project2.getReferencingProjects()); + assertThat("Project0 must not have referencing projects", project0.getReferencingProjects(), emptyArray()); + assertThat("Project1 must be referenced by Project0", project1.getReferencingProjects(), + arrayContaining(project0)); + assertThat("Project2 must be referenced by Project1", project2.getReferencingProjects(), + arrayContaining(project1)); DynamicReferenceProvider.addReference(project0, project2); - assertEquals("Project0 must not have referencing projects", EMPTY_PROJECTS, project0.getReferencingProjects()); - assertEquals("Project1 must be referenced by Project0", new IProject[] { project0 }, - project1.getReferencingProjects()); - assertEquals("Project2 must be referenced by Project1", new IProject[] { project1 }, - project2.getReferencingProjects()); + assertThat("Project0 must not have referencing projects", project0.getReferencingProjects(), emptyArray()); + assertThat("Project1 must be referenced by Project0", project1.getReferencingProjects(), + arrayContaining(project0)); + assertThat("Project2 must be referenced by Project1", project2.getReferencingProjects(), + arrayContaining(project1)); clearCache(); - assertEquals("Project0 must not have referencing projects", EMPTY_PROJECTS, project0.getReferencingProjects()); - assertEquals("Project1 must be referenced by Project0", new IProject[] { project0 }, - project1.getReferencingProjects()); - assertEquals("Project2 must be referenced by Project0 and Project1", new IProject[] { project0, project1 }, - project2.getReferencingProjects()); + assertThat("Project0 must not have referencing projects", project0.getReferencingProjects(), emptyArray()); + assertThat("Project1 must be referenced by Project0", project1.getReferencingProjects(), + arrayContaining(project0)); + assertThat("Project2 must be referenced by Project0 and Project1", project2.getReferencingProjects(), + arrayContaining(project0, project1)); } public void testComputeProjectOrder() throws CoreException { @@ -195,8 +196,9 @@ public void testComputeProjectOrder() throws CoreException { ProjectOrder projectOrder = getWorkspace().computeProjectOrder(allProjects); - assertEquals("Build order not defined, must return projects in default order", allProjects, projectOrder.projects); - assertFalse("No cycles", projectOrder.hasCycles); + assertThat("Build order not defined, must return projects in default order", projectOrder.projects, + is(allProjects)); + assertThat("Project order should not have cycles: " + projectOrder, !projectOrder.hasCycles); DynamicReferenceProvider.addReference(project0, project1); DynamicReferenceProvider.addReference(project1, project2); @@ -204,9 +206,9 @@ public void testComputeProjectOrder() throws CoreException { projectOrder = getWorkspace().computeProjectOrder(allProjects); - assertEquals("Build order must be Project2, Project1, Project0", - new IProject[] { project2, project1, project0 }, projectOrder.projects); - assertFalse("No cycles", projectOrder.hasCycles); + assertThat("Build order must be Project2, Project1, Project0", projectOrder.projects, + arrayContaining(project2, project1, project0)); + assertThat("Project order should not have cycles: " + projectOrder, !projectOrder.hasCycles); DynamicReferenceProvider.clear(); DynamicReferenceProvider.addReference(project1, project0); @@ -215,9 +217,9 @@ public void testComputeProjectOrder() throws CoreException { projectOrder = getWorkspace().computeProjectOrder(allProjects); - assertEquals("Build order must be Project2, Project0, Project1", - new IProject[] { project2, project0, project1 }, projectOrder.projects); - assertFalse("No cycles", projectOrder.hasCycles); + assertThat("Build order must be Project2, Project0, Project1", + projectOrder.projects, arrayContaining(project2, project0, project1)); + assertThat("Project order should not have cycles: " + projectOrder, !projectOrder.hasCycles); } public void testBug543776() throws Exception { @@ -229,13 +231,14 @@ public void testBug543776() throws Exception { project0.create(null); project0.open(null); - assertEquals(PROJECT_0_NAME, project0.getName()); - assertEquals("anotherName", project0.getDescription().getName()); + assertThat(project0.getName(), is(PROJECT_0_NAME)); + assertThat(project0.getDescription().getName(), is("anotherName")); DynamicReferenceProvider.addReference(project0, project1); clearCache(); - assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); + assertThat("Project0 must reference Project1", project0.getReferencedProjects(), + arrayContaining(project1)); } private void clearCache() { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectReferencesTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectReferencesTest.java index 1015b76a084..97233e5e2dd 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectReferencesTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectReferencesTest.java @@ -13,6 +13,10 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.resources; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.emptyArray; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThrows; import org.eclipse.core.internal.resources.BuildConfiguration; @@ -82,14 +86,16 @@ private void setUpVariants(IProject project) throws CoreException { public void testAddReferencesToNonExistantConfigs() throws CoreException { IProjectDescription desc = project0.getDescription(); - assertFalse("1.0", project0.hasBuildConfig(nonExistentBC)); + assertThat("project '" + project0 + "' has unexpected build config: " + nonExistentBC, + !project0.hasBuildConfig(nonExistentBC)); desc.setBuildConfigReferences(nonExistentBC, new IBuildConfiguration[] {project1v0}); project0.setDescription(desc, getMonitor()); - assertFalse("2.0", project0.hasBuildConfig(nonExistentBC)); + assertThat("project '" + project0 + "' has unexpected build config: " + nonExistentBC, + !project0.hasBuildConfig(nonExistentBC)); - assertEquals("3.1", new IBuildConfiguration[0], desc.getBuildConfigReferences(nonExistentBC)); + assertThat(desc.getBuildConfigReferences(nonExistentBC), emptyArray()); assertThrows(CoreException.class, () -> project0.getReferencedBuildConfigs(nonExistentBC, true)); } @@ -111,29 +117,29 @@ public void testChangingBuildConfigurations() throws CoreException { // Check build configa desc = project0.getDescription(); - assertEquals("1.0", refs, desc.getBuildConfigReferences(project0v0.getName())); - assertEquals("1.1", refs2, desc.getBuildConfigReferences(project0v1.getName())); + assertThat(desc.getBuildConfigReferences(project0v0.getName()), is(refs)); + assertThat(desc.getBuildConfigReferences(project0v1.getName()), is(refs2)); // Resetting the build configs doesn't change anything desc.setBuildConfigs(new String[] {project0v0.getName(), project0v1.getName()}); project0.setDescription(desc, getMonitor()); desc = project0.getDescription(); - assertEquals("2.0", refs, desc.getBuildConfigReferences(project0v0.getName())); - assertEquals("2.1", refs2, desc.getBuildConfigReferences(project0v1.getName())); + assertThat(desc.getBuildConfigReferences(project0v0.getName()), is(refs)); + assertThat(desc.getBuildConfigReferences(project0v1.getName()), is(refs2)); // Removing a build configuration removes the references desc.setBuildConfigs(new String[] {project0v0.getName()}); project0.setDescription(desc, getMonitor()); desc = project0.getDescription(); - assertEquals("3.0", refs, desc.getBuildConfigReferences(project0v0.getName())); - assertEquals("3.1", new IBuildConfiguration[0], desc.getBuildConfigReferences(project0v1.getName())); + assertThat(desc.getBuildConfigReferences(project0v0.getName()), is(refs)); + assertThat(desc.getBuildConfigReferences(project0v1.getName()), emptyArray()); // Re-adding a build configuration doesn't make references re-appear desc.setBuildConfigs(new String[] {project0v0.getName()}); project0.setDescription(desc, getMonitor()); desc = project0.getDescription(); - assertEquals("4.0", refs, desc.getBuildConfigReferences(project0v0.getName())); - assertEquals("4.1", new IBuildConfiguration[0], desc.getBuildConfigReferences(project0v1.getName())); + assertThat(desc.getBuildConfigReferences(project0v0.getName()), is(refs)); + assertThat(desc.getBuildConfigReferences(project0v1.getName()), emptyArray()); } /** @@ -148,11 +154,13 @@ public void testMixedProjectAndBuildConfigRefs() throws CoreException { // Check getters desc = project0.getDescription(); - assertEquals("1.1", new IProject[] {project1, project3}, desc.getDynamicReferences()); - assertEquals("1.2", new IBuildConfiguration[] {}, desc.getBuildConfigReferences(project0v0.getName())); - assertEquals("1.3", new IBuildConfiguration[] {}, desc.getBuildConfigReferences(project0v1.getName())); - assertEquals("1.4", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project3.getActiveBuildConfig()}, project0.getReferencedBuildConfigs(project0v0.getName(), false)); - assertEquals("1.5", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project3.getActiveBuildConfig()}, project0.getReferencedBuildConfigs(project0v1.getName(), false)); + assertThat(desc.getDynamicReferences(), arrayContaining(project1, project3)); + assertThat(desc.getBuildConfigReferences(project0v0.getName()), emptyArray()); + assertThat(desc.getBuildConfigReferences(project0v1.getName()), emptyArray()); + assertThat(project0.getReferencedBuildConfigs(project0v0.getName(), false), + arrayContaining(project1.getActiveBuildConfig(), project3.getActiveBuildConfig())); + assertThat(project0.getReferencedBuildConfigs(project0v1.getName(), false), + arrayContaining(project1.getActiveBuildConfig(), project3.getActiveBuildConfig())); // Now set dynamic references on config1 desc.setBuildConfigReferences(project0v0.getName(), new IBuildConfiguration[] {project3v1, project2v0, project1v0}); @@ -161,11 +169,14 @@ public void testMixedProjectAndBuildConfigRefs() throws CoreException { // Check references // This is deterministic as config0 is listed first, so we expect its config order to trump cofig1's desc = project0.getDescription(); - assertEquals("2.1", new IProject[] {project1, project3}, desc.getDynamicReferences()); - assertEquals("2.2", new IBuildConfiguration[] {project3v1, project2v0, project1v0}, desc.getBuildConfigReferences(project0v0.getName())); + assertThat(desc.getDynamicReferences(), arrayContaining(project1, project3)); + assertThat(desc.getBuildConfigReferences(project0v0.getName()), + arrayContaining(project3v1, project2v0, project1v0)); // Now at the project leve - assertEquals("2.3", new IBuildConfiguration[] {project3v1, project2v0, project1v0, project3v0}, project0.getReferencedBuildConfigs(project0v0.getName(), false)); - assertEquals("2.4", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project3.getActiveBuildConfig()}, project0.getReferencedBuildConfigs(project0v1.getName(), false)); + assertThat(project0.getReferencedBuildConfigs(project0v0.getName(), false), + arrayContaining(project3v1, project2v0, project1v0, project3v0)); + assertThat(project0.getReferencedBuildConfigs(project0v1.getName(), false), + arrayContaining(project1.getActiveBuildConfig(), project3.getActiveBuildConfig())); } public void testSetAndGetProjectReferences() throws CoreException { @@ -192,13 +203,14 @@ public void testSetAndGetProjectReferences() throws CoreException { // Test getters desc = project0.getDescription(); - assertEquals("1.0", new IProject[] {project3, project1}, desc.getReferencedProjects()); - assertEquals("1.1", new IProject[] {project1, project2}, desc.getDynamicReferences()); - assertEquals("1.3", new IBuildConfiguration[] {}, desc.getBuildConfigReferences(bc0)); - - assertEquals("2.0", new IProject[] {project3, project1, project2}, project0.getReferencedProjects()); - assertEquals("2.1", new IProject[] {project1, project3}, project0.getReferencingProjects()); - assertEquals("2.2", new IBuildConfiguration[] {project3v0, project1v0, project2v0}, project0.getReferencedBuildConfigs(project0v0.getName(), true)); + assertThat(desc.getReferencedProjects(), arrayContaining(project3, project1)); + assertThat(desc.getDynamicReferences(), arrayContaining(project1, project2)); + assertThat(desc.getBuildConfigReferences(bc0), emptyArray()); + + assertThat(project0.getReferencedProjects(), arrayContaining(project3, project1, project2)); + assertThat(project0.getReferencingProjects(), arrayContaining(project1, project3)); + assertThat(project0.getReferencedBuildConfigs(project0v0.getName(), true), + arrayContaining(project3v0, project1v0, project2v0)); } public void testSetAndGetProjectConfigReferences() throws CoreException { @@ -226,15 +238,17 @@ public void testSetAndGetProjectConfigReferences() throws CoreException { // Check getters desc = project0.getDescription(); - assertEquals("1.0", new IProject[] {project1}, desc.getReferencedProjects()); - assertEquals("1.1", new IProject[] {project3}, desc.getDynamicReferences()); - assertEquals("1.3", new IBuildConfiguration[] {project2v0, project1v0}, desc.getBuildConfigReferences(bc0)); - assertEquals("1.5", new IBuildConfiguration[] {project2v0}, desc.getBuildConfigReferences(bc1)); - - assertEquals("2.0", new IProject[] {project2, project1, project3}, project0.getReferencedProjects()); - assertEquals("2.1", new IProject[] {project1, project3}, project0.getReferencingProjects()); - assertEquals("2.2", new IBuildConfiguration[] {project2v0, project1v0, project3.getActiveBuildConfig()}, project0.getReferencedBuildConfigs(project0v0.getName(), true)); - assertEquals("2.3", new IBuildConfiguration[] {project2v0, project1.getActiveBuildConfig(), project3.getActiveBuildConfig()}, project0.getReferencedBuildConfigs(project0v1.getName(), true)); + assertThat(desc.getReferencedProjects(), arrayContaining(project1)); + assertThat(desc.getDynamicReferences(), arrayContaining(project3)); + assertThat(desc.getBuildConfigReferences(bc0), arrayContaining(project2v0, project1v0)); + assertThat(desc.getBuildConfigReferences(bc1), arrayContaining(project2v0)); + + assertThat(project0.getReferencedProjects(), arrayContaining(project2, project1, project3)); + assertThat(project0.getReferencingProjects(), arrayContaining(project1, project3)); + assertThat(project0.getReferencedBuildConfigs(project0v0.getName(), true), + arrayContaining(project2v0, project1v0, project3.getActiveBuildConfig())); + assertThat(project0.getReferencedBuildConfigs(project0v1.getName(), true), arrayContaining( + project2v0, project1.getActiveBuildConfig(), project3.getActiveBuildConfig())); } public void testReferencesToActiveConfigs() throws CoreException { @@ -242,7 +256,8 @@ public void testReferencesToActiveConfigs() throws CoreException { desc.setBuildConfigReferences(bc0, new IBuildConfiguration[] {getRef(project1)}); project0.setDescription(desc, getMonitor()); - assertEquals("1.0", new IBuildConfiguration[] {getRef(project1)}, desc.getBuildConfigReferences(bc0)); - assertEquals("1.1", new IBuildConfiguration[] {project1v0}, project0.getReferencedBuildConfigs(project0v0.getName(), true)); + assertThat(desc.getBuildConfigReferences(bc0), arrayContaining(getRef(project1))); + assertThat(project0.getReferencedBuildConfigs(project0v0.getName(), true), + arrayContaining(project1v0)); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java index d88ecfdb7b6..d41d29e979b 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java @@ -14,6 +14,9 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.resources; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -64,7 +67,7 @@ public void testDefaults() throws CoreException { for (String property : descriptionProperties) { assertTrue("2.0 - Description property is not default: " + property, defaultPropertiesList.contains(property)); } - + setDefaultWorkspaceDescription(); } @@ -267,7 +270,7 @@ public void assertEquals(String message, IWorkspaceDescription description, Pref */ public void assertEquals(String message, IWorkspaceDescription description1, IWorkspaceDescription description2) throws ComparisonFailure { assertEquals(message + " - 1", description1.isAutoBuilding(), description2.isAutoBuilding()); - assertEquals(message + " - 2", description1.getBuildOrder(), description2.getBuildOrder()); + assertThat(message + " - 2", description1.getBuildOrder(), is(description2.getBuildOrder())); assertEquals(message + " - 3", WorkspacePreferences.convertStringArraytoString(description1.getBuildOrder()), WorkspacePreferences.convertStringArraytoString(description2.getBuildOrder())); assertEquals(message + " - 4", description1.isApplyFileStatePolicy(), description2.isApplyFileStatePolicy()); assertEquals(message + " - 5", description1.getFileStateLongevity(), description2.getFileStateLongevity()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java index 1086f3d2f6d..eb3bde7a42b 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java @@ -21,6 +21,8 @@ import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_WATER; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.getInvalidNatureSets; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.getValidNatureSets; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThrows; import java.io.ByteArrayInputStream; @@ -206,11 +208,15 @@ public void testSimpleNature() throws CoreException { String[][] invalid = getInvalidNatureSets(); for (int i = 0; i < invalid.length; i++) { setNatures("invalid: " + i, project, invalid[i], true); - assertTrue("2.0", project.hasNature(NATURE_SIMPLE)); - assertTrue("2.1", !project.hasNature(NATURE_EARTH)); - assertTrue("2.2", project.isNatureEnabled(NATURE_SIMPLE)); - assertTrue("2.3", !project.isNatureEnabled(NATURE_EARTH)); - assertEquals("2.4", project.getDescription().getNatureIds(), currentSet); + assertThat("project '" + project + "' is expected to have nature: " + NATURE_SIMPLE, + project.hasNature(NATURE_SIMPLE)); + assertThat("project '" + project + "' is not expected to have nature: " + NATURE_EARTH, + !project.hasNature(NATURE_EARTH)); + assertThat("project '" + project + "' is expected to have nature enabled: " + NATURE_SIMPLE, + project.isNatureEnabled(NATURE_SIMPLE)); + assertThat("project '" + project + "' is not expected to have nature enabled: " + NATURE_EARTH, + !project.isNatureEnabled(NATURE_EARTH)); + assertThat(currentSet, is(project.getDescription().getNatureIds())); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/ProjectDescriptionDynamicTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/ProjectDescriptionDynamicTest.java index 912130574ed..662f3e65101 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/ProjectDescriptionDynamicTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/ProjectDescriptionDynamicTest.java @@ -13,8 +13,16 @@ ******************************************************************************/ package org.eclipse.core.tests.resources.session; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.emptyArray; +import static org.hamcrest.Matchers.is; + import junit.framework.Test; -import org.eclipse.core.resources.*; +import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.tests.resources.AutomatedResourceTests; import org.eclipse.core.tests.resources.WorkspaceSessionTest; import org.eclipse.core.tests.session.WorkspaceSessionTestSuite; @@ -89,10 +97,10 @@ public void test1() throws Exception { * - project level references still exist */ public void test2() throws Exception { - assertTrue("1.0", proj.isAccessible()); - assertEquals("1.1", dynRefs, proj.getDescription().getDynamicReferences()); - assertEquals("1.2", configs, proj.getBuildConfigs()); - assertEquals("1.3", configs[0], proj.getActiveBuildConfig()); + assertThat("project is unexpectedly not accessible: " + proj, proj.isAccessible()); + assertThat(dynRefs, is(proj.getDescription().getDynamicReferences())); + assertThat(proj.getBuildConfigs(), is(configs)); + assertThat(proj.getActiveBuildConfig(), is(configs[0])); // set build configuration level dynamic references on the project IProjectDescription desc = proj.getDescription(); @@ -111,20 +119,20 @@ public void test2() throws Exception { * - Build config references are correct */ public void test3() throws Exception { - assertTrue("2.0", proj.isAccessible()); - assertEquals("2.1", configs[1], proj.getActiveBuildConfig()); + assertThat("project is unexpectedly not accessible: " + proj, proj.isAccessible()); + assertThat(proj.getActiveBuildConfig(), is(configs[1])); // At description dynamic refs are what was set - assertEquals("2.2", dynRefs, proj.getDescription().getDynamicReferences()); + assertThat(proj.getDescription().getDynamicReferences(), is(dynRefs)); // At project all references are union of build configuration and project references - assertEquals("2.4", configRefsProjects, proj.getReferencedProjects()); + assertThat(proj.getReferencedProjects(), is(configRefsProjects)); // At the description level, dynamic config references match what was set. - assertEquals("2.5", configRefs, proj.getDescription().getBuildConfigReferences(configs[1].getName())); + assertThat(proj.getDescription().getBuildConfigReferences(configs[1].getName()), is(configRefs)); // At the project level, references are the union of project and build configuration level references IBuildConfiguration[] refs = new IBuildConfiguration[] {configRefs[0], configRefs[1], configRefs[2], getRef(dynRefs[0]), getRef(dynRefs[1])}; - assertEquals("2.6", refs, proj.getReferencedBuildConfigs(configs[1].getName(), true)); + assertThat(proj.getReferencedBuildConfigs(configs[1].getName(), true), is(refs)); // No other projects exist, so check references are empty if we want to filter empty projects - assertEquals("2.7", new IBuildConfiguration[0], proj.getReferencedBuildConfigs(configs[1].getName(), false)); + assertThat(proj.getReferencedBuildConfigs(configs[1].getName(), false), emptyArray()); } public static Test suite() { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceDescriptionTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceDescriptionTest.java index 8b2cb08cd9d..5f3ae0a5083 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceDescriptionTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceDescriptionTest.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + import junit.framework.Test; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceDescription; @@ -29,7 +32,7 @@ public class WorkspaceDescriptionTest extends WorkspaceSessionTest { private static final String[] BUILD_ORDER = new String[] {"Foo"}; private static final boolean APPLY_POLICY = false; - private static final int STATE_LONGEVITY = 123456; + private static final long STATE_LONGEVITY = 123456; private static final int MAX_STATES = 244; private static final long MAX_FILE_SIZE = 1024 * 53; private static final long SNAPSHOT_INTERVAL = 4321; @@ -51,13 +54,13 @@ public void test1() throws CoreException { public void test2() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceDescription desc = workspace.getDescription(); - assertTrue("2.0", !desc.isAutoBuilding()); - assertEquals("2.1", BUILD_ORDER, desc.getBuildOrder()); - assertEquals("2.2", APPLY_POLICY, desc.isApplyFileStatePolicy()); - assertEquals("2.3", STATE_LONGEVITY, desc.getFileStateLongevity()); - assertEquals("2.4", MAX_STATES, desc.getMaxFileStates()); - assertEquals("2.5", MAX_FILE_SIZE, desc.getMaxFileStateSize()); - assertEquals("2.6", SNAPSHOT_INTERVAL, desc.getSnapshotInterval()); + assertThat("auto building is expected to be disabled: " + desc, !desc.isAutoBuilding()); + assertThat("unexpected buildorder in: " + desc, desc.getBuildOrder(), is(BUILD_ORDER)); + assertThat("unexpected apply file state policy in: " + desc, desc.isApplyFileStatePolicy(), is(APPLY_POLICY)); + assertThat("unexpected longevity in: " + desc, desc.getFileStateLongevity(), is(STATE_LONGEVITY)); + assertThat("unexpected max states in: " + desc, desc.getMaxFileStates(), is(MAX_STATES)); + assertThat("unexpected max file size in: " + desc, desc.getMaxFileStateSize(), is(MAX_FILE_SIZE)); + assertThat("unexpected snapshot interval in: " + desc, desc.getSnapshotInterval(), is(SNAPSHOT_INTERVAL)); } public static Test suite() {