summaryrefslogtreecommitdiff
path: root/sc/qa/complex
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2015-06-09 15:24:08 +0200
committerNoel Grandin <noelgrandin@gmail.com>2015-06-11 12:52:06 +0000
commit3bd57cc2c0cabf33799edc57d3dd1c90c7857ecd (patch)
tree353a2b569d3acb9efa06ee4edf0178dd04ede9f8 /sc/qa/complex
parent0a8d96b7b565e496a18e22b44d04be7aa2513c94 (diff)
java:remove more unnecessary catch/re-throw
Change-Id: Id9a13c7f4ae0fd53c95c551544e60af44bb3fb95 Reviewed-on: https://gerrit.libreoffice.org/16203 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sc/qa/complex')
-rwxr-xr-x[-rw-r--r--]sc/qa/complex/cellRanges/CheckXCellRangesQuery.java166
-rw-r--r--sc/qa/complex/dataPilot/CheckDataPilot.java146
2 files changed, 120 insertions, 192 deletions
diff --git a/sc/qa/complex/cellRanges/CheckXCellRangesQuery.java b/sc/qa/complex/cellRanges/CheckXCellRangesQuery.java
index 9feb683be1ea..288b4f502239 100644..100755
--- a/sc/qa/complex/cellRanges/CheckXCellRangesQuery.java
+++ b/sc/qa/complex/cellRanges/CheckXCellRangesQuery.java
@@ -54,66 +54,48 @@ public class CheckXCellRangesQuery {
String sSheetName = "";
/**
- * Creates Spreadsheet document and the test object,
- * before the actual test starts.
- */
- @Before public void before() {
+ * Creates Spreadsheet document and the test object, before the actual test
+ * starts.
+ */
+ @Before
+ public void before() throws Exception {
// create a calc document
- final XMultiServiceFactory xMsf = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
+ final XMultiServiceFactory xMsf = UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, connection.getComponentContext()
+ .getServiceManager());
SOfficeFactory SOF = SOfficeFactory.getFactory(xMsf);
- try {
- System.out.println( "creating a Spreadsheet document" );
- m_xSheetDoc = SOF.createCalcDoc(null);
- } catch ( com.sun.star.uno.Exception e ) {
- // Some exception occurs.FAILED
- e.printStackTrace( );
- fail( "Couldn?t create document");
- }
+ System.out.println("creating a Spreadsheet document");
+ m_xSheetDoc = SOF.createCalcDoc(null);
XInterface oObj = null;
- try {
- System.out.println("Getting spreadsheet") ;
- XSpreadsheets oSheets = m_xSheetDoc.getSheets() ;
- XIndexAccess oIndexSheets =
- UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
- m_xSpreadSheet = (XSpreadsheet) AnyConverter.toObject(
- new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
-
- // get the first sheet name
- XNamed xNamed = (XNamed) AnyConverter.toObject(new Type(XNamed.class),m_xSpreadSheet);
- sSheetName = xNamed.getName();
-
- // get the cell
- System.out.println("Getting a cell from sheet") ;
- oObj = m_xSpreadSheet.getCellByPosition(2, 3);
- m_xCell = UnoRuntime.queryInterface(XCellRangesQuery.class, oObj);
-
- } catch (com.sun.star.lang.WrappedTargetException e) {
- e.printStackTrace();
- fail("Error getting cell object from spreadsheet document");
- } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
- e.printStackTrace();
- fail("Error getting cell object from spreadsheet document");
- } catch (com.sun.star.lang.IllegalArgumentException e) {
- e.printStackTrace();
- fail("Error getting cell object from spreadsheet document");
- }
+ System.out.println("Getting spreadsheet");
+ XSpreadsheets oSheets = m_xSheetDoc.getSheets();
+ XIndexAccess oIndexSheets = UnoRuntime.queryInterface(
+ XIndexAccess.class, oSheets);
+ m_xSpreadSheet = (XSpreadsheet) AnyConverter.toObject(new Type(
+ XSpreadsheet.class), oIndexSheets.getByIndex(0));
+
+ // get the first sheet name
+ XNamed xNamed = (XNamed) AnyConverter.toObject(new Type(XNamed.class),
+ m_xSpreadSheet);
+ sSheetName = xNamed.getName();
+
+ // get the cell
+ System.out.println("Getting a cell from sheet");
+ oObj = m_xSpreadSheet.getCellByPosition(2, 3);
+ m_xCell = UnoRuntime.queryInterface(XCellRangesQuery.class, oObj);
// set one value for comparison.
- try {
- m_xSpreadSheet.getCellByPosition(1, 1).setValue(15);
- m_xSpreadSheet.getCellByPosition(1, 3).setValue(5);
- m_xSpreadSheet.getCellByPosition(2, 1).setFormula("=B2+B4");
- } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
- e.printStackTrace();
- fail("Could not fill cell (1, 1) with a value.");
- }
+ m_xSpreadSheet.getCellByPosition(1, 1).setValue(15);
+ m_xSpreadSheet.getCellByPosition(1, 3).setValue(5);
+ m_xSpreadSheet.getCellByPosition(2, 1).setFormula("=B2+B4");
}
- /*
- * this method closes a calc document and resets the corresponding class variable xSheetDoc
+ /**
+ * this method closes a calc document and resets the corresponding class
+ * variable xSheetDoc
*/
protected boolean closeSpreadsheetDocument() {
boolean worked = true;
@@ -121,8 +103,8 @@ public class CheckXCellRangesQuery {
System.out.println(" disposing xSheetDoc ");
try {
- XCloseable oCloser = UnoRuntime.queryInterface(
- XCloseable.class, m_xSheetDoc);
+ XCloseable oCloser = UnoRuntime.queryInterface(XCloseable.class,
+ m_xSheetDoc);
oCloser.close(true);
} catch (com.sun.star.util.CloseVetoException e) {
worked = false;
@@ -140,10 +122,10 @@ public class CheckXCellRangesQuery {
return worked;
}
- @After public void after()
- {
- closeSpreadsheetDocument();
- }
+ @After
+ public void after() {
+ closeSpreadsheetDocument();
+ }
/**
* Perform some tests on an empty cell:
@@ -153,24 +135,32 @@ public class CheckXCellRangesQuery {
* <li>query for empty cells</li>
* <ol>
*/
- @Test public void checkEmptyCell() {
+ @Test
+ public void checkEmptyCell() {
System.out.println("Checking an empty cell...");
// compare an empty cell with a cell with a value
- assertTrue("\tQuery column differences did not return the correct value.", _queryColumnDifferences(sSheetName+".C4"));
+ assertTrue(
+ "\tQuery column differences did not return the correct value.",
+ _queryColumnDifferences(sSheetName + ".C4"));
// compare an empty cell with a cell with a value
- assertTrue("\tQuery column differences did not return the correct value.", _queryRowDifferences(sSheetName+".C4"));
+ assertTrue(
+ "\tQuery column differences did not return the correct value.",
+ _queryRowDifferences(sSheetName + ".C4"));
System.out.println("...done");
}
/**
* Perform some tests on a filled cell:
* <ol>
- * <li>compare an cell with value 5 with a cell with value 15 in the same column</li>
- * <li>compare an cell with value 5 with a cell with value 15 in the same row</li>
+ * <li>compare an cell with value 5 with a cell with value 15 in the same
+ * column</li>
+ * <li>compare an cell with value 5 with a cell with value 15 in the same
+ * row</li>
* <li>query for an empty cell.</li>
* <ol>
*/
- @Test public void checkFilledCell() {
+ @Test
+ public void checkFilledCell() {
System.out.println("Checking a filled cell...");
// fill the cell with a value
@@ -182,24 +172,30 @@ public class CheckXCellRangesQuery {
}
// compare an cell with value 5 with a cell with value 15
- assertTrue("\tQuery column differences did not return the correct value.", _queryColumnDifferences(sSheetName + ".C4"));
+ assertTrue(
+ "\tQuery column differences did not return the correct value.",
+ _queryColumnDifferences(sSheetName + ".C4"));
// compare an cell with value 5 with a cell with value 15
- assertTrue("\tQuery column differences did not return the correct value.", _queryRowDifferences(sSheetName+".C4"));
+ assertTrue(
+ "\tQuery column differences did not return the correct value.",
+ _queryRowDifferences(sSheetName + ".C4"));
// try to get nothing
- assertTrue("\tQuery empty cells did not return the correct value.", _queryEmptyCells(""));
+ assertTrue("\tQuery empty cells did not return the correct value.",
+ _queryEmptyCells(""));
System.out.println("...done");
}
-
/**
- * Query column differences between my cell(2,3) and (1,1).
- * @param expected The expected outcome value.
- * @return True, if the result equals the expected result.
+ * Query column differences between my cell(2,3) and (1,1).
+ *
+ * @param expected
+ * The expected outcome value.
+ * @return True, if the result equals the expected result.
*/
public boolean _queryColumnDifferences(String expected) {
System.out.println("\tQuery column differences");
- XSheetCellRanges ranges = m_xCell.queryColumnDifferences(
- new CellAddress((short) 0, 1, 1));
+ XSheetCellRanges ranges = m_xCell
+ .queryColumnDifferences(new CellAddress((short) 0, 1, 1));
String getting = ranges.getRangeAddressesAsString();
if (!getting.equals(expected)) {
@@ -212,8 +208,10 @@ public class CheckXCellRangesQuery {
/**
* Query for an empty cell.
- * @param expected The expected outcome value.
- * @return True, if the result equals the expected result.
+ *
+ * @param expected
+ * The expected outcome value.
+ * @return True, if the result equals the expected result.
*/
public boolean _queryEmptyCells(String expected) {
System.out.println("\tQuery empty cells");
@@ -229,14 +227,16 @@ public class CheckXCellRangesQuery {
}
/**
- * Query row differences between my cell(2,3) and (1,1).
- * @param expected The expected outcome value.
- * @return True, if the result equals the expected result.
+ * Query row differences between my cell(2,3) and (1,1).
+ *
+ * @param expected
+ * The expected outcome value.
+ * @return True, if the result equals the expected result.
*/
public boolean _queryRowDifferences(String expected) {
System.out.println("\tQuery row differences");
- XSheetCellRanges ranges = m_xCell.queryRowDifferences(
- new CellAddress((short) 0, 1, 1));
+ XSheetCellRanges ranges = m_xCell.queryRowDifferences(new CellAddress(
+ (short) 0, 1, 1));
String getting = ranges.getRangeAddressesAsString();
if (!getting.equals(expected)) {
@@ -248,14 +248,14 @@ public class CheckXCellRangesQuery {
return true;
}
-
- @BeforeClass public static void setUpConnection() throws Exception {
+ @BeforeClass
+ public static void setUpConnection() throws Exception {
connection.setUp();
}
- @AfterClass public static void tearDownConnection()
- throws InterruptedException, com.sun.star.uno.Exception
- {
+ @AfterClass
+ public static void tearDownConnection() throws InterruptedException,
+ com.sun.star.uno.Exception {
connection.tearDown();
}
diff --git a/sc/qa/complex/dataPilot/CheckDataPilot.java b/sc/qa/complex/dataPilot/CheckDataPilot.java
index ea3e4e6cc857..7554d1661a01 100644
--- a/sc/qa/complex/dataPilot/CheckDataPilot.java
+++ b/sc/qa/complex/dataPilot/CheckDataPilot.java
@@ -36,7 +36,6 @@ import com.sun.star.uno.Type;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.util.XCloseable;
-import lib.StatusException;
import lib.TestParameters;
import util.SOfficeFactory;
@@ -154,7 +153,7 @@ public class CheckDataPilot {
/**
* create an environment for the test
*/
- @Before public void before() {
+ @Before public void before() throws Exception {
final XMultiServiceFactory xMsf = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
SOfficeFactory SOF = SOfficeFactory.getFactory(xMsf);
@@ -176,14 +175,8 @@ public class CheckDataPilot {
sCellAdress.Column = 7;
sCellAdress.Row = 8;
- try {
- System.out.println( "Creating a Spreadsheet document" );
- xSheetDoc = SOF.createCalcDoc(null);
- } catch (com.sun.star.uno.Exception e) {
- // Some exception occurs.FAILED
- e.printStackTrace();
- throw new StatusException( "Couldn't create document", e );
- }
+ System.out.println( "Creating a Spreadsheet document" );
+ xSheetDoc = SOF.createCalcDoc(null);
System.out.println("Getting a sheet");
XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
@@ -195,42 +188,26 @@ public class CheckDataPilot {
// Per default there's now just one sheet, make sure we have at least two, then
xSpreadsheets.insertNewByName("Some Sheet", (short)0);
- try {
- oSheet = (XSpreadsheet) AnyConverter.toObject(
- new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
- oSheet2 = (XSpreadsheet) AnyConverter.toObject(
- new Type(XSpreadsheet.class),oIndexAccess.getByIndex(1));
- } catch (com.sun.star.lang.WrappedTargetException e) {
- e.printStackTrace();
- throw new StatusException( "Couldn't get a spreadsheet", e);
- } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
- e.printStackTrace();
- throw new StatusException( "Couldn't get a spreadsheet", e);
- } catch (com.sun.star.lang.IllegalArgumentException e) {
- e.printStackTrace();
- throw new StatusException( "Couldn't get a spreadsheet", e);
+ oSheet = (XSpreadsheet) AnyConverter.toObject(
+ new Type(XSpreadsheet.class),oIndexAccess.getByIndex(0));
+ oSheet2 = (XSpreadsheet) AnyConverter.toObject(
+ new Type(XSpreadsheet.class),oIndexAccess.getByIndex(1));
+
+ System.out.println("Filling a table");
+ for (int i = 1; i < mMaxFieldIndex; i++) {
+ oSheet.getCellByPosition(i, 0).setFormula("Col" + i);
+ oSheet.getCellByPosition(0, i).setFormula("Row" + i);
+ oSheet2.getCellByPosition(i, 0).setFormula("Col" + i);
+ oSheet2.getCellByPosition(0, i).setFormula("Row" + i);
}
- try {
- System.out.println("Filling a table");
- for (int i = 1; i < mMaxFieldIndex; i++) {
- oSheet.getCellByPosition(i, 0).setFormula("Col" + i);
- oSheet.getCellByPosition(0, i).setFormula("Row" + i);
- oSheet2.getCellByPosition(i, 0).setFormula("Col" + i);
- oSheet2.getCellByPosition(0, i).setFormula("Row" + i);
- }
-
- for (int i = 1; i < mMaxFieldIndex; i++)
+ for (int i = 1; i < mMaxFieldIndex; i++)
+ {
+ for (int j = 1; j < mMaxFieldIndex; j++)
{
- for (int j = 1; j < mMaxFieldIndex; j++)
- {
- oSheet.getCellByPosition(i, j).setValue(i * (j + 1));
- oSheet2.getCellByPosition(i, j).setValue(i * (j + 2));
- }
+ oSheet.getCellByPosition(i, j).setValue(i * (j + 1));
+ oSheet2.getCellByPosition(i, j).setValue(i * (j + 2));
}
- } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't fill some cells", e);
}
// change a value of a cell and check the change in the data pilot
@@ -238,18 +215,13 @@ public class CheckDataPilot {
Object oChangeCell = null;
Object oCheckCell = null;
Integer aChangeValue = null;
- try {
- // cell of data
- oChangeCell = oSheet.getCellByPosition(1, 5);
- int x = sCellAdress.Column;
- int y = sCellAdress.Row + 3;
- // cell of the data pilot output
- oCheckCell = oSheet.getCellByPosition(x, y);
- aChangeValue = Integer.valueOf(27);
- } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
- e.printStackTrace();
- throw new StatusException( "Couldn't get cells for changing.", e);
- }
+ // cell of data
+ oChangeCell = oSheet.getCellByPosition(1, 5);
+ int x = sCellAdress.Column;
+ int y = sCellAdress.Row + 3;
+ // cell of the data pilot output
+ oCheckCell = oSheet.getCellByPosition(x, y);
+ aChangeValue = Integer.valueOf(27);
// create the test objects
@@ -261,70 +233,26 @@ public class CheckDataPilot {
DPDsc.setSourceRange(sCellRangeAdress);
XPropertySet fieldPropSet = null;
- try {
- Object oDataPilotField = DPDsc.getDataPilotFields().getByIndex(0);
- fieldPropSet =
- UnoRuntime.queryInterface(XPropertySet.class, oDataPilotField);
- } catch (com.sun.star.lang.WrappedTargetException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't create a test environment", e);
- } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't create a test environment", e);
- }
+ Object oDataPilotField = DPDsc.getDataPilotFields().getByIndex(0);
+ fieldPropSet =
+ UnoRuntime.queryInterface(XPropertySet.class, oDataPilotField);
- try {
- fieldPropSet.setPropertyValue("Function",
- com.sun.star.sheet.GeneralFunction.SUM);
- fieldPropSet.setPropertyValue("Orientation",
- com.sun.star.sheet.DataPilotFieldOrientation.DATA);
- } catch(com.sun.star.lang.WrappedTargetException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't create a test environment", e);
- } catch(com.sun.star.lang.IllegalArgumentException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't create a test environment", e);
- } catch(com.sun.star.beans.PropertyVetoException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't create a test environment", e);
- } catch(com.sun.star.beans.UnknownPropertyException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't create a test environment", e);
- }
+ fieldPropSet.setPropertyValue("Function",
+ com.sun.star.sheet.GeneralFunction.SUM);
+ fieldPropSet.setPropertyValue("Orientation",
+ com.sun.star.sheet.DataPilotFieldOrientation.DATA);
System.out.println("Insert the DataPilotTable");
if (DPT.hasByName("DataPilotTable")) {
DPT.removeByName("DataPilotTable");
}
DPT.insertNewByName("DataPilotTable", sCellAdress, DPDsc);
- try {
- mDataPilotTableObject = (XInterface) AnyConverter.toObject(
- new Type(XInterface.class),DPT.getByName(DPT.getElementNames()[0]));
- } catch (com.sun.star.lang.WrappedTargetException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't create a test environment", e);
- } catch (com.sun.star.container.NoSuchElementException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't create a test environment", e);
- } catch (com.sun.star.lang.IllegalArgumentException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't create a test environment", e);
- }
+ mDataPilotTableObject = (XInterface) AnyConverter.toObject(
+ new Type(XInterface.class),DPT.getByName(DPT.getElementNames()[0]));
XIndexAccess IA = DPDsc.getDataPilotFields();
- try {
- mDataPilotFieldObject = (XInterface)AnyConverter.toObject(
- new Type(XInterface.class),IA.getByIndex(0));
- } catch (com.sun.star.lang.WrappedTargetException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't get data pilot field", e);
- } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't get data pilot field", e);
- } catch (com.sun.star.lang.IllegalArgumentException e) {
- e.printStackTrace();
- throw new StatusException("Couldn't get data pilot field", e);
- }
+ mDataPilotFieldObject = (XInterface)AnyConverter.toObject(
+ new Type(XInterface.class),IA.getByIndex(0));
// Other parameters required for interface tests
param.put("OUTPUTRANGE", sCellAdress);