Search in sources :

Example 1 with MessageType

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");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) MessageType(com.google.copybara.util.console.Message.MessageType) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MessageType(com.google.copybara.util.console.Message.MessageType) Test(org.junit.Test)

Example 2 with MessageType

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");
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MessageType(com.google.copybara.util.console.Message.MessageType) Test(org.junit.Test)

Aggregations

MessageType (com.google.copybara.util.console.Message.MessageType)2 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 IOException (java.io.IOException)1 List (java.util.List)1 Assert.assertThrows (org.junit.Assert.assertThrows)1 RunWith (org.junit.runner.RunWith)1 JUnit4 (org.junit.runners.JUnit4)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito (org.mockito.Mockito)1 Mockito.when (org.mockito.Mockito.when)1