Skip to content

Commit

Permalink
(#28) Added truncate implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Mar 22, 2019
1 parent 8699871 commit 3cd3e64
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ public void close() {
}

@Override
public void truncate(final long len) throws SQLException {

public void truncate(final long len) {
if(fitsInInt(len)){
stringBuilder.delete((int)len, stringBuilder.length());
}
}

@Override
Expand Down Expand Up @@ -170,12 +172,16 @@ private long applyOffset(final long pos) {
* @param stringToSet The String to set the content from.
* @param offset the index of the first character of {@code stringToSet} to be inserted. Starting at 0.
* @param length The length of the string to set.
* @return
* @return The length of the string that has been set
*/
private int setContent(final StringBuilder stringBuilder, final int position, final String stringToSet, final int offset, final int length) {
final boolean expandsString = position + length > stringBuilder.length();

if(expandsString){
private int setContent(final StringBuilder stringBuilder,
final int position,
final String stringToSet,
final int offset,
final int length) {
final boolean expandsCurrentContent = position + length > stringBuilder.length();

if(expandsCurrentContent){
stringBuilder.delete(position, stringBuilder.length());
stringBuilder.insert(position, stringToSet.toCharArray(), offset, length);
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,22 @@ public void testSetCharacterStream() throws Exception{
assertEquals(clobContent, expectedClobContent);
}

@Test
public void testTruncate() throws Exception {

//GIVEN
citrusClob.setString(1, sampleText);
final String expectedTruncatedString = "Keep calm";
final long desiredLength = expectedTruncatedString.length();

//WHEN
citrusClob.truncate(desiredLength);

//THEN
final String clobContent = IOUtils.toString(citrusClob.getCharacterStream());
assertEquals(clobContent, expectedTruncatedString);
}

@Test
public void testEqualsContract(){
EqualsVerifier
Expand Down

0 comments on commit 3cd3e64

Please sign in to comment.