ExperimentalStateTracker: make suffix gracefully handle negative length
When requested to produce a suffix of a string of a string
of a given length, gracefully handle the case where the requested
length is negative---simply return the empty string in
this case. While there, mark this static method as such; also
increase visibility to default as it is generally useful and
should be tested as an interface of this class.
--
Change-Id: I821966f7ba3828809bc6d000358803c131740ec9
Reviewed-on: https://bazel-review.googlesource.com/#/c/4223
MOS_MIGRATED_REVID=129080284
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java
index a416abf..a0f41d5 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java
@@ -13,6 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.runtime;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@@ -38,15 +39,13 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus;
-
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mockito;
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
/**
* Tests {@link ExperimentalStateTracker}.
*/
@@ -562,4 +561,12 @@
"Progress bar should contain 'Other action', but was:\n" + output,
output.contains("Other action"));
}
+
+
+ @Test
+ public void testSuffix() throws Exception {
+ assertEquals("bar", ExperimentalStateTracker.suffix("foobar", 3));
+ assertEquals("", ExperimentalStateTracker.suffix("foo", -2));
+ assertEquals("foobar", ExperimentalStateTracker.suffix("foobar", 200));
+ }
}