1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.csrf

File CopyStringMatcher.java

 

Coverage histogram

../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

4
11
4
1
91
39
6
0.55
2.75
4
1.5

Classes

Class Line # Actions
CopyStringMatcher 34 11 0% 6 12
0.3684210536.8%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.csrf;
21   
22    import org.hamcrest.BaseMatcher;
23    import org.hamcrest.Description;
24    import org.jmock.api.Action;
25    import org.jmock.api.Invocation;
26   
27    /**
28    * A matcher that acts as an action and returns the matched argument in the mocked method, allowing small modifications
29    * (prepend/append something to the value).
30    *
31    * @version $Id: 6c87fc3a8f4a413fdf546f76b9cf2d8cceef095a $
32    * @since 2.5M2
33    */
 
34    public final class CopyStringMatcher extends BaseMatcher<String> implements Action
35    {
36    /** The string to copy. */
37    private String value = null;
38   
39    /** String to prepend to the copied value. */
40    private String prefix;
41   
42    /** String to append to the copied value. */
43    private String suffix;
44   
45    /**
46    * Create new CopyStringMatcher with the given prefix and suffix.
47    *
48    * @param prefix string to prepend to the value
49    * @param suffix string to append to the value
50    */
 
51  9 toggle public CopyStringMatcher(String prefix, String suffix)
52    {
53  9 this.prefix = prefix;
54  9 this.suffix = suffix;
55    }
56   
57    /**
58    * @see org.hamcrest.Matcher#matches(java.lang.Object)
59    */
 
60  1 toggle @Override
61    public boolean matches(Object argument)
62    {
63  1 if (argument instanceof String) {
64  0 this.value = (String) argument;
65  0 return true;
66    }
67  1 return false;
68    }
69   
70    /**
71    * @see org.hamcrest.SelfDescribing#describeTo(org.hamcrest.Description)
72    */
 
73  0 toggle @Override
74    public void describeTo(Description d)
75    {
76  0 d.appendText("COPY VALUE: ");
77  0 d.appendValue(this.value);
78    }
79   
80    /**
81    * @see org.jmock.api.Invokable#invoke(org.jmock.api.Invocation)
82    */
 
83  0 toggle @Override
84    public String invoke(Invocation invocation) throws Throwable
85    {
86  0 if (this.value == null) {
87  0 return this.prefix + this.suffix;
88    }
89  0 return this.prefix + this.value + this.suffix;
90    }
91    }