QueryImpl extends AbstractQuery implements Query { @Override public Object getSingleResult() { ensureOpen(); try { final List<?> list = getResultListImpl(); if (list.isEmpty()) { throw new NoResultException("No result found for query " + query); } if (list.size() > 1) { throw new NoUniqueResultException("Multiple results found for query " + query); } return list.get(0); } catch (OntoDriverException e) { markTransactionForRollback(); throw queryEvaluationException(e); } catch (RuntimeException e) { if (exceptionCausesRollback(e)) { markTransactionForRollback(); } throw e; } } QueryImpl(final QueryHolder query, final ConnectionWrapper connection); @Override List getResultList(); @Override Object getSingleResult(); @Override Stream getResultStream(); @Override Query setMaxResults(int maxResults); @Override Query setFirstResult(int startPosition);  }
@Test void getSingleResultReturnsUniqueResult() throws Exception { final Query q = createQuery(SELECT_QUERY); when(resultRow.getColumnCount()).thenReturn(2); when(resultSetIterator.hasNext()).thenReturn(true).thenReturn(false); when(resultRow.isBound(anyInt())).thenReturn(true); when(resultRow.getObject(anyInt())).thenReturn("str"); final Object[] result = (Object[]) q.getSingleResult(); assertEquals(2, result.length); assertEquals("str", result[0]); assertEquals("str", result[1]); verify(resultSetIterator).next(); }