@Test public void TestOneError() { Problems problems = new Problems(); problems.addError("message %d", 1); Message[] errors = problems.getErrors().toArray(new Message[] {}); assertEquals(errors.length, 1); assertContainsAllOf(errors[0].toString(), "Error", "message 1"); assertEquals(problems.getWarnings().size(), 0, "Found unexpected warnings in problem object"); try { problems.throwIfHasErrors(); fail("Expected exception from problems object"); } catch (ConfigurationException e) { assertContainsAllOf(e.getMessage(), "message 1"); } }
@Test public void testAnnotatedGettersThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "some value"); properties.put("boolean-value", "true"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(AnnotatedGetter.class)); Assert.fail("Expected an exception in object creation due to conflicting configuration"); } catch (CreationException e) { monitor.assertNumberOfErrors(2); Assertions.assertContainsAllOf(e.getMessage(), "not a valid setter", "getStringValue") ; Assertions.assertContainsAllOf(e.getMessage(), "not a valid setter", "isBooleanValue") ; } }
@Test public void TestOneError() { Problems problems = new Problems(); problems.addError("message %d", 1); Message[] errors = problems.getErrors().toArray(new Message[] {}); assertEquals(errors.length, 1); assertContainsAllOf(errors[0].toString(), "Error", "message 1"); assertEquals(problems.getWarnings().size(), 0, "Found unexpected warnings in problem object"); try { problems.throwIfHasErrors(); fail("Expected exception from problems object"); } catch (ConfigurationException e) { assertContainsAllOf(e.getMessage(), "message 1"); } }
@Test public void TestOneWarning() { Problems problems = new Problems(); problems.addWarning("message %d", 1); Assert.assertEquals(problems.getErrors().size(), 0, "Found unexpected errors in problem object"); Message [] warnings = problems.getWarnings().toArray(new Message[]{}); Assert.assertEquals(warnings.length, 1); Assertions.assertContainsAllOf(warnings[0].toString(), "Warning", "message 1"); try { problems.throwIfHasErrors(); } catch(ConfigurationException cause) { Assert.fail("Didn't expect problems object to throw", cause); } }
@Test public void testAnnotatedGettersThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "some value"); properties.put("boolean-value", "true"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(AnnotatedGetter.class)); fail("Expected an exception in object creation due to conflicting configuration"); } catch (CreationException e) { monitor.assertNumberOfErrors(2); assertContainsAllOf(e.getMessage(), "not a valid setter", "getStringValue"); assertContainsAllOf(e.getMessage(), "not a valid setter", "isBooleanValue"); } }
@Test public void testAnnotatedGettersThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "some value"); properties.put("boolean-value", "true"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(AnnotatedGetter.class)); fail("Expected an exception in object creation due to conflicting configuration"); } catch (CreationException e) { monitor.assertNumberOfErrors(2); assertContainsAllOf(e.getMessage(), "not a valid setter", "getStringValue"); assertContainsAllOf(e.getMessage(), "not a valid setter", "isBooleanValue"); } }
@Test public void TestTwoErrors() { Problems problems = new Problems(); problems.addError("message %d", 1); problems.addError("message %d", 2); Message[] errors = problems.getErrors().toArray(new Message[] {}); assertEquals(errors.length, 2); assertContainsAllOf(errors[0].toString(), "Error", "message 1"); assertContainsAllOf(errors[1].toString(), "Error", "message 2"); assertEquals(problems.getWarnings().size(), 0, "Found unexpected warnings in problem object"); try { problems.throwIfHasErrors(); fail("Expected exception from problems object"); } catch (ConfigurationException e) { assertContainsAllOf(e.getMessage(), "message 1", "message 2"); } }
@Test public void TestFormatWarning() { Problems problems = new Problems(); problems.addWarning("message %d", "NaN"); assertEquals(problems.getErrors().size(), 0, "Found unexpected errors in problem object"); Message[] warnings = problems.getWarnings().toArray(new Message[] {}); assertEquals(warnings.length, 1); assertContainsAllOf(warnings[0].toString(), "Warning", "message %d", "NaN", "IllegalFormatConversionException"); try { problems.throwIfHasErrors(); } catch (ConfigurationException cause) { fail("Didn't expect problems object to throw", cause); } }
@Test public void TestOneWarning() { Problems problems = new Problems(); problems.addWarning("message %d", 1); assertEquals(problems.getErrors().size(), 0, "Found unexpected errors in problem object"); Message[] warnings = problems.getWarnings().toArray(new Message[] {}); assertEquals(warnings.length, 1); assertContainsAllOf(warnings[0].toString(), "Warning", "message 1"); try { problems.throwIfHasErrors(); } catch (ConfigurationException cause) { fail("Didn't expect problems object to throw", cause); } }
@Test public void TestOneWarning() { Problems problems = new Problems(); problems.addWarning("message %d", 1); assertEquals(problems.getErrors().size(), 0, "Found unexpected errors in problem object"); Message[] warnings = problems.getWarnings().toArray(new Message[] {}); assertEquals(warnings.length, 1); assertContainsAllOf(warnings[0].toString(), "Warning", "message 1"); try { problems.throwIfHasErrors(); } catch (ConfigurationException cause) { fail("Didn't expect problems object to throw", cause); } }
@Test public void TestFormatWarning() { Problems problems = new Problems(); problems.addWarning("message %d", "NaN"); assertEquals(problems.getErrors().size(), 0, "Found unexpected errors in problem object"); Message[] warnings = problems.getWarnings().toArray(new Message[] {}); assertEquals(warnings.length, 1); assertContainsAllOf(warnings[0].toString(), "Warning", "message %d", "NaN", "IllegalFormatConversionException"); try { problems.throwIfHasErrors(); } catch (ConfigurationException cause) { fail("Didn't expect problems object to throw", cause); } }
@Test public void TestTwoWarnings() { Problems problems = new Problems(); problems.addWarning("message %d", 1); problems.addWarning("message %d", 2); assertEquals(problems.getErrors().size(), 0, "Found unexpected errors in problem object"); Message[] warnings = problems.getWarnings().toArray(new Message[] {}); assertEquals(warnings.length, 2); assertContainsAllOf(warnings[0].toString(), "Warning", "message 1"); assertContainsAllOf(warnings[1].toString(), "Warning", "message 2"); try { problems.throwIfHasErrors(); } catch (ConfigurationException cause) { fail("Didn't expect problems object to throw", cause); } }
@Test public void TestTwoWarnings() { Problems problems = new Problems(); problems.addWarning("message %d", 1); problems.addWarning("message %d", 2); Assert.assertEquals(problems.getErrors().size(), 0, "Found unexpected errors in problem object"); Message [] warnings = problems.getWarnings().toArray(new Message[]{}); Assert.assertEquals(warnings.length, 2); Assertions.assertContainsAllOf(warnings[0].toString(), "Warning", "message 1"); Assertions.assertContainsAllOf(warnings[1].toString(), "Warning", "message 2"); try { problems.throwIfHasErrors(); } catch(ConfigurationException cause) { Assert.fail("Didn't expect problems object to throw", cause); } }
@Test public void TestTwoWarnings() { Problems problems = new Problems(); problems.addWarning("message %d", 1); problems.addWarning("message %d", 2); assertEquals(problems.getErrors().size(), 0, "Found unexpected errors in problem object"); Message[] warnings = problems.getWarnings().toArray(new Message[] {}); assertEquals(warnings.length, 2); assertContainsAllOf(warnings[0].toString(), "Warning", "message 1"); assertContainsAllOf(warnings[1].toString(), "Warning", "message 2"); try { problems.throwIfHasErrors(); } catch (ConfigurationException cause) { fail("Didn't expect problems object to throw", cause); } }
@Test public void TestFormatError() { Problems problems = new Problems(); problems.addError("message %d", "NaN"); Message[] errors = problems.getErrors().toArray(new Message[] {}); assertEquals(errors.length, 1); assertContainsAllOf(errors[0].toString(), "Error", "message %d", "NaN", "IllegalFormatConversionException"); assertEquals(problems.getWarnings().size(), 0, "Found unexpected warnings in problem object"); try { problems.throwIfHasErrors(); fail("Expected exception from problems object"); } catch (ConfigurationException e) { assertContains(e.getMessage(), "message %d [NaN]"); } }
@Test public void TestFormatError() { Problems problems = new Problems(); problems.addError("message %d", "NaN"); Message[] errors = problems.getErrors().toArray(new Message[] {}); assertEquals(errors.length, 1); assertContainsAllOf(errors[0].toString(), "Error", "message %d", "NaN", "IllegalFormatConversionException"); assertEquals(problems.getWarnings().size(), 0, "Found unexpected warnings in problem object"); try { problems.throwIfHasErrors(); fail("Expected exception from problems object"); } catch (ConfigurationException e) { assertContains(e.getMessage(), "message %d [NaN]"); } }
@Test public void testConfigurationWithConflictingLegacyConfigThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is the old value"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); fail("Expected an exception in object creation due to conflicting configuration"); } catch (CreationException e) { monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); assertContainsAllOf(e.getMessage(), "string-value", "conflicts with property", "string-a"); } }
@Test public void testConfigurationWithRedundantLegacyConfigThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is a"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); } catch (CreationException e) { monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); assertContainsAllOf(e.getMessage(), "string-value", "conflicts with property", "string-a"); } }
@Test public void testConfigurationWithConflictingLegacyConfigThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is the old value"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); Assert.fail("Expected an exception in object creation due to conflicting configuration"); } catch (CreationException e) { monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); Assertions.assertContainsAllOf(e.getMessage(), "string-value", "conflicts with property", "string-a") ; } }
@Test public void testConfigurationWithRedundantLegacyConfigThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is a"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); } catch (CreationException e) { monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); assertContainsAllOf(e.getMessage(), "string-value", "conflicts with property", "string-a"); } }