Search in sources :

Example 31 with Console

use of com.google.copybara.util.console.Console in project copybara by google.

the class SkylarkConsoleTest method testColorize.

@Test
public void testColorize() {
    Console delegate = mock(Console.class);
    when(delegate.colorize(any(), any())).thenReturn("colorized!");
    assertThat(new SkylarkConsole(delegate).colorize(AnsiColor.BLUE, "aaaa")).isEqualTo("colorized!");
}
Also used : Console(com.google.copybara.util.console.Console) Test(org.junit.Test)

Example 32 with Console

use of com.google.copybara.util.console.Console in project copybara by google.

the class GithubArchiveTest method setup.

@Before
public void setup() throws IOException {
    httpTransport = new MockHttpTransport() {

        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) {
            String requestString = method + " " + url;
            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest();
            MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
            request.setResponse(response);
            response.setStatusCode(200);
            response.setContent(responseContent);
            if (!url.equals(expectedRequest)) {
                response.setStatusCode(404);
                response.setContent(String.format("UNEXPECTED REQUEST (Returning 404) REQUEST: %s, expected: %s", requestString, expectedRequest));
            }
            return request;
        }
    };
    RemoteFileOptions options = new RemoteFileOptions();
    options.transport = () -> new GclientHttpStreamFactory(httpTransport, Duration.ofSeconds(20));
    Console console = new TestingConsole();
    OptionsBuilder optionsBuilder = new OptionsBuilder().setConsole(console);
    optionsBuilder.remoteFile = options;
    skylark = new SkylarkTestExecutor(optionsBuilder);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) Before(org.junit.Before)

Example 33 with Console

use of com.google.copybara.util.console.Console in project copybara by google.

the class TestingConsoleTest method testPredicateCausesAssertionError.

@Test
public void testPredicateCausesAssertionError() throws Exception {
    Console console = new TestingConsole().respondWithString("Lorem Ipsum!");
    assertThrows(IOException.class, () -> console.ask("Have anything to say?", "foo", x -> x.equals("Hello world!")));
}
Also used : Objects(java.util.Objects) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) MessageType(com.google.copybara.util.console.Message.MessageType) Console(com.google.copybara.util.console.Console) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) LogSubject(com.google.copybara.util.console.testing.LogSubjects.LogSubject) Before(org.junit.Before) Console(com.google.copybara.util.console.Console) Test(org.junit.Test)

Example 34 with Console

use of com.google.copybara.util.console.Console in project copybara by google.

the class TestingConsoleTest method testProgrammedStringResponses.

@Test
public void testProgrammedStringResponses() throws Exception {
    Console console = new TestingConsole().respondWithString("Hello world!");
    assertThat(console.ask("Have anything to say?", "foo", Objects::nonNull)).isEqualTo("Hello world!");
}
Also used : Console(com.google.copybara.util.console.Console) Objects(java.util.Objects) Test(org.junit.Test)

Example 35 with Console

use of com.google.copybara.util.console.Console in project copybara by google.

the class TestingConsoleTest method testProgrammedResponses.

@Test
public void testProgrammedResponses() throws Exception {
    Console console = new TestingConsole().respondYes().respondNo();
    assertThat(console.promptConfirmation("Proceed?")).isTrue();
    assertThat(console.promptConfirmation("Proceed?")).isFalse();
}
Also used : Console(com.google.copybara.util.console.Console) Test(org.junit.Test)

Aggregations

Console (com.google.copybara.util.console.Console)38 Test (org.junit.Test)19 ValidationException (com.google.copybara.exception.ValidationException)14 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)11 IOException (java.io.IOException)11 ImmutableList (com.google.common.collect.ImmutableList)10 Config (com.google.copybara.config.Config)8 Path (java.nio.file.Path)7 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)6 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)6 Before (org.junit.Before)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 Migration (com.google.copybara.config.Migration)5 Glob (com.google.copybara.util.Glob)5 RunWith (org.junit.runner.RunWith)5 JUnit4 (org.junit.runners.JUnit4)5 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)4 ConfigWithDependencies (com.google.copybara.config.SkylarkParser.ConfigWithDependencies)4 RepoException (com.google.copybara.exception.RepoException)4 Change (com.google.copybara.revision.Change)4