Skip to content

Commit

Permalink
"a".repeat is not available in Java 8, so create a helper function in…
Browse files Browse the repository at this point in the history
…stead.
  • Loading branch information
mingzhao-db committed Jan 3, 2022
1 parent 35e7d69 commit 560912a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions java/com/google/riegeli/RecordReadWriteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public class RecordReadWriteTest {
public void setUp() {
}

private String createTestString(int length) {
// String.repeat is only available from Java 11, so create a
// helper method instead.
return String.join("", java.util.Collections.nCopies(length, "a"));
}

@Test
public void writeWriteString() throws IOException {
// TODO: create a random file on TEST_TEMP directory.
Expand All @@ -21,7 +27,7 @@ public void writeWriteString() throws IOException {
writer.open(filename, "default");
final int kNumRecords = 4096;
for (int i = 0; i < kNumRecords; i++) {
final String s = "a".repeat(i + 1);
final String s = createTestString(i+1);
writer.writeRecord(s);
}
writer.close();
Expand All @@ -30,11 +36,11 @@ public void writeWriteString() throws IOException {
reader.open(filename);
for (int i = 0; i < kNumRecords; i++) {
byte[] record = reader.readRecord();
final String s = "a".repeat(i + 1);
final String s = createTestString(i+1);
assertEquals(new String(record), s);
}
byte[] record = reader.readRecord();
assertEquals(null, record);
reader.close();
}
}
}

0 comments on commit 560912a

Please sign in to comment.