-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add correct message, when set duration / period value in wrong format. (
- Loading branch information
Showing
4 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...rc/test/groovy/io/micronaut/runtime/converters/time/TimeConverterConfigurationSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.micronaut.runtime.converters.time | ||
|
||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.context.annotation.Value | ||
import io.micronaut.context.exceptions.DependencyInjectionException | ||
import jakarta.inject.Singleton | ||
import java.time.Duration | ||
import spock.lang.Specification | ||
|
||
class TimeConverterConfigurationSpec extends Specification { | ||
|
||
void 'test exception message with incorrect duration value'() { | ||
given: | ||
ApplicationContext ctx = ApplicationContext.run([ | ||
'spec.name' : 'TimeConverterRegistrarSpec', | ||
'health-check-cache-expiration': '60 seconds', | ||
]) | ||
|
||
when: | ||
var myTask = ctx.getBean(MyTask) | ||
|
||
then: | ||
var e = thrown(DependencyInjectionException.class) | ||
e.message.contains("Error resolving property value [\${health-check-cache-expiration}]. Unable to convert value [60 seconds] to target type [Duration] due to: Unparseable date format (60 seconds). Should either be a ISO-8601 duration or a round number followed by the unit type") | ||
} | ||
|
||
@Singleton | ||
@Requires(property = 'spec.name', value = 'TimeConverterRegistrarSpec') | ||
static class MyTask { | ||
|
||
@Value("\${health-check-cache-expiration}") | ||
private Duration healthCheckCacheExpiration; | ||
|
||
Duration getHealthCheckCacheExpiration() { | ||
return healthCheckCacheExpiration | ||
} | ||
|
||
void setHealthCheckCacheExpiration(Duration healthCheckCacheExpiration) { | ||
this.healthCheckCacheExpiration = healthCheckCacheExpiration | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters