### Question:
LocalDhisResourceRepositoryTemplate { public boolean isLocal( @Nonnull String id ) { final RequestCacheContext context = requestCacheService.getCurrentRequestCacheContext(); final Optional<LocalDhisResourceRepository<T>> repository = getRepository( context ); return repository.map( r -> r.findOneById( id ).map( DhisResource::isLocal ).orElse( false ) ).orElse( false ); } LocalDhisResourceRepositoryTemplate( @Nonnull Class<T> resourceClass, @Nonnull RequestCacheService requestCacheService,
        @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ); @Nonnull T save( @Nonnull T resource ); @Nonnull T save( @Nonnull T resource, @Nullable Consumer<T> localResourceConsumer ); boolean deleteById( @Nonnull String id, @Nonnull Function<String, T> prototypeFunction ); @Nonnull Optional<T> findOneById( @Nonnull String id, @Nonnull Function<String, T> callback ); boolean isLocal( @Nonnull String id ); @Nonnull Collection<T> find( @Nonnull Predicate<T> filter, @Nonnull Supplier<Collection<T>> collectionSupplier, boolean localOnly, @Nonnull String methodName, @Nonnull Object... args ); @Nonnull Collection<T> find( @Nullable String trackedEntityInstanceId, @Nonnull Predicate<T> filter, @Nonnull Supplier<Collection<T>> collectionSupplier, boolean localOnly, @Nonnull String methodName, @Nonnull Object... args ); static final String CONTAINER_REQUEST_CACHE_ATTRIBUTE_NAME; static final String RESOURCE_KEY_REQUEST_CACHE_ATTRIBUTE_NAME; }### Answer:
@Test public void isLocal() { final TrackedEntityInstance tei = new TrackedEntityInstance(); final Object resourceKey = new Object(); tei.setLocal( true ); Mockito.doReturn( requestCacheContext ).when( requestCacheService ).getCurrentRequestCacheContext(); Mockito.doReturn( resourceRepositoryContainer ).when( requestCacheContext ).getAttribute( Mockito.eq( LocalDhisResourceRepositoryTemplate.CONTAINER_REQUEST_CACHE_ATTRIBUTE_NAME ), Mockito.eq( LocalDhisResourceRepositoryContainer.class ) ); Mockito.doReturn( resourceKey ).when( requestCacheContext ).getAttribute( Mockito.eq( LocalDhisResourceRepositoryTemplate.RESOURCE_KEY_REQUEST_CACHE_ATTRIBUTE_NAME ), Mockito.eq( Object.class ) ); Mockito.doReturn( resourceRepository ).when( resourceRepositoryContainer ).getRepository( Mockito.eq( TrackedEntityInstance.class ), Mockito.same( persistCallback ) ); Mockito.doReturn( Optional.of( tei ) ).when( resourceRepository ).findOneById( Mockito.eq( "h1234567890" ) ); Assert.assertTrue( template.isLocal( "h1234567890" ) ); Mockito.verifyZeroInteractions( persistCallback ); }