| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package com.google.gitiles; |
| 16 | |
| 17 | import static com.google.gitiles.ConfigUtil.getDuration; |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 18 | import static org.junit.Assert.assertEquals; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 19 | |
| 20 | import org.eclipse.jgit.lib.Config; |
| 21 | import org.joda.time.Duration; |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 22 | import org.junit.Test; |
| Dave Borowitz | 3dc854f | 2014-11-04 16:19:37 -0800 | [diff] [blame] | 23 | import org.junit.runner.RunWith; |
| 24 | import org.junit.runners.JUnit4; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 25 | |
| 26 | /** Tests for configuration utilities. */ |
| Dave Borowitz | 3dc854f | 2014-11-04 16:19:37 -0800 | [diff] [blame] | 27 | @RunWith(JUnit4.class) |
| Dave Borowitz | d40bdf1 | 2014-04-19 19:33:56 -0700 | [diff] [blame] | 28 | public class ConfigUtilTest { |
| 29 | @Test |
| 30 | public void getDurationReturnsDuration() throws Exception { |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 31 | 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 | } |