PositionUtil { public CellRef newCellRef(final String address) throws ParseException, IOException { return CellAddressParser.create(this.tableNameUtil).parse(address); } PositionUtil(final TableNameUtil tableNameUtil); static PositionUtil create(); CellRef newCellRef(final String address); CellRef newCellRef(final int row, final int col); CellRef newCellRef(final Table table, final int row, final int col); String toCellAddress(final int row, final int col); String toCellAddress(final Table table, final int row, final int col); String toRangeAddress(final int row1, final int col1, final int row2, final int col2); String toRangeAddress(final Table table, final int row1, final int col1, final int row2,
                                 final int col2); void checkTableName(final CharSequence name); static final int ALPHABET_SIZE; static final int ORD_A; }
@Test public final void testA5() throws ParseException, IOException { final CellRef CellRef = this.util.newCellRef("A5"); Assert.assertEquals(0, CellRef.getColumn()); Assert.assertEquals(4, CellRef.getRow()); }
@Test public final void testAB6666() throws ParseException, IOException { final CellRef CellRef = this.util.newCellRef("AB6666"); Assert.assertEquals(27, CellRef.getColumn()); Assert.assertEquals(6665, CellRef.getRow()); }
@Test public final void testA1() throws ParseException, IOException { final CellRef CellRef = this.util.newCellRef("A1"); Assert.assertEquals(0, CellRef.getColumn()); Assert.assertEquals(0, CellRef.getRow()); }
@Test public final void testB6() throws ParseException, IOException { final CellRef CellRef = this.util.newCellRef("B6"); Assert.assertEquals(1, CellRef.getColumn()); Assert.assertEquals(5, CellRef.getRow()); }
@Test public final void testdBd6() throws ParseException, IOException { final CellRef CellRef = this.util.newCellRef("$B$6"); Assert.assertEquals(1, CellRef.getColumn()); Assert.assertEquals(5, CellRef.getRow()); }
@Test(expected = ParseException.class) public final void testdBd6d() throws ParseException, IOException { this.util.newCellRef("$B$6$"); }
@Test(expected = ParseException.class) public final void testddBd6d() throws ParseException, IOException { this.util.newCellRef("$$B$6$"); }
@Test(expected = ParseException.class) public final void testMinusAB6666() throws ParseException, IOException { this.util.newCellRef("-AB6666"); }
@Test(expected = ParseException.class) public final void testWeirdPos1() throws ParseException, IOException { this.util.newCellRef("_6"); }
@Test(expected = ParseException.class) public final void testWeirdPos2() throws ParseException, IOException { this.util.newCellRef("@6"); }
@Test(expected = ParseException.class) public final void testWeirdPos3() throws ParseException, IOException { this.util.newCellRef("A@6"); }
@Test(expected = ParseException.class) public final void testWeirdPos4() throws ParseException, IOException { this.util.newCellRef("A_6"); }
@Test(expected = ParseException.class) public final void testWeirdPos5() throws ParseException, IOException { this.util.newCellRef("AA$."); }
@Test(expected = ParseException.class) public final void testWeirdPos6() throws ParseException, IOException { this.util.newCellRef("AA$A"); }
@Test(expected = ParseException.class) public final void testWeirdPos7() throws ParseException, IOException { this.util.newCellRef("AA$9."); }
@Test(expected = ParseException.class) public final void testWeirdPos8() throws ParseException, IOException { this.util.newCellRef("AA$9A"); }
@Test public final void testEquals() throws ParseException, IOException { final CellRef CellRef1 = this.util.newCellRef("A5"); Assert.assertEquals(CellRef1, CellRef1); Assert.assertNotEquals(CellRef1, null); final CellRef CellRef2 = this.util.newCellRef(4, 0); Assert.assertEquals(CellRef1, CellRef2); final CellRef CellRef3 = this.util.newCellRef(5, 0); Assert.assertNotEquals(CellRef1, CellRef3); final CellRef CellRef4 = this.util.newCellRef(4, 1); Assert.assertNotEquals(CellRef1, CellRef4); Assert.assertEquals(34596, CellRef1.hashCode()); }
@Test public final void testAddress() { final CellRef CellRef1 = this.util.newCellRef(0, 0); Assert.assertEquals("A1", CellRef1.toString()); final CellRef CellRef2 = this.util.newCellRef(1, 2); Assert.assertEquals("C2", CellRef2.toString()); final CellRef CellRef3 = this.util.newCellRef(0, 25); Assert.assertEquals("Z1", CellRef3.toString()); final CellRef CellRef4 = this.util.newCellRef(0, 26); Assert.assertEquals("AA1", CellRef4.toString()); final CellRef CellRef5 = this.util.newCellRef(0, 52); Assert.assertEquals("BA1", CellRef5.toString()); final CellRef CellRef6 = this.util.newCellRef(0, 1023); Assert.assertEquals("AMJ1", CellRef6.toString()); }
@Test public void testGetCellRef() { final Table t = PowerMock.createMock(Table.class); PowerMock.resetAll(); EasyMock.expect(t.getName()).andReturn("no problem"); PowerMock.replayAll(); final String cellAddress = this.util.newCellRef(t, 0, 0).toString(); PowerMock.verifyAll(); Assert.assertEquals("'no problem'.A1", cellAddress); }