use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class MapBinderTests method bindToMapShouldBindToMapValue.
@Test
void bindToMapShouldBindToMapValue() {
ResolvableType type = ResolvableType.fromClassWithGenerics(Map.class, ResolvableType.fromClass(String.class), STRING_INTEGER_MAP.getType());
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar.baz", "1");
source.put("foo.bar.bin", "2");
source.put("foo.far.baz", "3");
source.put("foo.far.bin", "4");
source.put("faf.far.bin", "x");
this.sources.add(source);
Map<String, Map<String, Integer>> result = this.binder.bind("foo", Bindable.<Map<String, Map<String, Integer>>>of(type)).get();
assertThat(result).hasSize(2);
assertThat(result.get("bar")).containsEntry("baz", 1).containsEntry("bin", 2);
assertThat(result.get("far")).containsEntry("baz", 3).containsEntry("bin", 4);
}
use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class MapBinderTests method bindToMapShouldBindNestedMapValue.
@Test
void bindToMapShouldBindNestedMapValue() {
ResolvableType nestedType = ResolvableType.fromClassWithGenerics(Map.class, ResolvableType.fromClass(String.class), STRING_INTEGER_MAP.getType());
ResolvableType type = ResolvableType.fromClassWithGenerics(Map.class, ResolvableType.fromClass(String.class), nestedType);
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.nested.bar.baz", "1");
source.put("foo.nested.bar.bin", "2");
source.put("foo.nested.far.baz", "3");
source.put("foo.nested.far.bin", "4");
source.put("faf.nested.far.bin", "x");
this.sources.add(source);
Bindable<Map<String, Map<String, Map<String, Integer>>>> target = Bindable.of(type);
Map<String, Map<String, Map<String, Integer>>> result = this.binder.bind("foo", target).get();
Map<String, Map<String, Integer>> nested = result.get("nested");
assertThat(nested).hasSize(2);
assertThat(nested.get("bar")).containsEntry("baz", 1).containsEntry("bin", 2);
assertThat(nested.get("far")).containsEntry("baz", 3).containsEntry("bin", 4);
}
use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class BindableTests method ofTypeShouldSetType.
@Test
void ofTypeShouldSetType() {
ResolvableType type = ResolvableType.fromClass(String.class);
assertThat(Bindable.of(type).getType()).isEqualTo(type);
}
use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class Jackson2CborEncoderTests method canEncode.
@Test
public void canEncode() {
ResolvableType pojoType = ResolvableType.fromClass(Pojo.class);
assertThat(this.encoder.canEncode(pojoType, CBOR_MIME_TYPE)).isTrue();
assertThat(this.encoder.canEncode(pojoType, null)).isTrue();
// SPR-15464
assertThat(this.encoder.canEncode(ResolvableType.NONE, null)).isTrue();
}
use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class Jackson2CborEncoderTests method encodeStream.
@Test
public void encodeStream() {
Pojo pojo1 = new Pojo("foo", "bar");
Pojo pojo2 = new Pojo("foofoo", "barbar");
Pojo pojo3 = new Pojo("foofoofoo", "barbarbar");
Flux<Pojo> input = Flux.just(pojo1, pojo2, pojo3);
ResolvableType type = ResolvableType.fromClass(Pojo.class);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> encoder.encode(input, this.bufferFactory, type, CBOR_MIME_TYPE, null));
}
Aggregations