| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package io.v.syncbase.v23.services.syncbase.util; |
| |
| import static com.google.common.truth.Truth.assertThat; |
| import static com.google.common.truth.Truth.assert_; |
| |
| import java.util.Arrays; |
| import java.util.List; |
| |
| import junit.framework.TestCase; |
| |
| /** |
| * Tests the various {@link Util} methods. |
| */ |
| public class UtilTest extends TestCase { |
| public void testPrefixRange() { |
| List<String[]> tests = Arrays.asList(new String[][] { |
| {"", "", ""}, |
| {"a", "a", "b"}, |
| {"aa", "aa", "ab"}, |
| {"\u00fe", "\u00fe", "\u00ff"}, |
| {"a\u00fe", "a\u00fe", "a\u00ff"}, |
| {"aa\u00fe", "aa\u00fe", "aa\u00ff"}, |
| {"a\u00ff", "a\u00ff", "b"}, |
| {"aa\u00ff", "aa\u00ff", "ab"}, |
| {"a\u00ff\u00ff", "a\u00ff\u00ff", "b"}, |
| {"aa\u00ff\u00ff", "aa\u00ff\u00ff", "ab"}, |
| {"\u00ff", "\u00ff", ""}, |
| {"\u00ff\u00ff", "\u00ff\u00ff", ""} |
| }); |
| for (String[] test : tests) { |
| String prefix = test[0]; |
| String start = test[1]; |
| String limit = test[2]; |
| String actualStart = Util.prefixRangeStart(prefix); |
| String actualLimit = Util.prefixRangeLimit(prefix); |
| assert_().withFailureMessage("Failed for prefix: " + prefix) |
| .that(actualStart).isEqualTo(start); |
| assert_().withFailureMessage("Failed for prefix: " + prefix) |
| .that(actualLimit).isEqualTo(limit); |
| } |
| } |
| } |