### Question:
PageCommand extends AbstractCommand { public Command targetedCommand( final Object target ) { if( !( target instanceof Page ) ) { throw new IllegalArgumentException( "Target must non-null and of type Page." ); } return new PageCommand( getRequestContext(), getURLPattern(), getContentTemplate(), ( Page )target, m_action ); } private  PageCommand( final ContextEnum currentContext, final Page target, final String action ); private  PageCommand( final String requestContext,
                         final String urlPattern,
                         final String contentTemplate,
                         final Page target,
                         final String action ); Command targetedCommand( final Object target ); String getName(); Permission requiredPermission(); static final Command ATTACH; static final Command COMMENT; static final Command CONFLICT; static final Command DELETE; static final Command DIFF; static final Command EDIT; static final Command INFO; static final Command PREVIEW; static final Command RENAME; static final Command RSS; static final Command UPLOAD; static final Command VIEW; static final Command NONE; static final Command OTHER; }### Answer:
@Test public void testTargetedCommand() throws Exception { final TestEngine testEngine = TestEngine.build(); testEngine.saveText( "TestPage", "This is a test." ); final Page testPage = testEngine.getManager( PageManager.class ).getPage( "TestPage" ); Command a = PageCommand.VIEW; Command b = a.targetedCommand( testPage ); Assertions.assertNotSame( a, b ); Assertions.assertEquals( a.getRequestContext(), b.getRequestContext() ); Assertions.assertEquals( a.getJSP(), b.getJSP() ); Assertions.assertEquals( a.getURLPattern(), b.getURLPattern() ); Assertions.assertEquals( a.getContentTemplate(), b.getContentTemplate() ); Assertions.assertNotNull( b.getTarget() ); Assertions.assertNotNull( b.requiredPermission() ); Assertions.assertEquals( PermissionFactory.getPagePermission( testPage, "view" ), b.requiredPermission() ); Assertions.assertEquals( testPage, b.getTarget() ); a = PageCommand.EDIT; b = a.targetedCommand( testPage ); Assertions.assertNotSame( a, b ); Assertions.assertNotNull( b.getTarget() ); Assertions.assertNotNull( b.requiredPermission() ); Assertions.assertEquals( PermissionFactory.getPagePermission( testPage, "edit" ), b.requiredPermission() ); Assertions.assertEquals( testPage, b.getTarget() ); a = PageCommand.DELETE; b = a.targetedCommand( testPage ); Assertions.assertNotSame( a, b ); Assertions.assertNotNull( b.getTarget() ); Assertions.assertNotNull( b.requiredPermission() ); Assertions.assertEquals( PermissionFactory.getPagePermission( testPage, "delete" ), b.requiredPermission() ); Assertions.assertEquals( testPage, b.getTarget() ); a = PageCommand.INFO; b = a.targetedCommand( testPage ); Assertions.assertNotSame( a, b ); Assertions.assertNotNull( b.getTarget() ); Assertions.assertNotNull( b.requiredPermission() ); Assertions.assertEquals( PermissionFactory.getPagePermission( testPage, "view" ), b.requiredPermission() ); Assertions.assertEquals( testPage, b.getTarget() ); }