### Question:
HibernateHandler implements QueryHandler { @Override public void addScalar(Query query, String alias, Class<?> type) { query.unwrap(NativeQuery.class).addScalar(alias); }  @Override void addEntity(Query query, String alias, Class<?> type); @Override void addScalar(Query query, String alias, Class<?> type); @Override boolean createNativeQueryTyped(); @SuppressWarnings("unchecked") @Override CloseableIterator<T> iterate(Query query, FactoryExpression<?> projection); @SuppressWarnings("deprecation") @Override boolean transform(Query query, FactoryExpression<?> projection); @Override boolean wrapEntityProjections();  }### Answer:
@Test public void should_add_scalar() { expect(nativeQuery.unwrap(NativeQuery.class)).andReturn(nativeQuery); expect(nativeQuery.addScalar(alias)).andReturn(nativeQuery); replay(nativeQuery); hibernateHandler.addScalar(nativeQuery, alias, classType); verify(nativeQuery); }
@Test(expected = PersistenceException.class) public void addScalar_should_throw_persistence_exception_when_invalid_query_type() { Query notSupportedQuery = createMock(QueryImpl.class); PersistenceException expectedThrow = new PersistenceException(ExceptionLocalization.buildMessage("unable_to_unwrap_jpa", new String[]{Query.class.getName(), NativeQuery.class.getName()})); expect(notSupportedQuery.unwrap(NativeQuery.class)).andThrow(expectedThrow); replay(notSupportedQuery); hibernateHandler.addScalar(notSupportedQuery, alias, classType); }