title: How to handle "any other value" with Mockito?
body: <p>I have an interface <code>Foo</code> with method <code>int Foo.bar(int)</code> that I want to mock with Mockito. I want the mocked method to return <code>99</code> if I pass in <code>1</code>, but all other values will throw an exception. Can I do this?</p>
  
  <pre><code>final Foo foo = mock(Foo.class);
  when(foo.bar(1)).thenReturn(99);
  when(foo.bar(anyInt())).thenThrow(new IllegalArgumentException());
  </code></pre>
  
  <p>In other words, will the <code>1</code> take precedence over <code>anyInt()</code>? I wouldn't want it throwing an exception for <code>1</code>. The <a href="http://site.mockito.org/mockito/docs/current/org/mockito/Mockito.html#2" rel="noreferrer">docs</a> say that for multiple definitions the last definition is more important, but I couldn't tell if that meant for identical arguments or not. If it applies here, would I need to define the wildcard <code>anyInt()</code> first? Or do the two even have any relation, as one of them is a matcher and the other is just a value?</p>