### Question:
WritableScriptedLazyDhisResource extends AbstractWritableScriptedDhisResource implements AccessibleWritableScriptedLazyDhisResource { @ScriptExecutionForbidden @Nullable public DhisResource getDhisResource() { if ( scriptExecutionContext.hasScriptExecution() ) { throw new FatalTransformerException( "Resource instance cannot be accessed within script execution." ); } return resource; } WritableScriptedLazyDhisResource( @Nonnull DhisResource resource, @Nonnull ScriptExecutionContext scriptExecutionContext );  WritableScriptedLazyDhisResource( @Nonnull DhisResourceType resourceType, @Nonnull String resourceId, @Nonnull ScriptExecutionContext scriptExecutionContext ); @ScriptExecutionForbidden @Nullable DhisResource getDhisResource();  }### Answer:
@Test public void getDhisResourceNotSet() { final WritableScriptedLazyDhisResource resource = new WritableScriptedLazyDhisResource( DhisResourceType.TRACKED_ENTITY, "6738", scriptExecutionContext ); Assert.assertNull( resource.getDhisResource() ); }
@Test( expected = FatalTransformerException.class ) public void getDhisResourceNotSetScriptExecution() { Mockito.doReturn( true ).when( scriptExecutionContext ).hasScriptExecution(); final WritableScriptedLazyDhisResource resource = new WritableScriptedLazyDhisResource( DhisResourceType.TRACKED_ENTITY, "6738", scriptExecutionContext ); resource.getDhisResource(); }
@Test public void getDhisResource() { final TrackedEntityInstance resource = new TrackedEntityInstance(); final WritableScriptedLazyDhisResource scriptedResource = new WritableScriptedLazyDhisResource( resource, scriptExecutionContext ); Assert.assertSame( resource, scriptedResource.getDhisResource() ); }
@Test( expected = FatalTransformerException.class ) public void getDhisResourceScriptExecution() { Mockito.doReturn( true ).when( scriptExecutionContext ).hasScriptExecution(); final TrackedEntityInstance resource = new TrackedEntityInstance(); final WritableScriptedLazyDhisResource scriptedResource = new WritableScriptedLazyDhisResource( resource, scriptExecutionContext ); Assert.assertSame( resource, scriptedResource.getDhisResource() ); }