Search in sources :

Example 1 with OriginProvider

use of org.springframework.boot.origin.OriginProvider in project spring-boot by spring-projects.

the class ConfigurationPropertyTests method getPropertyOriginShouldReturnValuePropertyOrigin.

@Test
void getPropertyOriginShouldReturnValuePropertyOrigin() {
    Origin origin = mock(Origin.class);
    OriginProvider property = ConfigurationProperty.of(this.source, NAME, "foo", origin);
    assertThat(property.getOrigin()).isEqualTo(origin);
}
Also used : Origin(org.springframework.boot.origin.Origin) OriginProvider(org.springframework.boot.origin.OriginProvider) Test(org.junit.jupiter.api.Test)

Example 2 with OriginProvider

use of org.springframework.boot.origin.OriginProvider in project spring-boot by spring-projects.

the class InputStreamSourceToByteArrayConverterTests method convertWhenFailsWithIOExceptionFromOriginProviderThrowsException.

@ConversionServiceTest
void convertWhenFailsWithIOExceptionFromOriginProviderThrowsException(ConversionService conversionService) throws Exception {
    Origin origin = new TestOrigin("mylocation");
    InputStreamSource source = mock(InputStreamSource.class, withSettings().extraInterfaces(OriginProvider.class));
    given(source.getInputStream()).willThrow(IOException.class);
    given(((OriginProvider) source).getOrigin()).willReturn(origin);
    assertThatExceptionOfType(ConversionFailedException.class).isThrownBy(() -> conversionService.convert(source, byte[].class)).withCauseExactlyInstanceOf(IllegalStateException.class).withMessageContaining("Unable to read from mylocation");
}
Also used : Origin(org.springframework.boot.origin.Origin) InputStreamSource(org.springframework.core.io.InputStreamSource) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) OriginProvider(org.springframework.boot.origin.OriginProvider)

Aggregations

Origin (org.springframework.boot.origin.Origin)2 OriginProvider (org.springframework.boot.origin.OriginProvider)2 Test (org.junit.jupiter.api.Test)1 ConversionFailedException (org.springframework.core.convert.ConversionFailedException)1 InputStreamSource (org.springframework.core.io.InputStreamSource)1