SQLToCellValueConverter implements ToCellValueConverter { @Override public CellValue from(final Object o) { try { if (o instanceof Clob) { final Clob clob = (Clob) o; return new StringValue(clob.getSubString(1, (int) clob.length())); } else if (o instanceof SQLXML) { final SQLXML sqlxml = (SQLXML) o; final String string = sqlxml.getString().trim(); return new StringValue(string); } else if (o instanceof Date) { final long time = ((Date) o).getTime(); return new DateValue(new Date(time)); } else if (o instanceof Time) { final long time = ((Time) o).getTime(); return new DateValue(new Date(time)); } else if (o instanceof Timestamp) { final long time = ((Timestamp) o).getTime(); return new DateValue(new Date(time)); } else { final TimeValue timeValue = this.intervalConverter.castToInterval(o); if (timeValue == null) { return this.converter.from(o); } else { return timeValue; } } } catch (final SQLException e) { throw new RuntimeException(e); } } SQLToCellValueConverter(final ToCellValueConverter converter,
                            final IntervalConverter intervalConverter, final Charset charset); static SQLToCellValueConverter create(final IntervalConverter intervalConverter,
                                                 final String currency, final Charset charset); @Override CellValue from(final Object o); @Override CellValue from(final CellType type, final Object o);  }
