Search in sources :

Example 1 with CheckerException

use of com.google.copybara.checks.CheckerException in project copybara by google.

the class GitDestinationTest method testChecker.

@Test
public void testChecker() throws Exception {
    Writer<GitRevision> writer = firstCommitWriter();
    Files.write(workdir.resolve("existing"), "BAD".getBytes(UTF_8));
    ImmutableList<DestinationEffect> result = writer.write(TransformResults.of(workdir, new DummyRevision("ref1")), destinationFiles, console);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
    options.testingOptions.checker = new DummyChecker(ImmutableSet.of("BAD"));
    checker = "testing.dummy_checker()";
    final Writer<GitRevision> writer2 = newWriter();
    Files.write(workdir.resolve("new_file"), "ok".getBytes(UTF_8));
    result = writer2.write(TransformResults.of(workdir, new DummyRevision("ref2")), destinationFiles, console);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getErrors()).isEmpty();
    assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
    Files.write(workdir.resolve("new_file"), "BAD".getBytes(UTF_8));
    CheckerException ex = assertThrows(CheckerException.class, () -> writer2.write(TransformResults.of(workdir, new DummyRevision("ref3")), destinationFiles, console));
    assertThat(ex).hasMessageThat().containsMatch("Bad word 'bad' found:.*/new_file:1");
    assertThat(ex).hasMessageThat().doesNotContainMatch("Bad word 'bad' found:.*/existing:1");
}
Also used : DestinationEffect(com.google.copybara.DestinationEffect) CheckerException(com.google.copybara.checks.CheckerException) DummyRevision(com.google.copybara.testing.DummyRevision) DummyChecker(com.google.copybara.testing.DummyChecker) Test(org.junit.Test)

Example 2 with CheckerException

use of com.google.copybara.checks.CheckerException in project copybara by google.

the class GerritApiTransportWithCheckerTest method testGetThrowsException.

@Test
public void testGetThrowsException() throws Exception {
    doThrow(new CheckerException("Error!")).when(checker).doCheck(ArgumentMatchers.<ImmutableMap<String, String>>any(), eq(console));
    assertThrows(ValidationException.class, () -> transport.get("path/foo", String.class));
    verifyNoMoreInteractions(delegate);
}
Also used : CheckerException(com.google.copybara.checks.CheckerException) Test(org.junit.Test)

Example 3 with CheckerException

use of com.google.copybara.checks.CheckerException in project copybara by google.

the class GerritApiTransportWithCheckerTest method testPostThrowsException.

@Test
public void testPostThrowsException() throws Exception {
    doThrow(new CheckerException("Error!")).when(checker).doCheck(ArgumentMatchers.<ImmutableMap<String, String>>any(), eq(console));
    assertThrows(ValidationException.class, () -> transport.post("path/foo", "request_content", String.class));
    verifyNoMoreInteractions(delegate);
}
Also used : CheckerException(com.google.copybara.checks.CheckerException) Test(org.junit.Test)

Example 4 with CheckerException

use of com.google.copybara.checks.CheckerException in project copybara by google.

the class GitHubApiTransportWithCheckerTest method testPostThrowsException.

@Test
public void testPostThrowsException() throws Exception {
    doThrow(new CheckerException("Error!")).when(checker).check(any(), any(), any(), any(), any(), any());
    assertThrows(ValidationException.class, () -> transport.post("path/foo", "request_content", String.class));
    verifyNoMoreInteractions(delegate);
}
Also used : CheckerException(com.google.copybara.checks.CheckerException) Test(org.junit.Test)

Example 5 with CheckerException

use of com.google.copybara.checks.CheckerException in project copybara by google.

the class GitHubApiTransportWithCheckerTest method testGetThrowsException.

@Test
public void testGetThrowsException() throws Exception {
    doThrow(new CheckerException("Error!")).when(checker).check(any(), any(), any(), any());
    assertThrows(ValidationException.class, () -> transport.get("path/foo", String.class));
    verifyNoMoreInteractions(delegate);
}
Also used : CheckerException(com.google.copybara.checks.CheckerException) Test(org.junit.Test)

Aggregations

CheckerException (com.google.copybara.checks.CheckerException)5 Test (org.junit.Test)5 DestinationEffect (com.google.copybara.DestinationEffect)1 DummyChecker (com.google.copybara.testing.DummyChecker)1 DummyRevision (com.google.copybara.testing.DummyRevision)1