From 928286ad8f5713dbacee033250ee63fc7072e6bc Mon Sep 17 00:00:00 2001 From: Tomasz Zarna Date: Mon, 10 Dec 2012 11:20:06 +0100 Subject: [PATCH] Return info about config subsection when trying to get an invalid enum Change-Id: Id4a72a68bdbd485619f4801683d38ad98f9841a2 --- .../tst/org/eclipse/jgit/lib/ConfigTest.java | 19 +++++++++++++++++++ .../src/org/eclipse/jgit/lib/Config.java | 10 ++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index f02012eb5..983603623 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -292,6 +292,25 @@ public class ConfigTest { assertSame(TestEnum.ONE_TWO, c.getEnum("s", "b", "c", TestEnum.ONE_TWO)); } + @Test + public void testGetInvalidEnum() throws ConfigInvalidException { + Config c = parse("[a]\n\tb = invalid\n"); + try { + c.getEnum("a", null, "b", TestEnum.ONE_TWO); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Invalid value: a.b=invalid", e.getMessage()); + } + + c = parse("[a \"b\"]\n\tc = invalid\n"); + try { + c.getEnum("a", "b", "c", TestEnum.ONE_TWO); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Invalid value: a.b.c=invalid", e.getMessage()); + } + } + @Test public void testSetEnum() { final Config c = new Config(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index 348e1175d..fb78d0eff 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -412,11 +412,13 @@ public class Config { } if (subsection != null) - throw new IllegalArgumentException(MessageFormat.format(JGitText - .get().enumValueNotSupported3, section, name, value)); + throw new IllegalArgumentException(MessageFormat.format( + JGitText.get().enumValueNotSupported3, section, subsection, + name, value)); else - throw new IllegalArgumentException(MessageFormat.format(JGitText - .get().enumValueNotSupported2, section, name, value)); + throw new IllegalArgumentException( + MessageFormat.format(JGitText.get().enumValueNotSupported2, + section, name, value)); } /**