001: package org.drools.decisiontable.parser.xls;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.Map;
020:
021: import junit.framework.TestCase;
022: import jxl.Cell; //import jxl.CellFeatures;
023: import jxl.CellType;
024: import jxl.Range;
025: import jxl.format.CellFormat;
026:
027: /**
028: * @author <a href="mailto:michael.neale@gmail.com"> Michael Neale</a>
029: *
030: * Some unit tests for the corners of ExcelParser that are not explicitly
031: * covered by integration tests.
032: */
033: public class ExcelParserTest extends TestCase {
034:
035: public void testRemoveTrailingZero() {
036: String test = "1.0";
037: assertEquals("1", ExcelParser.removeTrailingZero(test));
038:
039: test = "42.0";
040: assertEquals("42", ExcelParser.removeTrailingZero(test));
041:
042: test = "42";
043: assertEquals("42", ExcelParser.removeTrailingZero(test));
044:
045: }
046:
047: /**
048: * This should test to see if a cell is in a certain range or not.
049: * If it is in a merged range, then it should return the top left cell.
050: * @throws Exception
051: */
052: public void testCellMerge() throws Exception {
053: ExcelParser parser = new ExcelParser((Map) null);
054:
055: Range[] ranges = new Range[1];
056:
057: MockRange r1 = new MockRange();
058: ranges[0] = r1;
059: r1.topLeft = new MockCell();
060: r1.topLeft.row = 2;
061: r1.topLeft.column = 2;
062: r1.topLeft.contents = "first";
063:
064: r1.bottomRight = new MockCell();
065: r1.bottomRight.column = 5;
066: r1.bottomRight.row = 7;
067: r1.bottomRight.contents = "last";
068:
069: MockCell cell = new MockCell();
070: cell.contents = "test";
071: cell.row = 1;
072: cell.column = 1;
073:
074: assertNull(parser.getRangeIfMerged(cell, ranges));
075:
076: cell = new MockCell();
077: cell.contents = "wrong";
078: cell.row = 2;
079: cell.column = 5;
080:
081: assertEquals("first", parser.getRangeIfMerged(cell, ranges)
082: .getTopLeft().getContents());
083:
084: }
085:
086: static class MockCell implements Cell {
087:
088: int column;
089: int row;
090: String contents;
091:
092: public CellFormat getCellFormat() {
093: return null;
094: }
095:
096: public int getColumn() {
097: return column;
098: }
099:
100: public String getContents() {
101: return contents;
102: }
103:
104: public int getRow() {
105: return row;
106: }
107:
108: public CellType getType() {
109: return null;
110: }
111:
112: public boolean isHidden() {
113: return false;
114: }
115:
116: }
117:
118: static class MockRange implements Range {
119:
120: MockCell bottomRight;
121: MockCell topLeft;
122:
123: public Cell getBottomRight() {
124: return bottomRight;
125: }
126:
127: public int getFirstSheetIndex() {
128: return 0;
129: }
130:
131: public int getLastSheetIndex() {
132: return 0;
133: }
134:
135: public Cell getTopLeft() {
136: return topLeft;
137: }
138:
139: }
140:
141: }
|