### Question:
AbstractCanonCommand implements CanonCommand<R>, TargetRefCommand<R> { @Override public CanonCommand<R> setTargetRef(final EdsBaseRef targetRef) { throwIfRunAlreadyCalled(); this.targetRef = Objects.requireNonNull(targetRef); if (targetRef instanceof EdsCameraRef) { this.targetRefType = TargetRefType.CAMERA; } else if (targetRef instanceof EdsImageRef) { this.targetRefType = TargetRefType.IMAGE; } else if (targetRef instanceof EdsEvfImageRef) { this.targetRefType = TargetRefType.EVF_IMAGE; } else if (targetRef instanceof EdsVolumeRef) { this.targetRefType = TargetRefType.VOLUME; } else if (targetRef instanceof EdsDirectoryItemRef) { this.targetRefType = TargetRefType.DIRECTORY_ITEM; } else { throw new IllegalArgumentException("Target ref not supported"); } return this; } protected  AbstractCanonCommand(); protected  AbstractCanonCommand(final AbstractCanonCommand<R> toCopy); @SuppressWarnings("unchecked") @Override AbstractCanonCommand<R> copy(); @Override final void run(); @Override CanonCommand<R> setTargetRef(final EdsBaseRef targetRef); final Optional<EdsBaseRef> getTargetRef(); @Override TargetRefType getTargetRefType(); @Override Instant getCreateTime(); @Override Instant getExecutionStartTime(); @Override boolean hasExecutionStarted(); @Override Instant getExecutionEndTime(); @Override boolean hasExecutionEnded(); @Override R get(); @Override Optional<Duration> getTimeout(); @Override CanonCommand<R> setTimeout(final Duration timeout);  }### Answer:
@Test void setTargetRef() { Assertions.assertThrows(NullPointerException.class, () -> doNothingCommand.setTargetRef(null)); doNothingCommand.setTargetRef(new EdsdkLibrary.EdsCameraRef()); Assertions.assertEquals(TargetRefType.CAMERA, doNothingCommand.getTargetRefType()); doNothingCommand.setTargetRef(new EdsdkLibrary.EdsImageRef()); Assertions.assertEquals(TargetRefType.IMAGE, doNothingCommand.getTargetRefType()); doNothingCommand.setTargetRef(new EdsdkLibrary.EdsEvfImageRef()); Assertions.assertEquals(TargetRefType.EVF_IMAGE, doNothingCommand.getTargetRefType()); doNothingCommand.setTargetRef(new EdsdkLibrary.EdsVolumeRef()); Assertions.assertEquals(TargetRefType.VOLUME, doNothingCommand.getTargetRefType()); doNothingCommand.setTargetRef(new EdsdkLibrary.EdsDirectoryItemRef()); Assertions.assertEquals(TargetRefType.DIRECTORY_ITEM, doNothingCommand.getTargetRefType()); Assertions.assertTrue(doNothingCommand.getTargetRef().isPresent()); }
@Test void setTargetRefThrowsOnUnhandled() { Assertions.assertThrows(IllegalArgumentException.class, () -> doNothingCommand.setTargetRef(new EdsdkLibrary.EdsBaseRef())); }