Varint { protected static List<String> groupOfSevenBits(String binaryString) { binaryString = padStart(binaryString, (((binaryString.length() - 1) / 7) + 1) * 7, '0'); ArrayList<String> groups = newArrayList(); for (int i = 0; i < (binaryString.length() / 7); i++) { StringBuffer substring = new StringBuffer(binaryString.substring(i * 7, (i * 7) + 7)); substring.insert(3, ' '); groups.add(substring.toString()); } return groups; }  static String intToVarint(int input);  }
@Test public void should_pad_binary_with_seven_bytes_groups() { assertThat(Varint.groupOfSevenBits("1")).containsExactly("000 0001"); assertThat(Varint.groupOfSevenBits("10")).containsExactly("000 0010"); assertThat(Varint.groupOfSevenBits("1000")).containsExactly("000 1000"); assertThat(Varint.groupOfSevenBits("1111111")).containsExactly("111 1111"); assertThat(Varint.groupOfSevenBits("10000000")).containsExactly("000 0001", "000 0000"); assertThat(Varint.groupOfSevenBits("10000001")).containsExactly("000 0001", "000 0001"); assertThat(Varint.groupOfSevenBits("100000000")).containsExactly("000 0010", "000 0000"); assertThat(Varint.groupOfSevenBits("10000000000000")).containsExactly("100 0000", "000 0000"); assertThat(Varint.groupOfSevenBits("100000000000000")).containsExactly("000 0001", "000 0000", "000 0000"); }