Пример #1
0
  @Test
  public void testKeyToSegmentsMethod() throws Exception {
    Object configOption =
        ReflectionUtils.callConstructor(
            ConfigOption.class,
            new Object[] {new URI(""), FileRepositoryBuilder.create(new File(""))});

    String[] segments =
        (String[])
            ReflectionUtils.callMethod(configOption, "keyToSegments", new Object[] {"a.b.c"});
    assertArrayEquals(new String[] {"a", "b", "c"}, segments);

    segments =
        (String[]) ReflectionUtils.callMethod(configOption, "keyToSegments", new Object[] {"a.c"});
    assertArrayEquals(new String[] {"a", null, "c"}, segments);

    segments =
        (String[])
            ReflectionUtils.callMethod(configOption, "keyToSegments", new Object[] {"a.b.c.d"});
    assertArrayEquals(new String[] {"a", "b.c", "d"}, segments);

    segments =
        (String[]) ReflectionUtils.callMethod(configOption, "keyToSegments", new Object[] {"a"});
    assertArrayEquals(null, segments);
  }
Пример #2
0
  @Test
  public void testSegmentsToKeyMethod() throws Exception {
    Object configOption =
        ReflectionUtils.callConstructor(
            ConfigOption.class,
            new Object[] {new URI(""), FileRepositoryBuilder.create(new File(""))});

    String key =
        (String)
            ReflectionUtils.callMethod(
                configOption, "segmentsToKey", new Object[] {new String[] {"a", "b", "c"}});
    assertEquals("a.b.c", key);

    key =
        (String)
            ReflectionUtils.callMethod(
                configOption, "segmentsToKey", new Object[] {new String[] {"a", null, "c"}});
    assertEquals("a.c", key);

    key =
        (String)
            ReflectionUtils.callMethod(
                configOption, "segmentsToKey", new Object[] {new String[] {"a", "b.c", "d"}});
    assertEquals("a.b.c.d", key);

    key =
        (String)
            ReflectionUtils.callMethod(
                configOption, "segmentsToKey", new Object[] {new String[] {"a", "b"}});
    assertEquals(null, key);

    key =
        (String)
            ReflectionUtils.callMethod(
                configOption, "segmentsToKey", new Object[] {new String[] {"a", "b", "c", "d"}});
    assertEquals(null, key);
  }