Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Code for ui/org.eclipse.pde.ui.tests #1662

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: PDE JUnit Tests
Bundle-SymbolicName: org.eclipse.pde.ui.tests; singleton:=true
Bundle-Version: 3.13.0.qualifier
Bundle-Version: 3.13.100.qualifier
Bundle-ClassPath: tests.jar
Bundle-Vendor: Eclipse.org
Require-Bundle: org.eclipse.pde.ui,
Expand Down
2 changes: 1 addition & 1 deletion ui/org.eclipse.pde.ui.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<relativePath>../../</relativePath>
</parent>
<artifactId>org.eclipse.pde.ui.tests</artifactId>
<version>3.13.0-SNAPSHOT</version>
<version>3.13.100-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ private int getIntAttribute(IMarker marker, String property) {
return 0;
}

if (value == null)
if (value == null) {
return 0;
}
return value.intValue();
}

Expand All @@ -185,8 +186,9 @@ private String getStringAttribute(IMarker marker, String property) {
value = "";
}

if (value == null || value.equalsIgnoreCase("\"\""))
if (value == null || value.equalsIgnoreCase("\"\"")) {
value = "";
}
return value.trim();
}

Expand All @@ -197,8 +199,9 @@ private String getProperty(PropertyResourceBundle propertyBundle, String propert
} catch (Exception e) {
value = "";
}
if (value == null || value.equalsIgnoreCase("\"\""))
if (value == null || value.equalsIgnoreCase("\"\"")) {
value = "";
}
return value.trim();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public class EnvironmentAnalyzerDelegate implements IExecutionEnvironmentAnalyze

