diff options
author | lberki <lberki@google.com> | 2017-05-30 12:35:33 +0200 |
---|---|---|
committer | László Csomor <laszlocsomor@google.com> | 2017-05-30 12:51:57 +0200 |
commit | aea56b36af994b269800602e36000c293cabd00b (patch) | |
tree | 794f6b3b2528353cc39bd383730d408d4ff25233 /src/test/java/com/google/devtools/build/lib/events | |
parent | 229f393bf460700594ae032a551879e026bd0b91 (diff) |
Migrate Java tests to Truth.
RELNOTES: None.
PiperOrigin-RevId: 157446717
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/events')
8 files changed, 72 insertions, 91 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/events/AbstractEventHandlerTest.java b/src/test/java/com/google/devtools/build/lib/events/AbstractEventHandlerTest.java index ab7c9ed761..4863da9852 100644 --- a/src/test/java/com/google/devtools/build/lib/events/AbstractEventHandlerTest.java +++ b/src/test/java/com/google/devtools/build/lib/events/AbstractEventHandlerTest.java @@ -13,17 +13,14 @@ // limitations under the License. package com.google.devtools.build.lib.events; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertThat; +import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.util.Set; - -/** - * Tests {@link AbstractEventHandler}. - */ +/** Tests {@link AbstractEventHandler}. */ @RunWith(JUnit4.class) public class AbstractEventHandlerTest { @@ -36,12 +33,10 @@ public class AbstractEventHandlerTest { @Test public void retainsEventMask() { - assertEquals(EventKind.ALL_EVENTS, - create(EventKind.ALL_EVENTS).getEventMask()); - assertEquals(EventKind.ERRORS_AND_WARNINGS, - create(EventKind.ERRORS_AND_WARNINGS).getEventMask()); - assertEquals(EventKind.ERRORS, - create(EventKind.ERRORS).getEventMask()); + assertThat(create(EventKind.ALL_EVENTS).getEventMask()).isEqualTo(EventKind.ALL_EVENTS); + assertThat(create(EventKind.ERRORS_AND_WARNINGS).getEventMask()) + .isEqualTo(EventKind.ERRORS_AND_WARNINGS); + assertThat(create(EventKind.ERRORS).getEventMask()).isEqualTo(EventKind.ERRORS); } } diff --git a/src/test/java/com/google/devtools/build/lib/events/EventCollectorTest.java b/src/test/java/com/google/devtools/build/lib/events/EventCollectorTest.java index aab4a904ae..ce339c95bd 100644 --- a/src/test/java/com/google/devtools/build/lib/events/EventCollectorTest.java +++ b/src/test/java/com/google/devtools/build/lib/events/EventCollectorTest.java @@ -13,9 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.events; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; +import static com.google.common.truth.Truth.assertThat; import java.util.ArrayList; import java.util.Collection; @@ -36,13 +34,13 @@ public class EventCollectorTest extends EventTestTemplate { EventCollector collector = new EventCollector(EventKind.ALL_EVENTS, events); collector.handle(event); Event onlyEvent = events.iterator().next(); - assertEquals(event.getMessage(), onlyEvent.getMessage()); - assertSame(location, onlyEvent.getLocation()); - assertEquals(event.getKind(), onlyEvent.getKind()); - assertEquals(event.getLocation().getStartOffset(), - onlyEvent.getLocation().getStartOffset()); - assertEquals(1, collector.count()); - assertEquals(1, events.size()); + assertThat(onlyEvent.getMessage()).isEqualTo(event.getMessage()); + assertThat(onlyEvent.getLocation()).isSameAs(location); + assertThat(onlyEvent.getKind()).isEqualTo(event.getKind()); + assertThat(onlyEvent.getLocation().getStartOffset()) + .isEqualTo(event.getLocation().getStartOffset()); + assertThat(collector.count()).isEqualTo(1); + assertThat(events).hasSize(1); } @Test @@ -51,11 +49,11 @@ public class EventCollectorTest extends EventTestTemplate { collector.handle(event); Iterator<Event> collectedEventIt = collector.iterator(); Event onlyEvent = collectedEventIt.next(); - assertEquals(event.getMessage(), onlyEvent.getMessage()); - assertSame(location, onlyEvent.getLocation()); - assertEquals(event.getKind(), onlyEvent.getKind()); - assertEquals(event.getLocation().getStartOffset(), - onlyEvent.getLocation().getStartOffset()); - assertFalse(collectedEventIt.hasNext()); + assertThat(onlyEvent.getMessage()).isEqualTo(event.getMessage()); + assertThat(onlyEvent.getLocation()).isSameAs(location); + assertThat(onlyEvent.getKind()).isEqualTo(event.getKind()); + assertThat(onlyEvent.getLocation().getStartOffset()) + .isEqualTo(event.getLocation().getStartOffset()); + assertThat(collectedEventIt.hasNext()).isFalse(); } } diff --git a/src/test/java/com/google/devtools/build/lib/events/EventSensorTest.java b/src/test/java/com/google/devtools/build/lib/events/EventSensorTest.java index d765f23038..b98c36eec1 100644 --- a/src/test/java/com/google/devtools/build/lib/events/EventSensorTest.java +++ b/src/test/java/com/google/devtools/build/lib/events/EventSensorTest.java @@ -13,9 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.events; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import com.google.common.eventbus.EventBus; import org.junit.Test; @@ -30,9 +28,9 @@ public class EventSensorTest extends EventTestTemplate { @Test public void sensorStartsOutWithFalse() { - assertFalse(new EventSensor(EventKind.ALL_EVENTS).wasTriggered()); - assertFalse(new EventSensor(EventKind.ERRORS).wasTriggered()); - assertFalse(new EventSensor(EventKind.ERRORS_AND_WARNINGS).wasTriggered()); + assertThat(new EventSensor(EventKind.ALL_EVENTS).wasTriggered()).isFalse(); + assertThat(new EventSensor(EventKind.ERRORS).wasTriggered()).isFalse(); + assertThat(new EventSensor(EventKind.ERRORS_AND_WARNINGS).wasTriggered()).isFalse(); } @Test @@ -40,7 +38,7 @@ public class EventSensorTest extends EventTestTemplate { EventSensor sensor = new EventSensor(EventKind.ERRORS); Reporter reporter = new Reporter(new EventBus(), sensor); reporter.handle(Event.error(location, "An ERROR event.")); - assertTrue(sensor.wasTriggered()); + assertThat(sensor.wasTriggered()).isTrue(); } @Test @@ -49,7 +47,7 @@ public class EventSensorTest extends EventTestTemplate { Reporter reporter = new Reporter(new EventBus(), sensor); reporter.handle(Event.error(location, "An ERROR event.")); reporter.handle(Event.warn(location, "A warning event.")); - assertTrue(sensor.wasTriggered()); + assertThat(sensor.wasTriggered()).isTrue(); } @Test @@ -57,7 +55,7 @@ public class EventSensorTest extends EventTestTemplate { EventSensor sensor = new EventSensor(EventKind.ERRORS_AND_WARNINGS); Reporter reporter = new Reporter(new EventBus(), sensor); reporter.handle(Event.info(location, "An INFO event.")); - assertFalse(sensor.wasTriggered()); + assertThat(sensor.wasTriggered()).isFalse(); } @Test @@ -68,8 +66,8 @@ public class EventSensorTest extends EventTestTemplate { reporter.handle(Event.error(location, "Another ERROR event.")); reporter.handle(Event.warn(location, "A warning event.")); reporter.handle(Event.info(location, "An info event.")); // not in mask - assertEquals(3, sensor.getTriggerCount()); - assertTrue(sensor.wasTriggered()); + assertThat(sensor.getTriggerCount()).isEqualTo(3); + assertThat(sensor.wasTriggered()).isTrue(); } } diff --git a/src/test/java/com/google/devtools/build/lib/events/EventTest.java b/src/test/java/com/google/devtools/build/lib/events/EventTest.java index 28e9fe5b25..2bfe0593d8 100644 --- a/src/test/java/com/google/devtools/build/lib/events/EventTest.java +++ b/src/test/java/com/google/devtools/build/lib/events/EventTest.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.events; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,18 +28,18 @@ public class EventTest extends EventTestTemplate { @Test public void eventRetainsEventKind() { - assertEquals(EventKind.WARNING, event.getKind()); + assertThat(event.getKind()).isEqualTo(EventKind.WARNING); } @Test public void eventRetainsMessage() { - assertEquals("This is not an error message.", event.getMessage()); + assertThat(event.getMessage()).isEqualTo("This is not an error message."); } @Test public void eventRetainsLocation() { - assertEquals(21, event.getLocation().getStartOffset()); - assertEquals(31, event.getLocation().getEndOffset()); + assertThat(event.getLocation().getStartOffset()).isEqualTo(21); + assertThat(event.getLocation().getEndOffset()).isEqualTo(31); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/events/LocationTest.java b/src/test/java/com/google/devtools/build/lib/events/LocationTest.java index 5c1c8875ac..481ca8d0d0 100644 --- a/src/test/java/com/google/devtools/build/lib/events/LocationTest.java +++ b/src/test/java/com/google/devtools/build/lib/events/LocationTest.java @@ -13,11 +13,9 @@ // limitations under the License. package com.google.devtools.build.lib.events; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static com.google.common.truth.Truth.assertThat; import com.google.devtools.build.lib.vfs.PathFragment; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -28,31 +26,31 @@ public class LocationTest extends EventTestTemplate { @Test public void fromFile() throws Exception { Location location = Location.fromPathFragment(path); - assertEquals(path, location.getPath()); - assertEquals(0, location.getStartOffset()); - assertEquals(0, location.getEndOffset()); - assertNull(location.getStartLineAndColumn()); - assertNull(location.getEndLineAndColumn()); - assertEquals(path + ":1", location.print()); + assertThat(location.getPath()).isEqualTo(path); + assertThat(location.getStartOffset()).isEqualTo(0); + assertThat(location.getEndOffset()).isEqualTo(0); + assertThat(location.getStartLineAndColumn()).isNull(); + assertThat(location.getEndLineAndColumn()).isNull(); + assertThat(location.print()).isEqualTo(path + ":1"); } @Test public void testPrintRelative() throws Exception { Location location = Location.fromPathFragment(path); - assertEquals( - "/path/to/workspace/my/sample/path.txt:1", - location.print(PathFragment.create("/some/other/path"), PathFragment.create("baz"))); - assertEquals( - "new/sample/path.txt:1", - location.print(PathFragment.create("/path/to/workspace/my"), PathFragment.create("new"))); - assertEquals( - "new/path.txt:1", - location.print( - PathFragment.create("/path/to/workspace/my/sample"), PathFragment.create("new"))); - assertEquals( - "new:1", - location.print( - PathFragment.create("/path/to/workspace/my/sample/path.txt"), - PathFragment.create("new"))); + assertThat(location.print(PathFragment.create("/some/other/path"), PathFragment.create("baz"))) + .isEqualTo("/path/to/workspace/my/sample/path.txt:1"); + assertThat( + location.print( + PathFragment.create("/path/to/workspace/my"), PathFragment.create("new"))) + .isEqualTo("new/sample/path.txt:1"); + assertThat( + location.print( + PathFragment.create("/path/to/workspace/my/sample"), PathFragment.create("new"))) + .isEqualTo("new/path.txt:1"); + assertThat( + location.print( + PathFragment.create("/path/to/workspace/my/sample/path.txt"), + PathFragment.create("new"))) + .isEqualTo("new:1"); } } diff --git a/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java b/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java index 27617cb5fd..ebaac26578 100644 --- a/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java +++ b/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.events; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; @@ -55,7 +54,7 @@ public class ReporterTest extends EventTestTemplate { reporter.handle(interesting); reporter.handle(Event.warn(null, "ignore-me").withTag("good")); - assertEquals(ImmutableList.copyOf(collector), ImmutableList.of(interesting)); + assertThat(ImmutableList.of(interesting)).isEqualTo(ImmutableList.copyOf(collector)); } @Test @@ -67,7 +66,7 @@ public class ReporterTest extends EventTestTemplate { reporter.handle(e); } ImmutableList<Event> got = ImmutableList.copyOf(collector); - assertEquals(got, want); + assertThat(want).isEqualTo(got); } @Test @@ -79,10 +78,10 @@ public class ReporterTest extends EventTestTemplate { reporter.addHandler(outAppender); reporter.addHandler(outAppender); // Should have 4 handlers now. copiedReporter.handle(Event.error(location, ".")); - assertEquals("...", out.toString()); // The copied reporter has 3 handlers. + assertThat(out.toString()).isEqualTo("..."); // The copied reporter has 3 handlers. out = new StringBuilder(); reporter.handle(Event.error(location, ".")); - assertEquals("....", out.toString()); // The old reporter has 4 handlers. + assertThat(out.toString()).isEqualTo("...."); // The old reporter has 4 handlers. } @Test @@ -90,7 +89,7 @@ public class ReporterTest extends EventTestTemplate { assertThat(out.toString()).isEmpty(); reporter.addHandler(outAppender); reporter.handle(Event.error(location, "Event gets registered.")); - assertEquals("Event gets registered.", out.toString()); + assertThat(out.toString()).isEqualTo("Event gets registered."); out = new StringBuilder(); reporter.removeHandler(outAppender); reporter.handle(Event.error(location, "Event gets ignored.")); diff --git a/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java b/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java index f99df103d2..d314465bfe 100644 --- a/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java +++ b/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java @@ -13,7 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.events; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertThat; import com.google.common.eventbus.EventBus; import org.junit.Test; @@ -41,6 +41,6 @@ public class SimpleReportersTest extends EventTestTemplate { reporter.handle(Event.info(location, "Add to handlerCount.")); reporter.handle(Event.info(location, "Add to handlerCount.")); reporter.handle(Event.info(location, "Add to handlerCount.")); - assertEquals(3, handlerCount); + assertThat(handlerCount).isEqualTo(3); } } diff --git a/src/test/java/com/google/devtools/build/lib/events/StoredErrorEventHandlerTest.java b/src/test/java/com/google/devtools/build/lib/events/StoredErrorEventHandlerTest.java index 1a8fb6cc62..eff1c507a1 100644 --- a/src/test/java/com/google/devtools/build/lib/events/StoredErrorEventHandlerTest.java +++ b/src/test/java/com/google/devtools/build/lib/events/StoredErrorEventHandlerTest.java @@ -13,34 +13,28 @@ // limitations under the License. package com.google.devtools.build.lib.events; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; - +import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.util.List; - -/** - * Tests the {@link StoredEventHandler} class. - */ +/** Tests the {@link StoredEventHandler} class. */ @RunWith(JUnit4.class) public class StoredErrorEventHandlerTest { @Test public void hasErrors() { StoredEventHandler eventHandler = new StoredEventHandler(); - assertFalse(eventHandler.hasErrors()); + assertThat(eventHandler.hasErrors()).isFalse(); eventHandler.handle(Event.warn("warning")); - assertFalse(eventHandler.hasErrors()); + assertThat(eventHandler.hasErrors()).isFalse(); eventHandler.handle(Event.info("info")); - assertFalse(eventHandler.hasErrors()); + assertThat(eventHandler.hasErrors()).isFalse(); eventHandler.handle(Event.error("error")); - assertTrue(eventHandler.hasErrors()); + assertThat(eventHandler.hasErrors()).isTrue(); } @Test @@ -49,7 +43,7 @@ public class StoredErrorEventHandlerTest { StoredEventHandler sink = new StoredEventHandler(); eventHandler.replayOn(sink); - assertTrue(sink.isEmpty()); + assertThat(sink.isEmpty()).isTrue(); } @Test @@ -67,6 +61,6 @@ public class StoredErrorEventHandlerTest { } eventHandler.replayOn(sink); - assertEquals(events, sink.getEvents()); + assertThat(sink.getEvents()).isEqualTo(events); } } |