ReadEntitiesByPropertyAction extends ComponentSupport { @Nullable public List<T> execute(final ODatabaseDocumentTx db, final Set<?> values) { checkNotNull(db); checkArgument(!values.isEmpty()); String q = query + buildIn(values); List<ODocument> results = db.command(new OSQLSynchQuery<>(q)).execute(values); return newArrayList(results.stream().map(adapter::readEntity).collect(toList())); } ReadEntitiesByPropertyAction(final EntityAdapter<T> adapter, final String property); @Nullable List<T> execute(final ODatabaseDocumentTx db, final Set<?> values); @Override String toString();  }
@Test(expected = IllegalArgumentException.class) public void testEmptySetNotAccepted() { underTest.execute(db, emptySet()); }
@Test public void testExecute() { Set<String> params = ImmutableSet.of("1", "2"); ArgumentCaptor<OSQLSynchQuery> argumentCaptor = ArgumentCaptor.forClass(OSQLSynchQuery.class); OCommandRequest oCommandRequest = mock(OCommandRequest.class); when(db.command(argumentCaptor.capture())).thenReturn(oCommandRequest); when(oCommandRequest.execute(params)).thenReturn(newArrayList(new ODocument(), new ODocument())); List<Entity> results = underTest.execute(db, params); assertThat(argumentCaptor.getValue().getText(), equalTo("SELECT FROM test WHERE test IN['1','2']")); assertThat(results, notNullValue()); assertThat(results.size(), equalTo(2)); }