Skip to content

Commit

Permalink
Using Assert.assertThat for better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Aug 22, 2013
1 parent 2e818f1 commit 87592a3
Showing 1 changed file with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
package org.jboss.forge.addon.shell.parser;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;

import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -70,22 +74,22 @@ public void testWizardInitialStepAutocomplete() throws Exception
assertCompletionStep("mockwizard --values ", "--v");
String stdout = assertCompletionStepWithSuggestions("mockwizard --values foo --", "foo --");

Assert.assertTrue(stdout.contains("--proceed"));
Assert.assertTrue(stdout.contains("--key"));
Assert.assertFalse(stdout.contains("--selections"));
Assert.assertFalse(stdout.contains("--done"));
Assert.assertThat(stdout, containsString("--proceed"));
Assert.assertThat(stdout, containsString("--key"));
Assert.assertThat(stdout, not(containsString("--selections")));
Assert.assertThat(stdout, not(containsString("--done")));

assertCompletionStep("mockwizard --values foo --proceed ", "p");
stdout = assertCompletionStepWithSuggestions("mockwizard --values foo --proceed --", "--");

Assert.assertTrue(stdout.contains("--key"));
Assert.assertTrue(stdout.contains("--done"));
Assert.assertTrue(stdout.contains("--selections"));
Assert.assertThat(stdout, containsString("--key"));
Assert.assertThat(stdout, containsString("--done"));
Assert.assertThat(stdout, containsString("--selections"));

assertCompletionStep("mockwizard --values foo --proceed --selections ", "sel");
stdout = assertCompletionStepWithSuggestions("mockwizard --values foo --proceed --selections blah --", "blah --");
Assert.assertFalse(stdout.contains("--key"));
Assert.assertTrue(stdout.contains("--done"));
Assert.assertThat(stdout, not(containsString("--key")));
Assert.assertThat(stdout, containsString("--done"));
}

@Test(timeout = 10000)
Expand All @@ -96,17 +100,17 @@ public void testWizardInitialStepAutocompleteBooleanFlagWithValue() throws Excep
assertCompletionStep("mockwizard --values ", "--v");
String stdout = assertCompletionStepWithSuggestions("mockwizard --values foo --", "foo --");

Assert.assertTrue(stdout.contains("--proceed"));
Assert.assertTrue(stdout.contains("--key"));
Assert.assertFalse(stdout.contains("--selections"));
Assert.assertFalse(stdout.contains("--done"));
Assert.assertThat(stdout, containsString("--proceed"));
Assert.assertThat(stdout, containsString("--key"));
Assert.assertThat(stdout, not(containsString("--selections")));
Assert.assertThat(stdout, not(containsString("--done")));

assertCompletionStep("mockwizard --values foo --proceed ", "p");
stdout = assertCompletionStepWithSuggestions("mockwizard --values foo --proceed true --", "true --");

Assert.assertTrue(stdout.contains("--key"));
Assert.assertTrue(stdout.contains("--done"));
Assert.assertTrue(stdout.contains("--selections"));
Assert.assertThat(stdout, containsString("--key"));
Assert.assertThat(stdout, containsString("--done"));
Assert.assertThat(stdout, containsString("--selections"));

assertCompletionStep("mockwizard --values foo --proceed true --selections ", "sel");
}
Expand All @@ -123,10 +127,11 @@ public String call() throws Exception
return null;
}
}, TIMEOUT, TimeUnit.SECONDS, expected);
Assert.assertEquals(expected, test.getBuffer().getLine());
Assert.assertThat(test.getBuffer().getLine(), equalTo(expected));
}

private String assertCompletionStepWithSuggestions(final String expected, final String write) throws TimeoutException
private String assertCompletionStepWithSuggestions(final String expected, final String write)
throws TimeoutException
{
test.waitForStdOutValue(new Callable<Void>()
{
Expand All @@ -143,7 +148,7 @@ public String call() throws Exception
return null;
}
}, TIMEOUT, TimeUnit.SECONDS, expected);
Assert.assertEquals(expected, test.getBuffer().getLine());
Assert.assertThat(test.getBuffer().getLine(), equalTo(expected));
return null;
}
}, TIMEOUT, TimeUnit.SECONDS, expected);
Expand Down

0 comments on commit 87592a3

Please sign in to comment.