Skip to content

Commit

Permalink
improve getUrl method for proxy + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mat1e committed Jul 28, 2021
1 parent 5a65cfc commit a90bdcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected String getUrl(Context context) {
if (!params.isEmpty()) {
builder.append('?');
params.forEach(p -> builder.append(p.getKey()).append('=').append(p.getValue()).append('&'));
builder.substring(0, builder.lastIndexOf("&"));
builder.deleteCharAt(builder.lastIndexOf("&"));
}
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.sonatype.nexus.repository.storage.StorageTx;
import org.sonatype.nexus.repository.view.Content;
import org.sonatype.nexus.repository.view.Context;
import org.sonatype.nexus.repository.view.Parameters;
import org.sonatype.nexus.repository.view.Payload;
import org.sonatype.nexus.repository.view.Request;
import org.sonatype.nexus.repository.view.Response;
Expand Down Expand Up @@ -263,4 +264,26 @@ public void checkPathWithoutSlashTest() throws Exception {

assertThat(result.equals(PACKAGES_PATH), is(true));
}

@Test
public void getUrlTestWithoutParams() {
when(request.getPath()).thenReturn("/" + PACKAGES_PATH);
when(request.getParameters()).thenReturn(new Parameters());

String result = underTest.getUrl(context);

assertThat(result.equals(PACKAGES_PATH), is(true));
}

@Test
public void getUrlTestWithParams() {
when(request.getPath()).thenReturn("/" + PACKAGES_PATH);
Parameters params = new Parameters();
params.set("page", "1");
when(request.getParameters()).thenReturn(params);

String result = underTest.getUrl(context);

assertThat(result.equals(PACKAGES_PATH + "?page=1"), is(true));
}
}

0 comments on commit a90bdcf

Please sign in to comment.