Skip to content

Commit

Permalink
update to use assertThat function
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelhak-zaaim committed Nov 13, 2024
1 parent ff215ad commit ae2f8e3
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.util.Optional;
import java.util.function.Predicate;

import static org.junit.jupiter.api.Assertions.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.is;

class PrompterTest {

Expand All @@ -31,7 +32,7 @@ void testPromptWithDefaultAnswer() {
String input = "\n";
System.setIn(new ByteArrayInputStream(input.getBytes()));
String result = Prompter.prompt("Enter your name", "defaultName");
assertEquals("defaultName", result);
assertThat(result, is("defaultName"));
}

@Test
Expand All @@ -40,15 +41,15 @@ void testPromptWithValidator() {
System.setIn(new ByteArrayInputStream(input.getBytes()));
Predicate<String> validator = s -> s.equals("validInput");
String result = Prompter.prompt("Enter valid input", null, validator);
assertEquals("validInput", result);
assertThat(result, is("validInput"));
}

@Test
void testPromptWithOptionalDefault() {
String input = "\n";
System.setIn(new ByteArrayInputStream(input.getBytes()));
String result = Prompter.prompt("Enter your name", Optional.of("defaultName"));
assertEquals("defaultName", result);
assertThat(result, is("defaultName"));
}

@Test
Expand All @@ -57,15 +58,15 @@ void testPromptSelection() {
System.setIn(new ByteArrayInputStream(input.getBytes()));
List<String> options = List.of("Option 1", "Option 2", "Option 3");
int result = Prompter.prompt("Choose an option", options, 0);
assertEquals(1, result);
assertThat(result, is(1));
}

@Test
void testPromptYesNo() {
String input = "y\n";
System.setIn(new ByteArrayInputStream(input.getBytes()));
boolean result = Prompter.promptYesNo("Do you agree?", false);
assertTrue(result);
assertThat(result, is(true));
}

}

0 comments on commit ae2f8e3

Please sign in to comment.