1   package com.lexicalscope.fluentreflection;
2   
3   import static org.hamcrest.Matchers.equalTo;
4   
5   import org.hamcrest.Matcher;
6   import org.jmock.Expectations;
7   
8   /*
9    * Copyright 2011 Tim Wood
10   *
11   * Licensed under the Apache License, Version 2.0 (the "License");
12   * you may not use this file except in compliance with the License.
13   * You may obtain a copy of the License at
14   *
15   * http://www.apache.org/licenses/LICENSE-2.0
16   *
17   * Unless required by applicable law or agreed to in writing, software
18   * distributed under the License is distributed on an "AS IS" BASIS,
19   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   * See the License for the specific language governing permissions and
21   * limitations under the License. 
22   */
23  
24  public class TestMatcherConstructorReflectingOn extends AbstractTestReflectionMatcher<FluentConstructor<?>> {
25      static class ClassWithAConstructor {
26          ClassWithAConstructor() {}
27      }
28  
29      static class AnotherClassWithAConstructor {
30          AnotherClassWithAConstructor() {}
31      }
32  
33      @Override protected FluentConstructor<?> target() {
34          return constructor;
35      }
36  
37      @Override protected void setupMatchingCase() throws Throwable {
38          context.checking(new Expectations() {
39              {
40                  oneOf(constructor).member();
41                  will(returnValue(ClassWithAConstructor.class.getDeclaredConstructor()));
42              }
43          });
44      }
45  
46      @Override protected void setupFailingCase() throws Throwable {
47          context.checking(new Expectations() {
48              {
49                  oneOf(constructor).member();
50                  will(returnValue(AnotherClassWithAConstructor.class.getDeclaredConstructor()));
51              }
52          });
53      }
54  
55      @Override protected Matcher<String> hasDescription() {
56          return equalTo("reflecting on constructor <com.lexicalscope.fluentreflection.TestMatcherConstructorReflectingOn$ClassWithAConstructor()>");
57      }
58  
59      @Override protected ReflectionMatcher<FluentConstructor<?>> matcher() throws Throwable {
60          return new MatcherConstructorReflectingOn(ClassWithAConstructor.class.getDeclaredConstructor());
61      }
62  }