mil.dod.th.ose.test/src/mil/dod/th/ose/test/BundleContextMocker.java
public static BundleContext createBundleContextEventFilter()
    {
        BundleContext context = createBasicMock();
        try
        {
            when(context.createFilter(anyString())).thenAnswer(new Answer<Filter>()
            {
                @Override
                public Filter answer(InvocationOnMock invocation) throws Throwable
                {
                    final String filter = (String)invocation.getArguments()[0];
                    final String eventTopic = filter.contains("(&(")
                        ? filter.substring(3, filter.indexOf(")")) : filter.substring(1, filter.length() - 1);
                    final String eventFilter = filter.contains(")(") 
                        ? filter.substring(filter.indexOf(")(") + 2, filter.length() - 2) : null;
                    
                    return new Filter()
                    {
                        
                        @Override
                        public boolean matchCase(Dictionary<String, ?> dictionary)
                        {
                            if (dictionary.get(EventConstants.EVENT_TOPIC).equals(eventTopic))
                            {
                                if (eventFilter == null && dictionary.get(EventConstants.EVENT_FILTER) == null)
                                {
                                    return true;
                                }
                                else if (eventFilter != null && dictionary.get(EventConstants.EVENT_FILTER) != null)
                                {
                                    return dictionary.get(EventConstants.EVENT_FILTER).equals(eventFilter);
                                }
                                
                                return false;
                            }
                            
                            return false;
                        }
                        
                        @Override
                        public boolean match(Dictionary<String, ?> dictionary)
                        {
                            return false;
                        }
                        
                        @Override
                        public boolean match(ServiceReference<?> reference)
                        {
                            return false;
                        }

                        @Override
                        public boolean matches(Map<String, ?> arg0) 
                        {
                            return false;
                        }
                    };
                }
            });
        }
        catch (InvalidSyntaxException e)
        {
            // inside when, never happens
        }
        
        return context;
    }
/**
     * Used for creating Filters for use with EventAdmin.
     * 
     * Assumes filter string is (&amp;(event.topic)(event.filter))
     */
Used for creating Filters for use with EventAdmin.


Used for creating Filters for use with EventAdmin .
public static BundleContext createBundleContextEventFilter()
    {
        BundleContext context = createBasicMock();
        try
        {
            when(context.createFilter(anyString())).thenAnswer(new Answer<Filter>()
            {
                @Override
                public Filter answer(InvocationOnMock invocation) throws Throwable
                {
                    final String filter = (String)invocation.getArguments()[0];
                    final String eventTopic = filter.contains("(&(")
                        ? filter.substring(3, filter.indexOf(")")) : filter.substring(1, filter.length() - 1);
                    final String eventFilter = filter.contains(")(") 
                        ? filter.substring(filter.indexOf(")(") + 2, filter.length() - 2) : null;
                    return new Filter()
                    {
                        @Override
                        public boolean matchCase(Dictionary<String, ?> dictionary)
                        {
                            if (dictionary.get(EventConstants.EVENT_TOPIC).equals(eventTopic))
                            {
                                if (eventFilter == null && dictionary.get(EventConstants.EVENT_FILTER) == null)
                                {
                                    return true;
                                }
                                else if (eventFilter != null && dictionary.get(EventConstants.EVENT_FILTER) != null)
                                {
                                    return dictionary.get(EventConstants.EVENT_FILTER).equals(eventFilter);
                                }
                                return false;
                            }
                            return false;
                        }
                        @Override
                        public boolean match(Dictionary<String, ?> dictionary)
                        {
                            return false;
                        }
                        @Override
                        public boolean match(ServiceReference<?> reference)
                        {
                            return false;
                        }
                        @Override
                        public boolean matches(Map<String, ?> arg0) 
                        {
                            return false;
                        }
                    };
                }
            });
        }
        catch (InvalidSyntaxException e)
        {
        }
        return context;
    }
public static BundleContext createBundleContextEventFilter ( ) { BundleContext context = createBasicMock ( ) ; try { when ( context . createFilter ( anyString ( ) ) ) . thenAnswer ( new Answer < Filter > ( ) { @ Override public Filter answer ( InvocationOnMock invocation ) throws Throwable { final String filter = ( String ) invocation . getArguments ( ) [ 0 ] ; final String eventTopic = filter . contains ( "(&(" ) ? filter . substring ( 3 , filter . indexOf ( ")" ) ) : filter . substring ( 1 , filter . length ( ) - 1 ) ; final String eventFilter = filter . contains ( ")(" ) ? filter . substring ( filter . indexOf ( ")(" ) + 2 , filter . length ( ) - 2 ) : null ; return new Filter ( ) { @ Override public boolean matchCase ( Dictionary < String , ? > dictionary ) { if ( dictionary . get ( EventConstants . EVENT_TOPIC ) . equals ( eventTopic ) ) { if ( eventFilter == null && dictionary . get ( EventConstants . EVENT_FILTER ) == null ) { return true ; } else if ( eventFilter != null && dictionary . get ( EventConstants . EVENT_FILTER ) != null ) { return dictionary . get ( EventConstants . EVENT_FILTER ) . equals ( eventFilter ) ; } return false ; } return false ; } @ Override public boolean match ( Dictionary < String , ? > dictionary ) { return false ; } @ Override public boolean match ( ServiceReference < ? > reference ) { return false ; } @ Override public boolean matches ( Map < String , ? > arg0 ) { return false ; } } ; } } ) ; } catch ( InvalidSyntaxException e ) { } return context ; }
Used for creating Filters for use with EventAdmin.
Used for creating Filters for use with EventAdmin .
// inside when, never happens