Skip to content

Commit

Permalink
Add javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Oct 20, 2024
1 parent 52f1855 commit 3d8f2f7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@

import org.itsallcode.jdbc.ParameterMapper;

/**
* A {@link PreparedStatement} that delegates all methods and converts parameter
* value of {@link #convert(Object)} using a {@link ParameterMapper}.
*/
public class ConvertingPreparedStatement extends DelegatingPreparedStatement {

private final ParameterMapper parameterMapper;

/**
* Create a new instance.
*
* @param delegate delegate
* @param parameterMapper parameter mapper
*/
public ConvertingPreparedStatement(final PreparedStatement delegate, final ParameterMapper parameterMapper) {
super(delegate);
this.parameterMapper = parameterMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.itsallcode.jdbc.statement;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.itsallcode.jdbc.ParameterMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class ConvertingPreparedStatementTest {
@Mock
PreparedStatement delegateMock;
@Mock
ParameterMapper parameterMapperMock;

@SuppressWarnings("resource")
@Test
void setObject() throws SQLException {
final Object o1 = new Object();
final Object o2 = new Object();
when(parameterMapperMock.map(same(o1))).thenReturn(o2);
new ConvertingPreparedStatement(delegateMock, parameterMapperMock).setObject(1, o1);
verify(delegateMock).setObject(eq(1), same(o2));
}
}

0 comments on commit 3d8f2f7

Please sign in to comment.