Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.eclipse.ui.tests.harness.util;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static void assertDialog(Dialog dialog) {
getShell();
}
if (_verifyDialog.open(dialog) == IDialogConstants.NO_ID) {
assertTrue(_verifyDialog.getFailureText(), false);
fail(_verifyDialog.getFailureText());
}
}

Expand Down Expand Up @@ -117,30 +117,28 @@ public static Shell getShell() {
private static void verifyCompositeText(Composite composite) {
Control children[] = composite.getChildren();
for (Control child : children) {
if (child instanceof TabFolder) {
TabFolder folder = (TabFolder) child;
if (child instanceof TabFolder folder) {
int numPages = folder.getItemCount();
for (int j = 0; j < numPages; j++) {
folder.setSelection(j);
}
} else if (child instanceof CTabFolder) {
CTabFolder folder = (CTabFolder) child;
} else if (child instanceof CTabFolder folder) {
int numPages = folder.getItemCount();
for (int j = 0; j < numPages; j++) {
folder.setSelection(j);
}
}
else if (child instanceof Button) {
else if (child instanceof Button b) {
//verify the text if the child is a button
verifyButtonText((Button) child);
verifyButtonText(b);
}
else if (child instanceof Label) {
else if (child instanceof Label l) {
//child is not a button, maybe a label
verifyLabelText((Label) child);
verifyLabelText(l);
}
else if (child instanceof Composite) {
else if (child instanceof Composite comp) {
//child is not a label, make a recursive call if it is a composite
verifyCompositeText((Composite) child);
verifyCompositeText(comp);
}
}
}
Expand All @@ -158,7 +156,7 @@ private static void verifyButtonText(Button button) {
//if (size.y/preferred.y) == X, then label spans X lines, so divide
//the calculated value of preferred.x by X
if (preferred.y * size.y > 0) {
preferred.y /= countLines(button.getText()); //check for '\n\'
preferred.y /= button.getText().lines().count(); // check for '\n\'
if (size.y / preferred.y > 1) {
preferred.x /= (size.y / preferred.y);
}
Expand All @@ -170,7 +168,7 @@ private static void verifyButtonText(Button button) {
if (preferred.x > size.x) {
//close the dialog
button.getShell().dispose();
assertTrue(message, false);
fail(message);
}
}

Expand All @@ -191,7 +189,7 @@ private static void verifyLabelText(Label label) {
//if (size.y/preferred.y) == X, then label spans X lines, so divide
//the calculated value of preferred.x by X
if (preferred.y * size.y > 0) {
preferred.y /= countLines(label.getText());
preferred.y /= label.getText().lines().count();
if (size.y / preferred.y > 1) {
preferred.x /= (size.y / preferred.y);
}
Expand All @@ -202,24 +200,8 @@ private static void verifyLabelText(Label label) {
if (preferred.x > size.x) {
//close the dialog
label.getShell().dispose();
assertTrue(message, false);
fail(message);
}
}

/*
* Counts the number of lines in a given String.
* For example, if a string contains one (1) newline character,
* a value of two (2) would be returned.
* @param text The string to look through.
* @return int the number of lines in text.
*/
private static int countLines(String text) {
int newLines = 1;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '\n') {
newLines++;
}
}
return newLines;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -18,13 +18,10 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
Expand All @@ -37,10 +34,6 @@

public class FileTool {

/**
* A buffer.
*/
private static byte[] buffer = new byte[8192];
/**
* Unzips the given zip file to the given destination directory
* extracting only those entries the pass through the given
Expand All @@ -64,7 +57,7 @@ public static void unzip(ZipFile zipFile, File dstDir) throws IOException {
File file = new File(dstDir, changeSeparator(entryName, '/', File.separatorChar));
file.getParentFile().mkdirs();
try (InputStream src = zipFile.getInputStream(entry); OutputStream dst= new FileOutputStream(file)){
transferData(src, dst);
src.transferTo(dst);
}
}
} finally {
Expand Down Expand Up @@ -99,24 +92,7 @@ public static String changeSeparator(String path, char oldSeparator, char newSep
public static void transferData(File source, File destination) throws IOException {
destination.getParentFile().mkdirs();
try (InputStream is = new FileInputStream(source); OutputStream os = new FileOutputStream(destination)) {
transferData(is, os);
}
}
/**
* Copies all bytes in the given source stream to
* the given destination stream. Neither streams
* are closed.
*
* @param source the given source stream
* @param destination the given destination stream
*/
public static void transferData(InputStream source, OutputStream destination) throws IOException {
int bytesRead = 0;
while(bytesRead != -1){
bytesRead = source.read(buffer, 0, buffer.length);
if(bytesRead != -1){
destination.write(buffer, 0, bytesRead);
}
is.transferTo(os);
}
}

Expand Down Expand Up @@ -151,12 +127,6 @@ public static File getFileInPlugin(Plugin plugin, IPath path) {
}
}

public static StringBuilder readToBuilder(String fileName) throws IOException {
try (FileReader reader = new FileReader(fileName)) {
return readToBuilder(reader);
}
}

public static StringBuilder readToBuilder(Reader reader) throws IOException {
StringBuilder s = new StringBuilder();
try {
Expand All @@ -175,9 +145,4 @@ public static StringBuilder readToBuilder(Reader reader) throws IOException {
return s;
}

public static void writeFromBuilder(String fileName, StringBuilder content) throws IOException {
try (Writer writer = new FileWriter(fileName)) {
writer.write(content.toString());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,9 +13,6 @@
*******************************************************************************/
package org.eclipse.ui.tests.harness.util;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
Expand Down Expand Up @@ -81,8 +78,8 @@ public static void createFolder(IFolder folder, boolean force, boolean local, IP
throws CoreException {
if (!folder.exists()) {
IContainer parent = folder.getParent();
if (parent instanceof IFolder) {
createFolder((IFolder) parent, force, local, null);
if (parent instanceof IFolder f) {
createFolder(f, force, local, null);
}
folder.create(force, local, monitor);
}
Expand All @@ -98,9 +95,7 @@ public static void createFolder(IFolder folder, boolean force, boolean local, IP
public static IFile createFile(String name, IProject proj) throws CoreException {
IFile file = proj.getFile(name);
if (!file.exists()) {
String str = " ";
InputStream in = new ByteArrayInputStream(str.getBytes());
file.create(in, true, null);
file.create(" ".getBytes(), IResource.FORCE, null);
}
return file;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,6 +14,8 @@
package org.eclipse.ui.tests.navigator;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand All @@ -31,7 +33,6 @@
import org.eclipse.ui.intro.IIntroPart;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.tests.harness.util.EditorTestHelper;
import org.eclipse.ui.tests.harness.util.FileTool;
import org.eclipse.ui.tests.harness.util.FileUtil;
import org.eclipse.ui.tests.harness.util.UITestCase;
import org.eclipse.ui.texteditor.AbstractTextEditor;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void doSetUp() {
file = FileUtil.createFile(FILE_NAME, project);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(FILE_CONTENTS);
FileTool.writeFromBuilder(file.getLocation().toOSString(), stringBuilder);
Files.writeString(Paths.get(file.getLocation().toOSString()), stringBuilder);
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
fail("Should not throw an exception");
Expand Down
Loading