### Question:
MetaverseBeanUtil { public Object get( String id ) { BlueprintContainer service = null; if ( bundleContext == null ) { return null; } else { try { Bundle bundle = bundleContext.getBundle(); if ( bundle == null ) { return null; } Collection<ServiceReference<BlueprintContainer>> serviceReferences = bundleContext.getServiceReferences( BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=" + bundle.getSymbolicName() + ")" ); if ( serviceReferences.size() != 0 ) { ServiceReference<BlueprintContainer> reference = serviceReferences.iterator().next(); service = bundleContext.getService( reference ); } } catch ( InvalidSyntaxException e ) { } if ( service == null ) { return null; } return service.getComponentInstance( id ); } } private  MetaverseBeanUtil(); static MetaverseBeanUtil getInstance(); void setBundleContext( BundleContext bundleContext ); Object get( String id );  }### Answer:
@Test public void testGet() throws Exception { MetaverseBeanUtil instance = MetaverseBeanUtil.getInstance(); BundleContext bundleContext = mock( BundleContext.class ); Bundle bundle = mock( Bundle.class ); when( bundleContext.getBundle() ).thenReturn( bundle ); instance.setBundleContext( bundleContext ); assertNull( instance.get( BEAN_NAME ) ); ServiceReference serviceReference = mock( ServiceReference.class ); when( bundleContext.getServiceReferences( Mockito.any( Class.class ), Mockito.anyString() ) ) .thenReturn( Collections.singletonList( serviceReference ) ); assertNull( instance.get( BEAN_NAME ) ); BlueprintContainer service = mock( BlueprintContainer.class ); when( bundleContext.getService( Mockito.any( ServiceReference.class ) ) ).thenReturn( service ); Object testObject = new Object(); when( service.getComponentInstance( BEAN_NAME ) ).thenReturn( testObject ); assertEquals( testObject, instance.get( BEAN_NAME ) ); when( bundleContext.getServiceReferences( Mockito.any( Class.class ), Mockito.anyString() ) ) .thenThrow( InvalidSyntaxException.class ); assertNull( MetaverseBeanUtil.getInstance().get( BEAN_NAME ) ); }