PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/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. */
  19. package org.jclouds.config;
  20. import static org.testng.Assert.assertEquals;
  21. import org.testng.annotations.Test;
  22. import com.google.inject.AbstractModule;
  23. import com.google.inject.Guice;
  24. import com.google.inject.name.Names;
  25. /**
  26. * Tests behavior of ValueOfConfigurationKeyOrNull
  27. *
  28. * @author Adrian Cole
  29. */
  30. @Test(groups = "unit")
  31. public class ValueOfConfigurationKeyOrNullTest {
  32. @Test
  33. public void testNotThere() {
  34. assertEquals(Guice.createInjector().getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), null);
  35. }
  36. @Test
  37. public void testThere() {
  38. assertEquals(Guice.createInjector(new AbstractModule() {
  39. @Override
  40. protected void configure() {
  41. bindConstant().annotatedWith(Names.named("foo")).to("bar");
  42. }
  43. }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), "bar");
  44. }
  45. @Test
  46. public void testEmptyIsThere() {
  47. assertEquals(Guice.createInjector(new AbstractModule() {
  48. @Override
  49. protected void configure() {
  50. bindConstant().annotatedWith(Names.named("foo")).to("");
  51. }
  52. }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), "");
  53. }
  54. }