/*******************************************************************************
 * Copyright (c) 2012, 2013, 2014 Rüdiger Herrmann.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Rüdiger Herrmann - initial API and implementation
 *    Frank Appel - ClassnameFilters
 ******************************************************************************/
package com.codeaffine.osgi.testuite;

import static com.codeaffine.osgi.testuite.BundleTestSuite.ClassnameFilters.DEFAULT_CLASSNAME_FILTERS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;
import org.junit.runners.model.InitializationError;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.wiring.BundleWiring;

public class TestCollectorTest {

  private BundleContext bundleContext;

  @Test
    public void testCollectWithNonExistingBundle() {
      String[] nonExistingBundle =  { "no.bundle" };
      TestCollector collector = new TestCollector( bundleContext, nonExistingBundle, DEFAULT_CLASSNAME_FILTERS );

      try {
        collector.collect();
        fail();
      } catch( InitializationError expected ) {
        assertTrue( expected.getCauses().get( 0 ).getMessage().contains( nonExistingBundle[ 0 ] ) );
      }
    }

  @Test
    public void testCollectWithExistingBundle() throws InitializationError {
      String[] bundle = { createBundle().getSymbolicName() };

      TestCollector collector = new TestCollector( bundleContext, bundle, DEFAULT_CLASSNAME_FILTERS );
      Class<?>[] classes = collector.collect();

      assertEquals( 0, classes.length );
    }

  @Before
  public void setUp() {
    bundleContext = mock( BundleContext.class );
    when( bundleContext.getBundles() ).thenReturn( new Bundle[ 0 ] );
  }

  private Bundle createBundle() {
    Bundle result = mock( Bundle.class );
    when( result.getSymbolicName() ).thenReturn( "bundle.symbolic.name" );
    BundleWiring bundleWiring = mock( BundleWiring.class );
    when( result.adapt( BundleWiring.class ) ).thenReturn( bundleWiring );
    when( bundleContext.getBundles() ).thenReturn( new Bundle[] { result } );
    return result;
  }

}

@@ -1211,34 +1211,32 @@
 ntext;%0A%0A  @Test%0A
-  
   public void te
@@ -1270,26 +1270,24 @@
 dle() %7B%0A    
-  
 String%5B%5D non
@@ -1321,18 +1321,16 @@
 dle%22 %7D;%0A
-  
     Test
@@ -1442,18 +1442,14 @@
     
-  
 try %7B%0A
-  
     
@@ -1467,26 +1467,24 @@
 .collect();%0A
-  
       fail()
@@ -1489,18 +1489,16 @@
 ();%0A    
-  
 %7D catch(
@@ -1531,18 +1531,16 @@
 ted ) %7B%0A
-  
       as
@@ -1634,21 +1634,17 @@
  );%0A
-      %7D%0A
     %7D
+%0A  %7D
 %0A%0A  
@@ -1649,18 +1649,16 @@
   @Test%0A
-  
   public
@@ -1728,18 +1728,16 @@
 r %7B%0A    
-  
 String%5B%5D
@@ -1785,18 +1785,16 @@
 e() %7D;%0A%0A
-  
     Test
@@ -1890,18 +1890,16 @@
  );%0A    
-  
 Class%3C?%3E
@@ -1933,26 +1933,24 @@
 ect();%0A%0A    
-  
 assertEquals
@@ -1968,26 +1968,24 @@
 s.length );%0A
-  
   %7D%0A%0A  @Befo

Fix indentation