### Question:
DynamicResourceUpdater implements Runnable { @Override public void run() { ApplicationContext ctx = ApplicationContext.getInstance(); Date date = new Date(); LOGGER.debug("Starting update process on {}...",date); try(WriteSession session = ctx.createSession()) { ResourceSnapshot snapshot = session.find(ResourceSnapshot.class,this.name,DynamicResourceHandler.class); DataSet dataSet = this.handler.get(snapshot); Individual<?,?> individual = dataSet. individualOfId( ManagedIndividualId. createId(this.name, DynamicResourceHandler.ID)); individual. addValue( REFRESHED_ON, Literals.of(date).dateTime()); this.handler.update(this.name, dataSet); session.modify(snapshot); session.saveChanges(); } catch (Exception e) { LOGGER.error("Could not update resource",e); } finally { LOGGER.debug("Finalized update process"); } } DynamicResourceUpdater(DynamicResourceHandler handler, Name<String> name); @Override void run();  }### Answer:
@Test public void testRun(@Mocked final WriteSession session, @Mocked final ResourceSnapshot snapshot) throws Exception { DynamicResourceHandler handler = new DynamicResourceHandler(); DynamicResourceUpdater sut = workingSut(handler,session,snapshot); sut.run(); verifyResult(snapshot,handler,true); }
@Test public void testRun$failure$runtimeException(@Mocked final WriteSession session, @Mocked final ResourceSnapshot snapshot) throws Exception { DynamicResourceHandler handler = new DynamicResourceHandler(); DynamicResourceUpdater sut = runtimeFailureSut(handler,session,snapshot); sut.run(); verifyResult(snapshot,handler,false); }
@Test public void testRun$failure$nullWriteSession(@Mocked final WriteSession session, @Mocked final ResourceSnapshot snapshot) throws Exception { DynamicResourceHandler handler = new DynamicResourceHandler(); DynamicResourceUpdater sut = nullWriteSessionSut(handler,session,snapshot); sut.run(); verifyResult(snapshot,handler,false); }
@Test public void testRun$failure$writeSessionCreationException(@Mocked final WriteSession session, @Mocked final ResourceSnapshot snapshot) throws Exception { DynamicResourceHandler handler = new DynamicResourceHandler(); DynamicResourceUpdater sut = writeSessionCreationFailureSut(handler,session,snapshot); sut.run(); verifyResult(snapshot,handler,false); }
@Test public void testRun$failure$writeSessionException(@Mocked final WriteSession session, @Mocked final ResourceSnapshot snapshot) throws Exception { DynamicResourceHandler handler = new DynamicResourceHandler(); DynamicResourceUpdater sut = writeSessionFailureSut(handler,session,snapshot); sut.run(); verifyResult(snapshot,handler,true); }
@Test public void testRun$failure$writeSessionTerminationFailure(@Mocked final WriteSession session, @Mocked final ResourceSnapshot snapshot) throws Exception { DynamicResourceHandler handler = new DynamicResourceHandler(); DynamicResourceUpdater sut = writeSessionTerminationSut(handler,session,snapshot); sut.run(); verifyResult(snapshot,handler,true); }
@Test public void testRun$failure$writeSessionAndTerminationFailure(@Mocked final WriteSession session, @Mocked final ResourceSnapshot snapshot) throws Exception { DynamicResourceHandler handler = new DynamicResourceHandler(); DynamicResourceUpdater sut = writeSessionFailureWithTerminationFailureSut(handler,session,snapshot); sut.run(); verifyResult(snapshot,handler,true); }