From cb70b67cf1cee32848ec69556ab113e8bd1b4ea4 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sat, 9 Dec 2023 09:25:20 +0100 Subject: [PATCH] Apply 'Convert StringBuffer to StringBuilder' clean-up to p2 tests --- .../equinox/p2/tests/StringBufferStream.java | 8 ++--- .../CompositeArtifactRepositoryTest.java | 2 +- .../director/DirectorApplicationTest.java | 30 +++++++++---------- .../p2/tests/generator/GeneratorTests.java | 6 ++-- .../CompositeMetadataRepositoryTest.java | 2 +- .../mirror/ArtifactMirrorApplicationTest.java | 4 +-- .../tests/mirror/MirrorApplicationTest.java | 4 +-- .../NewMirrorApplicationArtifactTest.java | 10 +++---- .../publisher/GeneralPublisherTests.java | 4 +-- .../actions/CategoryPublisherTest.java | 4 +-- .../dropins/AbstractReconcilerTest.java | 2 +- .../p2/tests/updatesite/UpdateSiteTest.java | 8 ++--- 12 files changed, 42 insertions(+), 42 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/StringBufferStream.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/StringBufferStream.java index 06a5e830d9..fe4f62717f 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/StringBufferStream.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/StringBufferStream.java @@ -17,17 +17,17 @@ import java.io.OutputStream; public class StringBufferStream extends OutputStream { - private StringBuffer buffer; + private StringBuilder buffer; public StringBufferStream() { - this.buffer = new StringBuffer(); + this.buffer = new StringBuilder(); } - public StringBufferStream(StringBuffer buffer) { + public StringBufferStream(StringBuilder buffer) { this.buffer = buffer; } - public StringBuffer getBuffer() { + public StringBuilder getBuffer() { return buffer; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/CompositeArtifactRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/CompositeArtifactRepositoryTest.java index 28dce634e3..19e808b71a 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/CompositeArtifactRepositoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/CompositeArtifactRepositoryTest.java @@ -694,7 +694,7 @@ public void testUncompressedPersistence() { public void testSyntaxErrorWhileParsing() { File badCompositeArtifacts = getTestData("1", "/testData/artifactRepo/composite/Bad/syntaxError"); PrintStream err = System.err; - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); try { System.setErr(new PrintStream(new StringBufferStream(buffer))); getArtifactRepositoryManager().loadRepository(badCompositeArtifacts.toURI(), null); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/DirectorApplicationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/DirectorApplicationTest.java index f695b17028..e917446ec4 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/DirectorApplicationTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/DirectorApplicationTest.java @@ -56,10 +56,10 @@ public class DirectorApplicationTest extends AbstractProvisioningTest { /** * runs default director app. */ - private StringBuffer runDirectorApp(String message, final String[] args) throws Exception { + private StringBuilder runDirectorApp(String message, final String[] args) throws Exception { PrintStream out = System.out; PrintStream err = System.err; - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); try { PrintStream newStream = new PrintStream(new StringBufferStream(buffer)); System.setOut(newStream); @@ -132,7 +132,7 @@ public void testSingleRepoCreationBothInvalid() { //Setup: use default arguments String[] args = getSingleRepoArgs("1.0", metadataRepo, artifactRepo, destinationRepo, installIU); - StringBuffer outputBuffer = null; + StringBuilder outputBuffer = null; try { outputBuffer = runDirectorApp("1.1", args); } catch (ProvisionException e) { @@ -178,7 +178,7 @@ public void testSingleRepoCreationMetadataInvalid() { //Setup: use default arguments String[] args = getSingleRepoArgs("2.1", metadataRepo, artifactRepo, destinationRepo, installIU); - StringBuffer outputBuffer = null; + StringBuilder outputBuffer = null; try { outputBuffer = runDirectorApp("2.2", args); } catch (ProvisionException e) { @@ -221,7 +221,7 @@ public void testSingleRepoCreationArtifactInvalid() { //Setup: use default arguments String[] args = getSingleRepoArgs("3.1", metadataRepo, artifactRepo, destinationRepo, installIU); - StringBuffer outputBuffer = null; + StringBuilder outputBuffer = null; try { outputBuffer = runDirectorApp("3.2", args); } catch (ProvisionException e) { @@ -636,7 +636,7 @@ public void testOnlyUsePassedInRepos() throws Exception { destinationRepo.mkdirs(); - StringBuffer buffer = runDirectorApp("12.5", args); + StringBuilder buffer = runDirectorApp("12.5", args); assertTrue(buffer.toString().contains("The installable unit yetanotherplugin has not been found.")); final URI[] afterArtifactRepos = artifactManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); @@ -672,7 +672,7 @@ public void testPassedInRepos_ProvisioningContext() throws Exception { String[] args = getSingleRepoArgs("13.4", metadataRepo2, artifactRepo2, destinationRepo, "helloworld"); destinationRepo.mkdirs(); - StringBuffer buffer = runDirectorApp("13.5", args); + StringBuilder buffer = runDirectorApp("13.5", args); assertTrue(buffer.toString().contains("Installing helloworld 1.0.0.")); artifactManager.removeRepository(artifactRepo1.toURI()); @@ -694,7 +694,7 @@ public void testDownloadOnlyFlag() { String[] args = getSingleRepoArgs("testDownloadOnly", metadataRepo, artifactRepo, destinationRepo, installIU, "-downloadOnly"); try { - StringBuffer buffer = runDirectorApp("testDownloadOnly", args); + StringBuilder buffer = runDirectorApp("testDownloadOnly", args); assertTrue(buffer.toString().contains("Installing fff.feature.group 1.0.0.")); } catch (Exception e) { fail("fail", e); @@ -722,7 +722,7 @@ public void testListFormatMissingListArgument() throws Exception { //Setup: create the args String[] args = getSingleRepoArgsForListing("testListFormatMissingListArgument", metadataRepo, artifactRepo, "", "", "-listFormat", "%i=%v,%d"); - StringBuffer buffer = runDirectorApp("testListFormatMissingListArgument", args); + StringBuilder buffer = runDirectorApp("testListFormatMissingListArgument", args); assertThat(buffer.toString(), containsString("-listFormat requires")); } @@ -734,7 +734,7 @@ public void testListFormat() throws Exception { //Setup: create the args String[] args = getSingleRepoArgsForListing("testListFormat", metadataRepo, artifactRepo, "-list", "", "-listFormat", "${id}_${version},${id},${org.eclipse.equinox.p2.name}"); - StringBuffer buffer = runDirectorApp("testListFormat", args); + StringBuilder buffer = runDirectorApp("testListFormat", args); assertThat(buffer.toString(), containsString("org.eclipse.ui.examples.job_3.0.0,org.eclipse.ui.examples.job,Progress Examples Plug-in")); } @@ -746,7 +746,7 @@ public void testListNoExplicitFormat() throws Exception { //Setup: create the args String[] args = getSingleRepoArgsForListing("testListNoExplicitFormat", metadataRepo, artifactRepo, "-list", "", "", ""); - StringBuffer buffer = runDirectorApp("testListNoExplicitFormat", args); + StringBuilder buffer = runDirectorApp("testListNoExplicitFormat", args); assertThat(buffer.toString(), containsString("org.eclipse.ui.examples.job=3.0.0")); } @@ -767,7 +767,7 @@ public void testUninstallIgnoresPassedInRepos() throws Exception { destinationRepo.mkdirs(); - StringBuffer buffer = runDirectorApp("14.2", args); + StringBuilder buffer = runDirectorApp("14.2", args); assertTrue(buffer.toString().contains("The installable unit helloworld has not been found.")); artifactManager.removeRepository(srcRepo.toURI()); @@ -885,7 +885,7 @@ public void testPGPSignedArtifact() throws Exception { destinationRepo.mkdirs(); - StringBuffer buffer = runDirectorApp(null, args); + StringBuilder buffer = runDirectorApp(null, args); assertFalse(buffer.toString(), buffer.toString().contains("failed")); artifactManager.removeRepository(srcRepo.toURI()); @@ -908,7 +908,7 @@ public void testRejectedPGPSignedArtifact() throws Exception { destinationRepo.mkdirs(); - StringBuffer buffer = runDirectorApp(null, args.toArray(String[]::new)); + StringBuilder buffer = runDirectorApp(null, args.toArray(String[]::new)); assertTrue(buffer.toString(), buffer.toString().contains("One or more PGP keys are not trusted.")); artifactManager.removeRepository(srcRepo.toURI()); @@ -933,7 +933,7 @@ public void testSpecificallyAcceptedGPSignedArtifact() throws Exception { destinationRepo.mkdirs(); - StringBuffer buffer = runDirectorApp(null, args.toArray(String[]::new)); + StringBuilder buffer = runDirectorApp(null, args.toArray(String[]::new)); assertFalse(buffer.toString(), buffer.toString().contains("failed")); artifactManager.removeRepository(srcRepo.toURI()); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java index 09d64caed9..2730efc029 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java @@ -59,10 +59,10 @@ protected Object launchApplication(Map applicationMap) { } public Object go(String[] arguments) throws Exception { - return go(arguments, new StringBuffer()); + return go(arguments, new StringBuilder()); } - public Object go(String[] arguments, StringBuffer buffer) throws Exception { + public Object go(String[] arguments, StringBuilder buffer) throws Exception { Object result = null; PrintStream out = System.out; PrintStream err = System.err; @@ -112,7 +112,7 @@ public void test233240_artifactsDeleted() throws Exception { //Taunt you one more time application = new TestGeneratorApplication(); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); try { application.go(arguments, buffer); fail("3.0 - Expected Illegal Argument Exception not thrown."); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/CompositeMetadataRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/CompositeMetadataRepositoryTest.java index d7f71e4c53..8b29a33efb 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/CompositeMetadataRepositoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/CompositeMetadataRepositoryTest.java @@ -389,7 +389,7 @@ public void testUncompressedPersistence() { public void testSyntaxErrorWhileParsing() { File badCompositeContent = getTestData("1", "/testData/metadataRepo/composite/Bad/syntaxError"); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); PrintStream err = System.err; try { System.setErr(new PrintStream(new StringBufferStream(buffer))); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java index 0529e84087..351cc537e5 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java @@ -99,8 +99,8 @@ protected void tearDown() throws Exception { /** * runs the mirror application with arguments args */ - private StringBuffer runMirrorApplication(String message, final String[] args) throws Exception { - StringBuffer buffer = new StringBuffer(); + private StringBuilder runMirrorApplication(String message, final String[] args) throws Exception { + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; PrintStream err = System.err; try { diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MirrorApplicationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MirrorApplicationTest.java index 8a709580ce..bc7f2b574c 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MirrorApplicationTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MirrorApplicationTest.java @@ -134,8 +134,8 @@ private static RepositoryDescriptor createRepositoryDescriptor(URI location, Boo return descriptor; } - private static StringBuffer runApplication(MirrorApplication app) throws ProvisionException { - StringBuffer buffer = new StringBuffer(); + private static StringBuilder runApplication(MirrorApplication app) throws ProvisionException { + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; try { System.setOut(new PrintStream(new StringBufferStream(buffer))); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java index aa1ccf1bd8..64b04672e0 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java @@ -107,7 +107,7 @@ public void tearDown() throws Exception { super.tearDown(); } - private StringBuffer basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination, String destName) throws Exception { + private StringBuilder basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination, String destName) throws Exception { MirrorApplication app = new MirrorApplication(); if (destination != null) { @@ -124,7 +124,7 @@ private StringBuffer basicRunMirrorApplication(String message, URI source, URI d app.addSource(src); } - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; try { System.setOut(new PrintStream(new StringBufferStream(buffer))); @@ -135,11 +135,11 @@ private StringBuffer basicRunMirrorApplication(String message, URI source, URI d return buffer; } - private StringBuffer basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination) throws Exception { + private StringBuilder basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination) throws Exception { return basicRunMirrorApplication(message, source, destination, append, formatDestination, null); } - private StringBuffer basicRunMirrorApplication(String message, URI source, URI destination) throws Exception { + private StringBuilder basicRunMirrorApplication(String message, URI source, URI destination) throws Exception { return basicRunMirrorApplication(message, source, destination, null, null, null); } @@ -826,7 +826,7 @@ public void testExistingArtifactRepoWithNewName() { } assertEquals("Assert name is set correctly before mirror", oldName, destinationRepo.getName()); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; try { System.setOut(new PrintStream(new StringBufferStream(buffer))); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/GeneralPublisherTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/GeneralPublisherTests.java index e04b716e91..d4a99ac940 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/GeneralPublisherTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/GeneralPublisherTests.java @@ -44,7 +44,7 @@ public void testBug255820_Product_normalize() throws Exception { public void testInvalidConfiguration1() { FeaturesAndBundlesPublisherApplication application = new FeaturesAndBundlesPublisherApplication(); Integer retValue = 0; - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; try { System.setOut(new PrintStream(new StringBufferStream(buffer))); @@ -63,7 +63,7 @@ public void testInvalidConfiguration1() { public void testInvalidConfiguration2() { FeaturesAndBundlesPublisherApplication application = new FeaturesAndBundlesPublisherApplication(); Integer retValue = 0; - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; try { System.setOut(new PrintStream(new StringBufferStream(buffer))); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/CategoryPublisherTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/CategoryPublisherTest.java index 92ed0a9cc7..38bfd8a3c0 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/CategoryPublisherTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/CategoryPublisherTest.java @@ -26,9 +26,9 @@ public class CategoryPublisherTest extends AbstractProvisioningTest { /** * runs default director app. */ - protected StringBuffer runPublisherApp(AbstractPublisherApplication application, final String[] args) throws Exception { + protected StringBuilder runPublisherApp(AbstractPublisherApplication application, final String[] args) throws Exception { PrintStream out = System.out; - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); try { System.setOut(new PrintStream(new StringBufferStream(buffer))); application.run(args); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java index cc2b02bda5..9f6c1b3193 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java @@ -280,7 +280,7 @@ private File getPlatformZip() { // then use the non canonical one... } } - StringBuffer detailedMessage = new StringBuffer(600); + StringBuilder detailedMessage = new StringBuilder(600); detailedMessage.append(" propertyToPlatformArchive was ").append(propertyToPlatformArchive == null ? " not set " : propertyToPlatformArchive).append('\n'); detailedMessage.append(" org.eclipse.equinox.p2.reconciler.tests.platform.archive was ").append(property == null ? " not set " : property).append('\n'); detailedMessage.append(" install location is ").append(getInstallLocation()).append('\n'); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java index 652f5a1a2d..e5fcab8f77 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java @@ -308,7 +308,7 @@ public void testCorruptDigestGoodSite() { } catch (ProvisionException e) { fail("0.2", e); } - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; try { System.setOut(new PrintStream(new StringBufferStream(buffer))); @@ -373,7 +373,7 @@ public void testBadFeatureURL() { } catch (ProvisionException e) { fail("0.2", e); } - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; try { System.setOut(new PrintStream(new StringBufferStream(buffer))); @@ -463,7 +463,7 @@ public void testBadIncludedFeatureArchive() { } catch (ProvisionException e) { fail("0.2", e); } - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; try { System.setOut(new PrintStream(new StringBufferStream(buffer))); @@ -617,7 +617,7 @@ public void testRepoWithFeatureWithNullUpdateURL() { assertNotNull(repoMan); File site = getTestData("Update site", "/testData/updatesite/missingUpdateURLFeature/"); IMetadataRepository metadataRepo = null; - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); PrintStream out = System.out; try { System.setOut(new PrintStream(new StringBufferStream(buffer)));