AnyString() as parameter for unit test
<p>I have to deal with a legacy application that has no tests. So before I begin refactoring I want to make sure everything works as it is.</p>

<p>Now imagine the following situation:</p>

<pre><code>public SomeObject doSomething(final OtherObject x, final String something) {
    if(x == null) throw new RuntimeException("x may not be null!");
    ...
}
</code></pre>

<p>Now I want to test that null check, so to be sure it works and I don't lose it once I refactor.</p>

<p>So I did this</p>

<pre><code>@Test(expected = RuntimeException.class)
public void ifOtherObjectIsNullExpectRuntimeException() {
    myTestObject.doSomething(null, "testString");
}
</code></pre>

<p>Now, this works of course.</p>

<p>But instead of "testString" I'd like to pass in a random String.</p>

<p>So I tried with:</p>

<pre><code>@Test(expected = RuntimeException.class)
public void ifOtherObjectIsNullExpectRuntimeException() {
    myTestObject.doSomething(null, Mockito.anyString());
}
</code></pre>

<p>But this is not allowed., as I get <blockquote>org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
... You cannot use argument matchers outside of verifications or stubbing</blockquote></p>

<p>I do understand the meaning of this, but I wonder whether I can still manage to do what I want without parameterizing my test or the like.
The only libraries I may use are Junit, AssertJ, Mockito and Powermock.</p>

<p>Any ideas?</p>