### Question:
MetadataService extends PentahoBase { public MarshallableResultSet doQuery( Query query, Integer rowLimit ) { MetadataServiceUtil util = getMetadataServiceUtil(); org.pentaho.metadata.query.model.Query fullQuery = util.convertQuery( query ); QueryXmlHelper helper = new QueryXmlHelper(); String xml = helper.toXML( fullQuery ); return doXmlQuery( xml, rowLimit ); } MetadataService(); @GET @Path( "/getDatasourcePermissions" ) @Produces( { APPLICATION_JSON } ) String getDatasourcePermissions(); ModelInfo[] listBusinessModels( String domainName ); String listBusinessModelsJson( String domainName ); Model loadModel( String domainId, String modelId ); String loadModelJson( String domainId, String modelId ); MarshallableResultSet doQuery( Query query, Integer rowLimit ); MarshallableResultSet doXmlQuery( String xml, Integer rowLimit ); String doXmlQueryToJson( String xml, int rowLimit ); String doXmlQueryToCdaJson( String xml, int rowLimit ); MarshallableResultSet doJsonQuery( String json, Integer rowLimit ); String doJsonQueryToJson( String json, int rowLimit ); String doJsonQueryToCdaJson( String json, int rowLimit ); @Override Log getLogger();  }### Answer:
@Test public void testDoQuery() { when( metadataService.doQuery( any( Query.class ), anyInt() ) ).thenCallRealMethod(); when( metadataService.doXmlQuery( anyString(), any( Integer.class ) ) ).thenCallRealMethod(); when( metadataServiceUtil.convertQuery( any( Query.class ) ) ).thenCallRealMethod(); when( metadataServiceUtil.getCategory( anyString(), any( LogicalModel.class ) ) ).thenCallRealMethod(); MarshallableResultSet marshallableResultSet = getMarshallableResultSet(); when( metadataService.getMarshallableResultSet() ).thenReturn( marshallableResultSet ); Query query = buildQuery(); MarshallableResultSet marshallableResultSetReturned = metadataService.doQuery( query, ROWS ); MarshallableRow[] rows = marshallableResultSetReturned.getRows(); String[] cell = rows[0].getCell(); MarshallableColumnNames columnNames = marshallableResultSetReturned.getColumnNames(); String[] columnName = columnNames.getColumnName(); Assert.assertTrue( rows.length <= ROWS ); Assert.assertTrue( cell[0].equals( RESULT ) ); Assert.assertTrue( columnName[0].equals( COLUMN_NAME ) ); }