Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Throw an exception in case of missing property
Browse files Browse the repository at this point in the history
  • Loading branch information
geofjamg committed May 22, 2017
1 parent db783c2 commit be97761
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ class IdentifiableExtension {
static Object propertyMissing(Identifiable self, String name) {
// first check if an extension exist then a property
Identifiable.Extension extension = self.getExtensionByName(name)
extension != null ? extension : self.properties[name]
if (extension != null) {
extension
} else {
Object value = self.properties[name]
if (value == null) {
throw new RuntimeException("Property '" + name + "' of '" + self.id + "' not found")
}
value
}
}

static void propertyMissing(Identifiable self, String name, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,23 @@ class IdentifiableExtensionTest {
@Test
void testProperty() {
assertFalse(s.hasProperty())
assertNull(s.greeting)
try {
s.greeting
fail()
} catch (Exception ignored) {
}
s.greeting = "hello"
assertEquals("hello", s.getProperties().getProperty("greeting"))
assertEquals("hello", s.greeting)
}

@Test
void testExtension() {
try {
s.foo
fail()
} catch (Exception ignored) {
}
s.addExtension(Substation.class, new Foo())
assertNotNull(s.foo)
s.foo.value = 3f
Expand Down

0 comments on commit be97761

Please sign in to comment.