blob: a767b0d489ce67daa9efcb5f6a5e741ccb8b4f51 [file] [log] [blame]
Dave Borowitz9de65952012-08-13 16:09:45 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.gitiles;
16
17import static com.google.gitiles.ConfigUtil.getDuration;
Dave Borowitzd40bdf12014-04-19 19:33:56 -070018import static org.junit.Assert.assertEquals;
Dave Borowitz9de65952012-08-13 16:09:45 -070019
20import org.eclipse.jgit.lib.Config;
21import org.joda.time.Duration;
Dave Borowitzd40bdf12014-04-19 19:33:56 -070022import org.junit.Test;
Dave Borowitz3dc854f2014-11-04 16:19:37 -080023import org.junit.runner.RunWith;
24import org.junit.runners.JUnit4;
Dave Borowitz9de65952012-08-13 16:09:45 -070025
26/** Tests for configuration utilities. */
Dave Borowitz3dc854f2014-11-04 16:19:37 -080027@RunWith(JUnit4.class)
Dave Borowitzd40bdf12014-04-19 19:33:56 -070028public class ConfigUtilTest {
29 @Test
30 public void getDurationReturnsDuration() throws Exception {
Dave Borowitz9de65952012-08-13 16:09:45 -070031 Duration def = Duration.standardSeconds(2);
32 Config config = new Config();
33 Duration t;
34
35 config.setString("core", "dht", "timeout", "500 ms");
36 t = getDuration(config, "core", "dht", "timeout", def);
37 assertEquals(500, t.getMillis());
38
39 config.setString("core", "dht", "timeout", "5.2 sec");
40 t = getDuration(config, "core", "dht", "timeout", def);
41 assertEquals(5200, t.getMillis());
42
43 config.setString("core", "dht", "timeout", "1 min");
44 t = getDuration(config, "core", "dht", "timeout", def);
45 assertEquals(60000, t.getMillis());
46 }
47}