Java Code Examples for com.google.inject.util.Types#listOf()
The following examples show how to use
com.google.inject.util.Types#listOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpParameterTest.java From wisdom with Apache License 2.0 | 6 votes |
@Test public void testHeaderWithMultipleValues() { Request request = mock(Request.class); Context ctx = mock(Context.class); when(ctx.request()).thenReturn(request); when(request.data()).thenReturn(Collections.<String, Object>emptyMap()); when(ctx.headers("header")).thenReturn(ImmutableList.of("value1", "value2")); when(ctx.header("header")).thenReturn("value1"); when(ctx.headers("count")).thenReturn(ImmutableList.of("1")); when(ctx.header("count")).thenReturn("1"); ActionParameter argument = new ActionParameter("header", Source.HTTP, List.class, Types.listOf(String.class)); assertThat((List) Bindings.create(argument, ctx, engine)).contains("value1", "value2"); argument = new ActionParameter("header", Source.HTTP, String.class, null); assertThat(Bindings.create(argument, ctx, engine)).isEqualTo("value1"); argument = new ActionParameter("count", Source.HTTP, Integer.class); assertThat(Bindings.create(argument, ctx, engine)).isEqualTo(1); argument = new ActionParameter("count", Source.HTTP, List.class, Types.listOf(Integer.class)); assertThat((List) Bindings.create(argument, ctx, engine)).containsExactly(1); }
Example 2
Source File: ConfigModule.java From proteus with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void bindConfig(final Config config) { traverse(this.binder(), "", config.root()); for (Entry<String, ConfigValue> entry : config.entrySet()) { String name = entry.getKey(); Named named = Names.named(name); Object value = entry.getValue().unwrapped(); if (value instanceof List) { List<Object> values = (List<Object>) value; Type listType = (values.size() == 0) ? String.class : Types.listOf(values.iterator().next().getClass()); Key<Object> key = (Key<Object>) Key.get(listType, Names.named(name)); this.binder().bind(key).toInstance(values); } else { this.binder().bindConstant().annotatedWith(named).to(value.toString()); } } Config referenceConfig = ConfigFactory.load(ConfigFactory.defaultReference()); this.config = ConfigFactory.load(config).withFallback(referenceConfig); log.debug(this.config.toString()); this.binder().bind(Config.class).toInstance(config); }
Example 3
Source File: HttpParameterTest.java From wisdom with Apache License 2.0 | 5 votes |
@Test public void testMissingHeader() { Request request = mock(Request.class); Context ctx = mock(Context.class); when(ctx.request()).thenReturn(request); when(request.data()).thenReturn(Collections.<String, Object>emptyMap()); when(ctx.headers("header")).thenReturn(ImmutableList.of("value1", "value2")); when(ctx.header("header")).thenReturn("value1"); when(ctx.headers("count")).thenReturn(ImmutableList.of("1")); when(ctx.header("count")).thenReturn("1"); ActionParameter argument = new ActionParameter("missing", Source.HTTP, List.class, Types.listOf(String.class)); assertThat((List) Bindings.create(argument, ctx, engine)).isEmpty(); argument = new ActionParameter("missing", Source.HTTP, String.class, null); assertThat((List) Bindings.create(argument, ctx, engine)).isNull(); }
Example 4
Source File: HttpParameterTest.java From wisdom with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testHeaderWithoutName() { Context ctx = mock(Context.class); when(ctx.headers("header")).thenReturn(ImmutableList.of("value1", "value2")); when(ctx.header("header")).thenReturn("value1"); when(ctx.headers("count")).thenReturn(ImmutableList.of("1")); when(ctx.header("count")).thenReturn("1"); ActionParameter argument = new ActionParameter(null, Source.HTTP, List.class, Types.listOf(String.class)); Bindings.create(argument, ctx, engine); fail("Should have failed"); }
Example 5
Source File: HttpParameterTest.java From wisdom with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testHeaderWithEmptyName() { Context ctx = mock(Context.class); when(ctx.headers("header")).thenReturn(ImmutableList.of("value1", "value2")); when(ctx.header("header")).thenReturn("value1"); when(ctx.headers("count")).thenReturn(ImmutableList.of("1")); when(ctx.header("count")).thenReturn("1"); ActionParameter argument = new ActionParameter("", Source.HTTP, List.class, Types.listOf(String.class)); Bindings.create(argument, ctx, engine); fail("Should have failed"); }
Example 6
Source File: HttpParameterTest.java From wisdom with Apache License 2.0 | 5 votes |
@Test public void testRequestScopeInjectionWithMultipleValues() { Request request = mock(Request.class); Context ctx = mock(Context.class); when(ctx.request()).thenReturn(request); when(request.data()).thenReturn(ImmutableMap.<String, Object>of( "data", ImmutableList.of("value1", "value2"), "key", "value", "count", 1 )); ActionParameter argument = new ActionParameter("data", Source.HTTP, List.class, Types.listOf(String.class)); assertThat((List) Bindings.create(argument, ctx, engine)).contains("value1", "value2"); }
Example 7
Source File: HttpParameterTest.java From wisdom with Apache License 2.0 | 5 votes |
@Test public void testMissingRequestScopeValue() { Request request = mock(Request.class); Context ctx = mock(Context.class); when(ctx.request()).thenReturn(request); when(request.data()).thenReturn(ImmutableMap.<String, Object>of( "data", ImmutableList.of("value1", "value2"), "key", "value", "count", 1 )); ActionParameter argument = new ActionParameter("missing", Source.HTTP, List.class, Types.listOf(String.class)); assertThat((List) Bindings.create(argument, ctx, engine)).isEmpty(); argument = new ActionParameter("missing", Source.HTTP, String.class, null); assertThat((List) Bindings.create(argument, ctx, engine)).isNull(); }
Example 8
Source File: HttpParameterTest.java From wisdom with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testRequestScopeInjectionWithoutName() { Request request = mock(Request.class); Context ctx = mock(Context.class); when(ctx.request()).thenReturn(request); when(request.data()).thenReturn(ImmutableMap.<String, Object>of( "data", ImmutableList.of("value1", "value2"), "key", "value", "count", 1 )); ActionParameter argument = new ActionParameter(null, Source.HTTP, List.class, Types.listOf(String.class)); Bindings.create(argument, ctx, engine); fail("Should have failed"); }