Skip to content

Commit

Permalink
Merge pull request #16 from jonathan-yan/master
Browse files Browse the repository at this point in the history
Fix for issue with merging of resource class and method path annotations
  • Loading branch information
danielbodart committed May 15, 2015
2 parents 5c9cdf9 + c9fada8 commit 1d62ff5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import static com.googlecode.totallylazy.Predicates.notNullValue;
import static com.googlecode.totallylazy.Sequences.sequence;
import static com.googlecode.utterlyidle.UriTemplate.trimSlashes;

public class UriTemplateExtractor implements Extractor<Method, UriTemplate> {
static UriTemplate uriTemplate(Method method) {
Expand All @@ -23,7 +24,7 @@ public UriTemplate extract(Method method) {
public static Callable1<? super Path, String> getValue() {
return new Callable1<Path, String>() {
public String call(Path o) throws Exception {
return o.value();
return trimSlashes(o.value());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.googlecode.utterlyidle.annotations;

import com.googlecode.utterlyidle.UriTemplate;
import org.junit.Test;

import java.lang.reflect.Method;

import static com.googlecode.utterlyidle.annotations.UriTemplateExtractor.uriTemplate;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class UriTemplateExtractorTest {
@Test
public void mergesClassAndMethodPathAnnotations() {
@Path("/test")
class TestResource {
@GET
@Path("/method")
public Method method() {
return new Object() {}.getClass().getEnclosingMethod();
}
}

assertThat(uriTemplate(new TestResource().method()), is(UriTemplate.uriTemplate("test/method")));
}
}

0 comments on commit 1d62ff5

Please sign in to comment.