### Question:
GroupCommand extends AbstractCommand { public Command targetedCommand( final Object target ) { if( !( target instanceof GroupPrincipal ) ) { throw new IllegalArgumentException( "Target must non-null and of type GroupPrincipal." ); } return new GroupCommand( getRequestContext(), getURLPattern(), getContentTemplate(), ( GroupPrincipal )target, m_action ); } private  GroupCommand( final ContextEnum currentContext, final GroupPrincipal target, final String action ); private  GroupCommand( final String requestContext,
                          final String urlPattern,
                          final String contentTemplate,
                          final GroupPrincipal target,
                          final String action ); Command targetedCommand( final Object target ); String getName(); Permission requiredPermission(); static final Command DELETE_GROUP; static final Command EDIT_GROUP; static final Command VIEW_GROUP; }### Answer:
@Test public void testTargetedCommand() { Command a = GroupCommand.VIEW_GROUP; final GroupPrincipal group = new GroupPrincipal( "Test" ); Command b = a.targetedCommand( group ); 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( new GroupPermission( "*:Test", "view" ), b.requiredPermission() ); Assertions.assertEquals( group, b.getTarget() ); a = GroupCommand.EDIT_GROUP; b = a.targetedCommand( group ); Assertions.assertNotSame( a, b ); Assertions.assertNotNull( b.getTarget() ); Assertions.assertNotNull( b.requiredPermission() ); Assertions.assertEquals( new GroupPermission( "*:Test", "edit" ), b.requiredPermission() ); Assertions.assertEquals( group, b.getTarget() ); a = GroupCommand.DELETE_GROUP; b = a.targetedCommand( group ); Assertions.assertNotSame( a, b ); Assertions.assertNotNull( b.getTarget() ); Assertions.assertNotNull( b.requiredPermission() ); Assertions.assertEquals( new GroupPermission( "*:Test", "delete" ), b.requiredPermission() ); Assertions.assertEquals( group, b.getTarget() ); }