Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011 UrsaJ Ltd (http://ursaj.com) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.ursaj.hfs.tools;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
 
 import static com.ursaj.hfs.HfsTestUtils.RND;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;

 
 public class HfsDbFileServiceAdapterTest {

    
Test method wrapping.

Throws:
java.lang.Exception In case of any exception.
 
     @Test
     public void testMethodWrapping() throws Exception {
         DataSource dataSource = mock(DataSource.class);
         Connection connection = mock(Connection.class);
         @SuppressWarnings("unchecked"HfsDbFileServiceAdapter<Integerdelegate = mock(HfsDbFileServiceAdapter.class);
 
         HfsDbFileServiceAdapter<Integerservice = new Delegate<>(delegate);
         service.setDataSource(dataSource);
         doReturn(connection).when(dataSource).getConnection();
 
 
         verifyNoMoreInteractions(delegate);
 
         final Set<UUIDfileIds = new HashSet<>(Arrays.asList(UUID.randomUUID(), UUID.randomUUID()));
         service.getFiles(fileIds);
         verify(delegate).getFiles(connectionfileIds);
         verifyNoMoreInteractions(delegate);
 
         final List<Integerfiles = Arrays.asList(1, 2, 3, .nextInt());
         service.storeFiles(files);
         verify(delegate).storeFiles(connectionfiles);
         verifyNoMoreInteractions(delegate);
 
         final UUID fileId = UUID.randomUUID();
         final Consumer<UUIDIOExceptionconsumer = new HfsConsumer<>(new ArrayList<UUID>());
         service.collectAliveFiles(fileIdconsumer);
         verify(delegate).collectAliveFiles(connectionfileIdconsumer);
         verifyNoMoreInteractions(delegate);
     }

    
Delegate-based implementation of DB file service adapter.
 
     private static final class Delegate<T> extends HfsDbFileServiceAdapter<T> {
        
Delegate to perform all actual operations.
 
         private final HfsDbFileServiceAdapter<T> delegate;

        
Constructs delegate-based implementation of DB file service adapter.

Parameters:
delegate Delegate to perform actual operations.
 
         private Delegate(HfsDbFileServiceAdapter<T> delegate) {
             this. = delegate;
         }
 
         @Override
         protected Map<UUID, T> getFiles(Connection connectionSet<UUIDfileIdsthrows SQLExceptionIOException {
             return .getFiles(connectionfileIds);
         }
 
         @Override
         protected void storeFiles(Connection connectionCollection<T> filesthrows SQLExceptionIOException {
            .storeFiles(connectionfiles);
        }
        @Override
        protected boolean collectAliveFiles(Connection connectionUUID fromIdConsumer<UUIDIOExceptionconsumer)
            throws SQLExceptionIOException {
            return .collectAliveFiles(connectionfromIdconsumer);
        }
    }
New to GrepCode? Check out our FAQ X