KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > TestCloneSheet


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.hssf.usermodel;
20
21 import java.io.File JavaDoc;
22 import java.io.FileInputStream JavaDoc;
23 import java.io.FileOutputStream JavaDoc;
24
25 import junit.framework.TestCase;
26
27 import org.apache.poi.hssf.util.Region;
28 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
29
30 /**
31  * Test the ability to clone a sheet.
32  * If adding new records that belong to a sheet (as opposed to a book)
33  * add that record to the sheet in the testCloneSheetBasic method.
34  * @author avik
35  */

36 public class TestCloneSheet extends TestCase {
37
38     public TestCloneSheet(String JavaDoc arg0) {
39         super(arg0);
40     }
41     
42     public void testCloneSheetBasic(){
43         try{
44             HSSFWorkbook b = new HSSFWorkbook();
45             HSSFSheet s = b.createSheet("Test");
46             s.addMergedRegion(new Region((short)0,(short)0,(short)1,(short)1));
47             HSSFSheet clonedSheet = b.cloneSheet(0);
48             
49             assertEquals("One merged area", 1, clonedSheet.getNumMergedRegions());
50
51         }
52         catch(Exception JavaDoc e){e.printStackTrace();fail(e.getMessage());}
53     }
54
55    /**
56     * Ensures that pagebreak cloning works properly
57     *
58     */

59    public void testPageBreakClones() {
60       HSSFWorkbook b = new HSSFWorkbook();
61       HSSFSheet s = b.createSheet("Test");
62       s.setRowBreak(3);
63       s.setColumnBreak((short)6);
64       
65       HSSFSheet clone = b.cloneSheet(0);
66       assertTrue("Row 3 not broken", clone.isRowBroken(3));
67       assertTrue("Column 6 not broken", clone.isColumnBroken((short)6));
68       
69       s.removeRowBreak(3);
70       
71       assertTrue("Row 3 still should be broken", clone.isRowBroken(3));
72    }
73    
74 }
75
Popular Tags