Skip to content

Commit 79c8ef1

Browse files
committed
Compile-time tests for @path
1 parent c943afc commit 79c8ef1

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithPathVariable.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.androidannotations.rest.spring.annotations.Get;
2222
import org.androidannotations.rest.spring.annotations.Head;
2323
import org.androidannotations.rest.spring.annotations.Options;
24+
import org.androidannotations.rest.spring.annotations.Path;
2425
import org.androidannotations.rest.spring.annotations.Post;
2526
import org.androidannotations.rest.spring.annotations.Put;
2627
import org.androidannotations.rest.spring.annotations.Rest;
@@ -49,4 +50,12 @@ public interface ClientWithPathVariable {
4950
@Put("/test/{v1}/{v2}")
5051
void putWithParameterEntity(int v1, String v2);
5152

53+
@Get("/test/{v1}")
54+
void getWithPathAnnotation(@Path("v1") int version);
55+
56+
@Get("/test/{v1}/{v2}")
57+
void getWithPathAnnotationAndParam(@Path("v1") int v1, String v2);
58+
59+
@Get("/test/{v1}/{v2}")
60+
void getWithCrossParamAnnotations(@Path("v1") int v2, @Path("v2") int v1);
5261
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.rest.spring;
17+
18+
import org.androidannotations.rest.spring.annotations.Get;
19+
import org.androidannotations.rest.spring.annotations.Path;
20+
import org.androidannotations.rest.spring.annotations.Rest;
21+
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
22+
23+
@Rest(converters = MappingJacksonHttpMessageConverter.class)
24+
public interface ClientWithWrongPathVariables {
25+
26+
@Get("/duplicates/{v1}")
27+
void getWithDuplicatePathVariables(@Path("v1") int v1, @Path("v1") int v2);
28+
29+
@Get("/missingvariable/{v1}")
30+
void getWithMissingPathVariable(@Path("v1") int v1, @Path("v2") int hasMissingVariable);
31+
32+
@Get("/missingparameter/{v1}")
33+
void getWithMissingMethodParameter(@Path("v1") int v1);
34+
35+
void missingGetAnnotation(@Path("missingGet") int v1);
36+
}

AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/RestTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public void clientWithPathVariables() throws IOException {
7878
assertCompilationSuccessful(result);
7979
}
8080

81+
@Test
82+
public void clientWithWrongPathVariables() throws IOException {
83+
CompileResult result = compileFiles(ClientWithWrongPathVariables.class);
84+
assertCompilationErrorOn(ClientWithWrongPathVariables.class, "@Get(\"/duplicates/{v1}\")", result);
85+
assertCompilationErrorOn(ClientWithWrongPathVariables.class, "@Get(\"/missingvariable/{v1}\")", result);
86+
assertCompilationErrorOn(ClientWithWrongPathVariables.class, "@Path(\"v2\")", result);
87+
assertCompilationErrorOn(ClientWithWrongPathVariables.class, "@Path(\"missingGet\")", result);
88+
assertCompilationErrorCount(5, result);
89+
}
90+
8191
@Test
8292
public void clientWithWrongEnhancedMethods() throws IOException {
8393
CompileResult result = compileFiles(ClientWithWrongEnhancedMethod.class);

0 commit comments

Comments
 (0)