Search code examples
tddhamcrest

Hamcrest: file1 either file2 exists


I currently refactor my tests from AsserJ to hamcrest library. But there is one assertion that I can not migrate to hamcrest.

tmp1 and tmp2 contain two paths in the filesystem. I need to verify that either tmp1 or tmp2 exists, but not both. The current assertion is

assertTrue(new File(tmp1).exists() ^ new File(tmp2).exists());

What is the equivialent hamcrest test?


Solution

  •  assertThat(new File(tmp1).exists() ^ new File(tmp2).exists(), is(true));