1 package com.lexicalscope.fluentreflection.usecases;
2
3 import static com.lexicalscope.fluentreflection.FluentReflection.object;
4 import static com.lexicalscope.fluentreflection.ReflectionMatchers.*;
5 import static org.hamcrest.Matchers.containsInAnyOrder;
6 import static org.junit.Assert.assertThat;
7
8 import org.hamcrest.Matcher;
9 import org.junit.Test;
10
11 import com.lexicalscope.fluentreflection.ListBuilder;
12 import com.lexicalscope.fluentreflection.FluentMember;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class TestFindAllBeanMethods {
31 static class Bean {
32 private int readWriteProperty;
33 private String readOnlyProperty;
34
35 String getReadOnlyProperty() {
36 return readOnlyProperty;
37 }
38
39 int getReadWriteProperty() {
40 return readWriteProperty;
41 }
42
43 void setReadWriteProperty(final int readWriteProperty) {
44 this.readWriteProperty = readWriteProperty;
45 }
46
47 void setWriteOnlyProperty(final Object writeOnlyProperty) {
48
49 }
50
51 int getMethodWithArgument(final int outOfPlace) {
52 return outOfPlace;
53 }
54
55 void getMethodReturningVoid() {}
56 }
57
58
59
60 @Test public void canSelectAllGetters() throws Exception {
61 assertThat(
62 object(new Bean()).methods(isGetter()),
63 containsInAnyOrder(
64 ListBuilder.<Matcher<? super FluentMember>>
65 list(hasName("getReadOnlyProperty")).add(
66 hasName("getReadWriteProperty")).$()));
67 }
68
69 @Test public void canSelectAllSetters() throws Exception {
70 assertThat(
71 object(new Bean()).methods(
72 isSetter()),
73 containsInAnyOrder(
74 ListBuilder.<Matcher<? super FluentMember>>
75 list(hasName("setWriteOnlyProperty")).add(
76 hasName("setReadWriteProperty")).$()));
77 }
78 }