PageRenderTime 35ms CodeModel.GetById 32ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 1ms

/core/src/test/java/org/jclouds/config/ValueOfConfigurationKeyOrNullTest.java

https://github.com/richardcloudsoft/legacy-jclouds
Java | 65 lines | 31 code | 11 blank | 23 comment | 0 complexity | 7d27714bee9d36e99128505f569d886a MD5 | raw file
 1/**
 2 * Licensed to jclouds, Inc. (jclouds) under one or more
 3 * contributor license agreements.  See the NOTICE file
 4 * distributed with this work for additional information
 5 * regarding copyright ownership.  jclouds licenses this file
 6 * to you under the Apache License, Version 2.0 (the
 7 * "License"); you may not use this file except in compliance
 8 * with the License.  You may obtain a copy of the License at
 9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.config;
20
21import static org.testng.Assert.assertEquals;
22
23import org.testng.annotations.Test;
24
25import com.google.inject.AbstractModule;
26import com.google.inject.Guice;
27import com.google.inject.name.Names;
28
29/**
30 * Tests behavior of ValueOfConfigurationKeyOrNull
31 * 
32 * @author Adrian Cole
33 */
34@Test(groups = "unit")
35public class ValueOfConfigurationKeyOrNullTest {
36
37   @Test
38   public void testNotThere() {
39      assertEquals(Guice.createInjector().getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), null);
40   }
41
42   @Test
43   public void testThere() {
44      assertEquals(Guice.createInjector(new AbstractModule() {
45
46         @Override
47         protected void configure() {
48            bindConstant().annotatedWith(Names.named("foo")).to("bar");
49         }
50
51      }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), "bar");
52   }
53   
54   @Test
55   public void testEmptyIsThere() {
56      assertEquals(Guice.createInjector(new AbstractModule() {
57
58         @Override
59         protected void configure() {
60            bindConstant().annotatedWith(Names.named("foo")).to("");
61         }
62
63      }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), "");
64   }
65}