### Question:
MetaverseUtil { public static void addLineageGraph( final IDocument document, Graph graph ) throws MetaverseException { if ( document == null ) { throw new MetaverseException( Messages.getString( "ERROR.Document.IsNull" ) ); } IDocumentController docController = MetaverseUtil.getDocumentController(); if ( docController != null ) { IMetaverseBuilder metaverseBuilder = new MetaverseBuilder( graph ); docController.setMetaverseBuilder( metaverseBuilder ); List<IDocumentAnalyzer> matchingAnalyzers = docController.getDocumentAnalyzers( "ktr" ); if ( matchingAnalyzers != null ) { for ( IDocumentAnalyzer analyzer : matchingAnalyzers ) { if ( analyzer instanceof IClonableDocumentAnalyzer ) { analyzer = ( (IClonableDocumentAnalyzer) analyzer ).cloneAnalyzer(); } else { log.debug( Messages.getString( "WARNING.CannotCloneAnalyzer" ), analyzer ); } Runnable analyzerRunner = getAnalyzerRunner( analyzer, document ); Graph g = ( graph != null ) ? graph : new TinkerGraph(); Future<Graph> transAnalysis = LineageGraphCompletionService.getInstance().submit( analyzerRunner, g ); LineageGraphMap.getInstance().put( document.getContent(), transAnalysis ); } } } }  static IDocumentController getDocumentController(); static void setDocumentController( IDocumentController docController ); static IDocument createDocument(
    INamespace namespace,
    Object content,
    String id,
    String name,
    String extension,
    String mimeType ); static void addLineageGraph( final IDocument document, Graph graph ); static void enhanceEdge( Edge edge ); static void enhanceVertex( Vertex vertex ); static Operations convertOperationsStringToMap( String operations ); static Runnable getAnalyzerRunner( final IDocumentAnalyzer analyzer, final IDocument document ); static void delay(); static final String MESSAGE_PREFIX_NODETYPE; static final String MESSAGE_PREFIX_LINKTYPE; static final String MESSAGE_PREFIX_CATEGORY; static final String MESSAGE_FAILED_PREFIX; }### Answer:
@Test( expected = MetaverseException.class ) public void testAddLineageGraphNullDocument() throws Exception { MetaverseUtil.addLineageGraph( null, null ); }
@Test public void testAddLineageGraph() throws Exception { IDocument document = mock( IDocument.class ); when( document.getName() ).thenReturn( "myDoc" ); Object content = new Object(); when( document.getContent() ).thenReturn( content ); IDocumentController documentController = mock( IDocumentController.class, withSettings().extraInterfaces( IRequiresMetaverseBuilder.class ) ); List<IDocumentAnalyzer> analyzers = new ArrayList<IDocumentAnalyzer>(); when( documentController.getDocumentAnalyzers( Mockito.anyString() ) ).thenReturn( analyzers ); MetaverseUtil.documentController = documentController; MetaverseUtil.addLineageGraph( document, null ); IDocumentAnalyzer<IMetaverseNode> documentAnalyzer = mock( IDocumentAnalyzer.class ); when( documentAnalyzer.analyze( Mockito.any( IComponentDescriptor.class ), Mockito.any( IDocument.class ) ) ) .thenReturn( mock( IMetaverseNode.class ) ); analyzers.add( documentAnalyzer ); Graph graph = new TinkerGraph(); MetaverseUtil.addLineageGraph( document, graph ); MetaverseUtil.addLineageGraph( document, null ); }