Skip to content

Commit e81b4d5

Browse files
committed
test: add shouldSelectMapper test for PreparedStatement to verify entity mapping
1 parent f52ff9f commit e81b4d5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/PreparedStatementTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,23 @@ void shouldReturnSingleFieldsInResult() {
157157
Assertions.assertThat(fields).isNotEmpty().hasSize(1).contains(new Object[]{"Ada", 20});
158158
}
159159

160+
@Test
161+
void shouldSelectMapper() {
162+
var communicationPreparedStatement = Mockito.mock(org.eclipse.jnosql.communication.semistructured.CommunicationPreparedStatement.class);
163+
var entity = CommunicationEntity.of("Person");
164+
entity.add("name", "Ada");
165+
entity.add("age", 20);
166+
entity.add("_id", 20);
167+
168+
Mockito.when(communicationPreparedStatement.result()).thenReturn(Stream.of(entity));
169+
MapperObserver mapperObserver = new MapperObserver(entitiesMetadata);
170+
mapperObserver.fireEntity("Person");
171+
mapperObserver.fireSelectField("Person", "name");
172+
mapperObserver.fireSelectField("Person", "age");
173+
var preparedStatement = new PreparedStatement(communicationPreparedStatement, converter, mapperObserver, entitiesMetadata);
174+
preparedStatement.setSelectMapper(selectQuery -> selectQuery);
175+
Stream<Object[]> fields = preparedStatement.result();
176+
Assertions.assertThat(fields).isNotEmpty().hasSize(1).contains(new Object[]{"Ada", 20});
177+
}
178+
160179
}

0 commit comments

Comments
 (0)