@Test public void testFromBase() throws FastOdsException { PowerMock.resetAll(); EasyMock.expect(this.wrappedConverter.from(CellType.FLOAT, FASTODS)) .andReturn(EMPTY_STRING_VALUE); PowerMock.replayAll(); Assert.assertEquals(EMPTY_STRING_VALUE, this.converter.from(CellType.FLOAT, FASTODS)); PowerMock.verifyAll(); }
@Test public void testFromBlob() { final MockBlob blob = new MockBlob(FASTODS.getBytes(CHARSET)); PowerMock.resetAll(); EasyMock.expect(this.intervalConverter.castToInterval(blob)).andReturn(null); EasyMock.expect(this.wrappedConverter.from(blob)).andReturn(EMPTY_STRING_VALUE); PowerMock.replayAll(); Assert.assertEquals(EMPTY_STRING_VALUE, this.converter.from(blob)); PowerMock.verifyAll(); }
@Test public void testFromHintBlob() throws FastOdsException { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new StringValue(FASTODS), this.converter.from(CellType.STRING, new MockBlob(FASTODS.getBytes(CHARSET)))); PowerMock.verifyAll(); }
@Test(expected = FastOdsException.class) public void testFromHintFailBlob() throws FastOdsException { final MockBlob blob = new MockBlob(FASTODS.getBytes(CHARSET)); EasyMock.expect(this.wrappedConverter.from(CellType.VOID, blob)) .andThrow(new FastOdsException("")); PowerMock.replayAll(); this.converter.from(CellType.VOID, blob); PowerMock.verifyAll(); }
@Test public void testFromClob() { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new StringValue(FASTODS), this.converter.from(new MockClob(FASTODS))); PowerMock.verifyAll(); }
@Test public void testFromHintClob() throws FastOdsException { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new StringValue(FASTODS), this.converter.from(CellType.STRING, new MockClob(FASTODS))); PowerMock.verifyAll(); }
@Test(expected = FastOdsException.class) public void testFromHintFailClob() throws FastOdsException { final MockClob clob = new MockClob(FASTODS); EasyMock.expect(this.wrappedConverter.from(CellType.VOID, clob)) .andThrow(new FastOdsException("")); PowerMock.replayAll(); this.converter.from(CellType.VOID, clob); PowerMock.verifyAll(); }
@Test public void testFromSQLXML() { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new StringValue(XML_FASTODS), this.converter.from(new MockSQLXML(XML_FASTODS_RAW))); PowerMock.verifyAll(); }
@Test public void testFromString() { PowerMock.resetAll(); EasyMock.expect(this.intervalConverter.castToInterval("test")).andReturn(null); EasyMock.expect(this.wrappedConverter.from("test")).andReturn(new StringValue("test")); PowerMock.replayAll(); Assert.assertEquals(new StringValue("test"), this.converter.from("test")); PowerMock.verifyAll(); }
@Test public void testFromHintString() throws FastOdsException { PowerMock.resetAll(); EasyMock.expect(this.wrappedConverter.from(CellType.STRING, "test")) .andReturn(new StringValue("test")); PowerMock.replayAll(); Assert.assertEquals(new StringValue("test"), this.converter.from(CellType.STRING, "test")); PowerMock.verifyAll(); }
@Test public void testFromHintSQLXML() throws FastOdsException { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new StringValue(XML_FASTODS), this.converter.from(CellType.STRING, new MockSQLXML(XML_FASTODS_RAW))); PowerMock.verifyAll(); }
@Test(expected = FastOdsException.class) public void testFromHintFailSQLXML() throws FastOdsException { PowerMock.resetAll(); final MockSQLXML sqlxml = new MockSQLXML(FASTODS); EasyMock.expect(this.wrappedConverter.from(CellType.VOID, sqlxml)) .andThrow(new FastOdsException("")); PowerMock.replayAll(); this.converter.from(CellType.VOID, sqlxml); PowerMock.verifyAll(); }
@Test public void testFromDate() { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new DateValue(UTIL_DATE), this.converter.from(SQL_DATE)); PowerMock.verifyAll(); }
@Test public void testFromHintDate() throws FastOdsException { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new DateValue(UTIL_DATE), this.converter.from(CellType.DATE, SQL_DATE)); PowerMock.verifyAll(); }
@Test(expected = FastOdsException.class) public void testFromHintFailDate() throws FastOdsException { PowerMock.resetAll(); EasyMock.expect(this.wrappedConverter.from(CellType.VOID, SQL_DATE)) .andThrow(new FastOdsException("")); PowerMock.replayAll(); this.converter.from(CellType.VOID, SQL_DATE); PowerMock.verifyAll(); }
@Test public void testFromTime() { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new DateValue(UTIL_DATE), this.converter.from(SQL_TIME)); PowerMock.verifyAll(); }
@Test public void testFromHintTime() throws FastOdsException { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new DateValue(UTIL_DATE), this.converter.from(CellType.DATE, SQL_TIME)); PowerMock.verifyAll(); }
@Test(expected = FastOdsException.class) public void testFromHintFailTime() throws FastOdsException { PowerMock.resetAll(); EasyMock.expect(this.wrappedConverter.from(CellType.VOID, SQL_TIME)) .andThrow(new FastOdsException("")); PowerMock.replayAll(); this.converter.from(CellType.VOID, SQL_TIME); PowerMock.verifyAll(); }
@Test public void testFromTimestamp() { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new DateValue(UTIL_DATE), this.converter.from(SQL_TS)); PowerMock.verifyAll(); }
@Test public void testFromHintTimestamp() throws FastOdsException { PowerMock.resetAll(); PowerMock.replayAll(); Assert.assertEquals(new DateValue(UTIL_DATE), this.converter.from(CellType.DATE, SQL_TS)); PowerMock.verifyAll(); }
@Test(expected = FastOdsException.class) public void testFromHintFailTimestamp() throws FastOdsException { PowerMock.resetAll(); EasyMock.expect(this.wrappedConverter.from(CellType.VOID, SQL_TS)) .andThrow(new FastOdsException("")); PowerMock.replayAll(); this.converter.from(CellType.VOID, SQL_TS); PowerMock.verifyAll(); }
@Test public void testFromIntervalYes() { PowerMock.resetAll(); final Object interval = new Object(); EasyMock.expect(this.intervalConverter.castToInterval(interval)).andReturn(TIME_VALUE); PowerMock.replayAll(); Assert.assertEquals(TIME_VALUE, this.converter.from(interval)); PowerMock.verifyAll(); }
@Test public void testFromIntervalNo() { PowerMock.resetAll(); final Object interval = new Object(); EasyMock.expect(this.intervalConverter.castToInterval(interval)).andReturn(null); EasyMock.expect(this.wrappedConverter.from(interval)).andReturn(EMPTY_STRING_VALUE); PowerMock.replayAll(); Assert.assertEquals(EMPTY_STRING_VALUE, this.converter.from(interval)); PowerMock.verifyAll(); }
@Test public void testFromHintIntervalYes() throws FastOdsException { PowerMock.resetAll(); final Object interval = new Object(); EasyMock.expect(this.intervalConverter.castToInterval(interval)).andReturn(TIME_VALUE); PowerMock.replayAll(); Assert.assertEquals(TIME_VALUE, this.converter.from(CellType.TIME, interval)); PowerMock.verifyAll(); }
@Test(expected = FastOdsException.class) public void testFromHintIntervalNo() throws FastOdsException { PowerMock.resetAll(); final Object interval = new Object(); EasyMock.expect(this.intervalConverter.castToInterval(interval)).andReturn(null); EasyMock.expect(this.wrappedConverter.from(CellType.TIME, interval)) .andThrow(new FastOdsException("")); PowerMock.replayAll(); this.converter.from(CellType.TIME, interval); PowerMock.verifyAll(); }
@Test(expected = FastOdsException.class) public void testFromHintFailInterval() throws FastOdsException { PowerMock.resetAll(); final Object interval = new Object(); EasyMock.expect(this.wrappedConverter.from(CellType.VOID, interval)) .andThrow(new FastOdsException("")); PowerMock.replayAll(); this.converter.from(CellType.VOID, interval); PowerMock.verifyAll(); }