@Override
public CompatibleEnvironment[] analyze(IVMInstall vm, IProgressMonitor monitor) throws CoreException {
if (!(vm instanceof IVMInstall2 vm2))
if (!(vm instanceof IVMInstall2 vm2)) {
return new CompatibleEnvironment[0];
}
ArrayList<CompatibleEnvironment> result = new ArrayList<>();
String javaVersion = vm2.getJavaVersion();
if (javaVersion != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ protected void load(boolean addListener) {
try {
fModel = new BundleModel(fDocument, false);
fModel.load();
if (!fModel.isLoaded() || !fModel.isValid())
if (!fModel.isLoaded() || !fModel.isValid()) {
fail("model cannot be loaded");
}
if (addListener) {
fListener = new BundleTextChangeListener(fModel.getDocument());
fModel.addModelChangedListener(fListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,11 @@ public void testRemoveReExport() throws Exception {

private static RequireBundleObject getBundle(RequireBundleHeader header, String id) {
RequireBundleObject[] bundles = header.getRequiredBundles();
for (RequireBundleObject bundle : bundles)
if (bundle.getId().equals(id))
for (RequireBundleObject bundle : bundles) {
if (bundle.getId().equals(id)) {
return bundle;
}
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ protected void load(boolean addListener) {
try {
fModel = new PluginModel(fDocument, true);
fModel.load();
if (!fModel.isLoaded() || !fModel.isValid())
if (!fModel.isLoaded() || !fModel.isValid()) {
fail("model cannot be loaded");
}
if (addListener) {
fListener = new XMLTextChangeListener(fModel.getDocument());
fModel.addModelChangedListener(fListener);
Expand All @@ -68,8 +69,9 @@ protected void setXMLContents(StringBuilder body, String newline) {
sb.append(newline);
sb.append("<plugin>");
sb.append(newline);
if (body != null)
if (body != null) {
sb.append(body.toString());
}
sb.append(newline);
sb.append("</plugin>");
sb.append(newline);
Expand All @@ -78,8 +80,9 @@ protected void setXMLContents(StringBuilder body, String newline) {

protected void reload() {
TextEdit[] ops = fListener.getTextOperations();
if (ops.length == 0)
if (ops.length == 0) {
return;
}
MultiTextEdit multi = new MultiTextEdit();
multi.addChildren(ops);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ protected void setUpIterations() {

private void setUpSchemaFile() throws Exception, IOException {
Bundle bundle = FrameworkUtil.getBundle(AbstractSchemaPerfTest.class);
if (bundle == null)
if (bundle == null) {
throw new Exception("ERROR: Bundle uninitialized"); //$NON-NLS-1$
}
URL url = bundle.getEntry(F_FILENAME);
if (url == null)
if (url == null) {
throw new Exception("ERROR: URL not found: " + F_FILENAME); //$NON-NLS-1$
}
String path = FileLocator.resolve(url).getPath();
if ("".equals(path)) //$NON-NLS-1$
if ("".equals(path)) { //$NON-NLS-1$
throw new Exception("ERROR: URL unresolved: " + F_FILENAME); //$NON-NLS-1$
}
fXSDFile = new File(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ public void testPreferenceChangeListener1(){
preferences.removePreferenceChangeListener(listener);

// Restore original value
if (originalValue != key)
if (originalValue != key) {
preferences.put(key, originalValue);
}
}

@Test
Expand All @@ -105,8 +106,9 @@ public void testPreferenceChangeListner2(){
preferences.removePreferenceChangeListener(listener);

// Restore original value
if (originalValue != key)
if (originalValue != key) {
preferences.put(key, originalValue);
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ public void testHopViaTargetPlatform_required() throws Exception {
IBuildConfiguration[] referencedBuildConfigs = coreCommandsProject
.getReferencedBuildConfigs(coreCommandsProject.getActiveBuildConfig().getName(), false);
for (IBuildConfiguration reference : referencedBuildConfigs) {
if (reference.getProject() == osgiProject)
if (reference.getProject() == osgiProject) {
return;
}
}

Assert.fail("references should include local osgi project: " + Arrays.toString(referencedBuildConfigs));
Expand All @@ -101,8 +102,9 @@ public void testHopViaTargetPlatform_imported() throws Exception {
IBuildConfiguration[] referencedBuildConfigs = importingTargetBundle
.getReferencedBuildConfigs(importingTargetBundle.getActiveBuildConfig().getName(), false);
for (IBuildConfiguration reference : referencedBuildConfigs) {
if (reference.getProject() == osgiProject)
if (reference.getProject() == osgiProject) {
return;
}
}

Assert.fail("references should include local osgi project: " + Arrays.toString(referencedBuildConfigs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,21 @@ protected String getProjectName() {
}

private void createFeature(FeatureData fd, boolean patch, Object modelObject) throws Exception {
if (fd == null)
if (fd == null) {
fd = DEFAULT_FEATURE_DATA;
}
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
IPath path = Platform.getLocation();
IRunnableWithProgress op;
if ((patch && !(modelObject instanceof IFeatureModel)) || (!patch && modelObject != null && !(modelObject instanceof IPluginBase[])))
if ((patch && !(modelObject instanceof IFeatureModel)) || (!patch && modelObject != null && !(modelObject instanceof IPluginBase[]))) {
fail("Unaccepted model object passed..." + modelObject);
}

if (patch)
if (patch) {
op = new CreateFeaturePatchOperation(project, path, fd, (IFeatureModel) modelObject, PDEPlugin.getActiveWorkbenchShell());
else
} else {
op = new CreateFeatureProjectOperation(project, path, fd, (IPluginBase[]) modelObject, PDEPlugin.getActiveWorkbenchShell());
}
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
progressService.runInUI(progressService, op, null);
}
Expand All @@ -89,9 +92,10 @@ public void testCreationFeatureProject() throws Exception {
@Test
public void testCreationFeaturePatch() throws Exception {
IFeatureModel[] models = PDECore.getDefault().getFeatureModelManager().getModels();
if (models.length == 0)
if (models.length == 0) {
// cant test patches if no feature models exist
return;
}
createFeature(DEFAULT_FEATURE_DATA, true, models[0]);
verifyProjectExistence();
verifyFeatureNature();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ public void setUp() throws Exception {
+ "<category-def name=\"new_category_1\" label=\"New Category 1\"/>" //$NON-NLS-1$
+ "</site>"; //$NON-NLS-1$
ByteArrayInputStream source = new ByteArrayInputStream(content.getBytes(StandardCharsets.US_ASCII));
if (file.exists())
if (file.exists()) {
file.setContents(source, true, false, new NullProgressMonitor());
else
} else {
file.create(source, true, new NullProgressMonitor());
}
project.delete(false, true, new NullProgressMonitor());
}
}
Expand Down
Loading