View Javadoc
1   package org.codehaus.plexus.resource.loader;
2   
3   import static org.mockito.Mockito.when;
4   import static org.mockito.Mockito.verify;
5   import static org.mockito.Mockito.verifyNoMoreInteractions;
6   import junit.framework.TestCase;
7   
8   import org.codehaus.plexus.logging.Logger;
9   import org.mockito.InjectMocks;
10  import org.mockito.Mock;
11  import org.mockito.MockitoAnnotations;
12  
13  public class URLResourceLoaderTest
14      extends TestCase
15  {
16      @Mock
17      private Logger logger;
18  
19      @InjectMocks
20      private ResourceLoader resourceLoader = new URLResourceLoader();
21  
22      @Override
23      protected void setUp()
24          throws Exception
25      {
26          MockitoAnnotations.initMocks( this );
27      }
28  
29      public void testMalformedURL()
30          throws Exception
31      {
32          when( logger.isDebugEnabled() ).thenReturn( true );
33  
34          try
35          {
36              resourceLoader.getResource( "LICENSE.txt" );
37              fail();
38          }
39          catch ( ResourceNotFoundException e )
40          {
41              verify( logger ).isDebugEnabled();
42              verify( logger ).debug( "URLResourceLoader: No valid URL 'LICENSE.txt'" );
43              verifyNoMoreInteractions( logger );
44              assertEquals( "Could not find resource 'LICENSE.txt'.", e.getMessage() );
45          }
46  
47      }
48  }