### Question:
SwitchToSlaveCopyThenBranch extends SwitchToSlave { private void copyStore( URI masterUri, URI me, CancellationRequest cancellationRequest, MoveAfterCopy moveAfterCopy ) throws Throwable { boolean success = false; monitor.storeCopyStarted(); LifeSupport copyLife = new LifeSupport(); try { MasterClient masterClient = newMasterClient( masterUri, me, null, copyLife ); copyLife.start(); boolean masterIsOld = MasterClient.CURRENT.compareTo( masterClient.getProtocolVersion() ) > 0; if ( masterIsOld ) { throw new UnableToCopyStoreFromOldMasterException( MasterClient.CURRENT.getApplicationProtocol(), masterClient.getProtocolVersion().getApplicationProtocol() ); } else { copyStoreFromMaster( masterClient, cancellationRequest, moveAfterCopy ); success = true; } } finally { monitor.storeCopyCompleted( success ); copyLife.shutdown(); } } SwitchToSlaveCopyThenBranch( DatabaseLayout databaseLayout, LogService logService, FileSystemAbstraction fileSystemAbstraction, Config config,
            HaIdGeneratorFactory idGeneratorFactory, DelegateInvocationHandler<Master> masterDelegateHandler,
            ClusterMemberAvailability clusterMemberAvailability, RequestContextFactory requestContextFactory, PullerFactory pullerFactory,
            Iterable<KernelExtensionFactory<?>> kernelExtensions, MasterClientResolver masterClientResolver, Monitor monitor,
            StoreCopyClientMonitor storeCopyMonitor, Supplier<NeoStoreDataSource> neoDataSourceSupplier,
            Supplier<TransactionIdStore> transactionIdStoreSupplier, Function<Slave,SlaveServer> slaveServerFactory, UpdatePuller updatePuller,
            PageCache pageCache, Monitors monitors, Supplier<DatabaseTransactionStats> transactionStatsSupplier );   SwitchToSlaveCopyThenBranch( DatabaseLayout databaseLayout,
                                 LogService logService,
                                 Config config,
                                 HaIdGeneratorFactory idGeneratorFactory,
                                 DelegateInvocationHandler<Master> masterDelegateHandler,
                                 ClusterMemberAvailability clusterMemberAvailability,
                                 RequestContextFactory requestContextFactory,
                                 PullerFactory pullerFactory,
                                 MasterClientResolver masterClientResolver,
                                 SwitchToSlave.Monitor monitor,
                                 StoreCopyClient storeCopyClient,
                                 Supplier<NeoStoreDataSource> neoDataSourceSupplier,
                                 Supplier<TransactionIdStore> transactionIdStoreSupplier,
                                 Function<Slave, SlaveServer> slaveServerFactory,
                                 UpdatePuller updatePuller,
                                 PageCache pageCache,
                                 Monitors monitors,
                                 Supplier<DatabaseTransactionStats> transactionStatsSupplier );   }### Answer:
@Test public void shouldRestartServicesIfCopyStoreFails() throws Throwable { when( updatePuller.tryPullUpdates() ).thenReturn( true ); PageCache pageCacheMock = mockPageCache(); StoreCopyClient storeCopyClient = mock( StoreCopyClient.class ); doThrow( new RuntimeException() ).doNothing().when( storeCopyClient ).copyStore( any( StoreCopyClient.StoreCopyRequester.class ), any( CancellationRequest.class ), any( MoveAfterCopy.class ) ); SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy( pageCacheMock, storeCopyClient ); URI localhost = getLocalhostUri(); try { switchToSlave.switchToSlave( mock( LifeSupport.class ), localhost, localhost, mock( CancellationRequest.class ) ); fail( "Should have thrown an Exception" ); } catch ( RuntimeException e ) { verify( requestContextFactory, never() ).start(); verify( switchToSlave ).cleanStoreDir(); switchToSlave.switchToSlave( mock( LifeSupport.class ), localhost, localhost, mock( CancellationRequest.class ) ); verify( requestContextFactory ).start(); } }