Skip to content

Commit

Permalink
Add ConfigValue test for missing expression
Browse files Browse the repository at this point in the history
  • Loading branch information
barchetta committed May 14, 2024
1 parent bbfa0d0 commit 73b7224
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
import java.util.Optional;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigValue;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class MpConfigReferenceTest {
Expand Down Expand Up @@ -65,6 +68,15 @@ void testMissingRefs() {
// since Config 2.0, missing references must throw an exception
assertThrows(NoSuchElementException.class, () -> config.getValue("referencing4-1", String.class));
assertThrows(NoSuchElementException.class, () -> config.getValue( "referencing4-2", String.class));

// MP Config 3.1 TCK requires well-formed ConfigValue when missing reference
ConfigValue configValue = config.getConfigValue("referencing4-1");
assertThat(configValue, notNullValue());
assertThat(configValue.getName(), is("referencing4-1"));
assertThat(configValue.getValue(), nullValue());
assertThat(configValue.getRawValue(), is("${missing}"));
assertThat(configValue.getSourceName(), endsWith("microprofile-config.properties"));
assertThat(configValue.getSourceOrdinal(), is(100));
}

@Test
Expand Down

0 comments on commit 73b7224

Please sign in to comment.