Source:
<code>public void canLogin() throws IOException { final String token = "GitHubToken"; final String code = "GitHubCode"; final int userid = 1; final String login = "octocat"; final String avatar = "<LINK_1>"; final String lgattr = "login"; final String acattr = "access_token"; final Take take = new TkFork( new FkRegex( "/login/oauth/access_token", new Take() { @Override public Response act(final Request req) throws IOException { return new RsXembly( new XeDirectives( new Directives().add("OAuth") .add("token_type").set("bearer").up() .add("scope").set("repo,gist").up() .add(acattr).set(token).toString() ) ); } } ), new FkRegex( "/user", new Take() { @Override public Response act(final Request req) throws IOException { MatcherAssert.assertThat( new RqHref.Base(req).href().param( acattr ).iterator().next(), Matchers.containsString(token) ); return new RsJSON( Json.createObjectBuilder() .add(lgattr, login) .add("id", userid) .add("avatar_url", avatar) .build() ); } } ) ); new FtRemote(take).exec( new FtRemote.Script() { @Override public void exec(final URI home) throws IOException { <START> final Iterator<Identity> itr = new PsGithub( <END> "app", "key", home.toString(), home.toString() ).enter(new RqFake("GET", String.format("?code=%s", code))); final Identity identity = itr.next(); MatcherAssert.assertThat( identity.urn(), Matchers.equalTo(String.format("urn:github:%d", userid)) ); MatcherAssert.assertThat( identity.properties().get(lgattr), Matchers.equalTo(login) ); MatcherAssert.assertThat( identity.properties().get("avatar"), Matchers.equalTo(avatar) ); } } ); }</code><technical_language>@dmzaytsev This variable is once. get rid of calling next() enter() call</technical_language>

Target:
public void canLogin() throws IOException { final Take take = new TkFork( new FkRegex( "/login/oauth/access_token", new Take() { @Override public Response act(final Request req) throws IOException { final Request greq = new RqGreedy(req); PsGithubTest.assertParam(greq, "code", "code"); PsGithubTest.assertParam(greq, "client_id", "app"); PsGithubTest.assertParam(greq, "client_secret", "key"); return new RsXembly( new XeDirectives( new Directives().add("OAuth") .add("token_type").set("bearer").up() .add("scope").set("repo,gist").up() .add("access_token").set("GitHubToken") .toString() ) ); } } ), new FkRegex( "/user", new Take() { @Override public Response act(final Request req) throws IOException { MatcherAssert.assertThat( new RqHref.Base(req).href().param("access_token") .iterator().next(), Matchers.containsString("GitHubToken") ); return new RsJSON( Json.createObjectBuilder() .add("login", "octocat") .add("id", 1) .add( "avatar_url", "<LINK_0>" ) .build() ); } } ) ); new FtRemote(take).exec( new FtRemote.Script() { @Override public void exec(final URI home) throws IOException { final Identity identity = new PsGithub( "app", "key", home.toString(), home.toString() ).enter(new RqFake("GET", "?code=code")).next(); MatcherAssert.assertThat( identity.urn(), Matchers.equalTo("urn:github:1") ); MatcherAssert.assertThat( identity.properties().get("login"), Matchers.equalTo("octocat") ); MatcherAssert.assertThat( identity.properties().get("avatar"), Matchers.equalTo("<LINK_0>") ); } } ); }