Skip to content

Commit

Permalink
Apply 'Convert StringBuffer to StringBuilder' clean-up to p2 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Dec 9, 2023
1 parent d2492e3 commit cb70b67
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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"));
}

Expand All @@ -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"));
}

Expand All @@ -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"));
}

Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ protected Object launchApplication(Map<String, Object> 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;
Expand Down Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)));
Expand All @@ -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);
}

Expand Down Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit cb70b67

Please sign in to comment.