### Question:
MetadataService extends PentahoBase { public ModelInfo[] listBusinessModels( String domainName ) throws IOException { List<ModelInfo> models = new ArrayList<ModelInfo>(); IMetadataDomainRepository repo = getMetadataRepository(); if ( repo == null ) { error( Messages.getErrorString( "MetadataService.ERROR_0001_BAD_REPO" ) ); return null; } try { if ( domainName == null ) { for ( String domain : getMetadataRepository().getDomainIds() ) { getModelInfos( domain, models ); } } else { getModelInfos( domainName, models ); } } catch ( Throwable t ) { error( Messages.getErrorString( "MetadataService.ERROR_0002_BAD_MODEL_LIST" ), t ); } Collections.sort( models, new ModelInfoComparator() ); return models.toArray( new ModelInfo[ models.size() ] ); } 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 testListBusinessModels() { try { when( metadataService.listBusinessModels( anyString() ) ).thenCallRealMethod(); ModelInfo[] businessModels = metadataService.listBusinessModels( DOMAIN_ID ); Assert.assertTrue( businessModels.length == 2 ); Assert.assertTrue( businessModels[0].getModelName() == LOGICAL_MODEL_NAME ); Assert.assertTrue( businessModels[1].getModelName() == LOGICAL_MODEL_2_NAME ); businessModels = metadataService.listBusinessModels( null ); Assert.assertTrue( businessModels.length == 2 ); Assert.assertTrue( businessModels[0].getModelName() == LOGICAL_MODEL_NAME ); Assert.assertTrue( businessModels[1].getModelName() == LOGICAL_MODEL_2_NAME ); } catch ( Exception ex ) { fail(); } }