title: Creating a testing rule in Mockito like "for each arg the method would return an answer based on this arg"
body: <p>There is a class.</p>
  
  <pre><code>class A {
  
   public String getValue(String key) {
     return key;
   }
  
  }
  </code></pre>
  
  <p>Is it possible to write such a test that would test that method <code>getValue()</code> returns a key as a value.</p>
  
  <p>There is my try:</p>
  
  <pre><code>  A aMock = mock(A.class);
    when(aMock.getValue("key")).thenReturn("key");
  </code></pre>
  
  <p>That's nice, but this works only for one particular parameter value. But I, probably, need some kind of rule like <code>"for each parameter it would return the parameter itself whatever value this parameter would have"</code></p>
  
  <hr>
  
  <p>More context, what I'm actually trying to test:</p>
  
  <p>Let's say we have a file with <code>key=value</code> entries, like a resource bundle.
  The method would return key if it could not find a value. For example if we search by "user.name", we going to have "Bob" if it is defined. If not - it would return key (user.name) itsef, because I do not want this method returns me <code>null</code>. </p>
  
  <p>(This is actually a model of <code>org.springframework.context.MessageSource.getMessage</code> - it behaves similar way) </p>
  
  <p>So.. updated </p>
  
  <pre><code>public String getValue(String key) {
      // some code ...might be here, but we care about a result
      if (valueWasFound) {
       return theValue;
      } 
      return key;
  }
  </code></pre>