use of com.google.copybara.util.console.Message.MessageType in project copybara by google.
the class DelegateConsoleTest method testDelegateAsk.
@Test
public void testDelegateAsk() throws IOException {
Console delegate = Mockito.mock(Console.class);
when(delegate.ask(Mockito.eq("fail"), anyString(), any())).thenThrow(new RuntimeException("should fail"));
when(delegate.ask(Mockito.eq("work"), anyString(), any())).thenReturn("good");
DelegateConsole console = new DelegateConsole(delegate) {
@Override
protected void handleMessage(MessageType info, String message) {
}
};
RuntimeException e = assertThrows(RuntimeException.class, () -> console.ask("fail", "aaa", s -> true));
assertThat(e).hasMessageThat().contains("should fail");
assertThat(console.ask("work", "aaa", s -> true)).isEqualTo("good");
}
use of com.google.copybara.util.console.Message.MessageType in project copybara by google.
the class DelegateConsoleTest method testConsole.
@Test
public void testConsole() {
TestingConsole delegate = new TestingConsole();
List<Message> messages = new ArrayList<>();
DelegateConsole delegating = new DelegateConsole(delegate) {
@Override
protected void handleMessage(MessageType type, String message) {
messages.add(new Message(type, message));
}
};
delegating.startupMessage("v1");
delegating.info("This is info");
delegating.warn("This is warning");
delegating.error("This is error");
delegating.verbose("This is verbose");
delegating.progress("This is progress");
assertThat(messages).containsExactly(new Message(MessageType.INFO, "Copybara source mover (Version: v1)"), new Message(MessageType.INFO, "This is info"), new Message(MessageType.WARNING, "This is warning"), new Message(MessageType.ERROR, "This is error"), new Message(MessageType.VERBOSE, "This is verbose"), new Message(MessageType.PROGRESS, "This is progress"));
delegate.assertThat().matchesNext(MessageType.INFO, "Copybara source mover [(]Version: v1[)]").matchesNext(MessageType.INFO, "This is info").matchesNext(MessageType.WARNING, "This is warning").matchesNext(MessageType.ERROR, "This is error").matchesNext(MessageType.VERBOSE, "This is verbose").matchesNext(MessageType.PROGRESS, "This is progress");
}
Aggregations