private Object getClassInstance(final Class<?> clz) { if (injector != null && clz != null) { try { return injector.getInstance(clz); } catch (final ConfigurationException e) { LOG.error(e.getMessage(), e); return null; } } return null; }
public void testNonAssistedFactoryMethodParameter() { try { FactoryProvider.newFactory(NamedParameterFactory.class, Mustang.class); fail(); } catch (ConfigurationException expected) { assertContains( expected.getMessage(), "Only @Assisted is allowed for factory parameters, but found @" + Named.class.getName()); } }
public void testFactoryMethodsMismatch() { try { FactoryProvider.newFactory(SummerCarFactory.class, Beetle.class); fail(); } catch (ConfigurationException e) { assertContains(e.getMessage(), "Constructor mismatch"); } }
public void testFactoryMethodMustDeclareAllConstructorExceptions() { try { FactoryProvider.newFactory(DefectiveCarFactoryWithNoExceptions.class, DefectiveCar.class); fail(); } catch (ConfigurationException expected) { assertContains(expected.getMessage(), "no compatible exception is thrown"); } }
@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 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 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 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 TestOneError() { Problems problems = new Problems(); problems.addError("message %d", 1); Message [] errors = problems.getErrors().toArray(new Message[]{}); Assert.assertEquals(errors.length, 1); Assertions.assertContainsAllOf(errors[0].toString(), "Error", "message 1"); Assert.assertEquals(problems.getWarnings().size(), 0, "Found unexpected warnings in problem object"); try { problems.throwIfHasErrors(); Assert.fail("Expected exception from problems object"); } catch(ConfigurationException e) { Assertions.assertContainsAllOf(e.getMessage(), "message 1"); } }
@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[]{}); Assert.assertEquals(errors.length, 2); Assertions.assertContainsAllOf(errors[0].toString(), "Error", "message 1"); Assertions.assertContainsAllOf(errors[1].toString(), "Error", "message 2"); Assert.assertEquals(problems.getWarnings().size(), 0, "Found unexpected warnings in problem object"); try { problems.throwIfHasErrors(); Assert.fail("Expected exception from problems object"); } catch(ConfigurationException e) { Assertions.assertContainsAllOf(e.getMessage(), "message 1", "message 2"); } }
@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 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 TestErrorsAndWarnings() { Problems problems = new Problems(); problems.addError("message e%d", 1); problems.addError("message e%d", 2); problems.addWarning("message w%d", 1); problems.addWarning("message w%d", 2); problems.addWarning("message w%d", 3); Message[] errors = problems.getErrors().toArray(new Message[] {}); assertEquals(errors.length, 2); assertContainsAllOf(errors[0].toString(), "Error", "message e1"); assertContainsAllOf(errors[1].toString(), "Error", "message e2"); Message[] warnings = problems.getWarnings().toArray(new Message[] {}); assertEquals(warnings.length, 3); assertContainsAllOf(warnings[0].toString(), "Warning", "message w1"); assertContainsAllOf(warnings[1].toString(), "Warning", "message w2"); assertContainsAllOf(warnings[2].toString(), "Warning", "message w3"); try { problems.throwIfHasErrors(); fail("Expected exception from problems object"); } catch (ConfigurationException e) { assertContainsAllOf(e.getMessage(), "message e1", "message e2", "message w1", "message w2", "message w3"); } }
@Test public void TestErrorsAndWarnings() { Problems problems = new Problems(); problems.addError("message e%d", 1); problems.addError("message e%d", 2); problems.addWarning("message w%d", 1); problems.addWarning("message w%d", 2); problems.addWarning("message w%d", 3); Message[] errors = problems.getErrors().toArray(new Message[] {}); assertEquals(errors.length, 2); assertContainsAllOf(errors[0].toString(), "Error", "message e1"); assertContainsAllOf(errors[1].toString(), "Error", "message e2"); Message[] warnings = problems.getWarnings().toArray(new Message[] {}); assertEquals(warnings.length, 3); assertContainsAllOf(warnings[0].toString(), "Warning", "message w1"); assertContainsAllOf(warnings[1].toString(), "Warning", "message w2"); assertContainsAllOf(warnings[2].toString(), "Warning", "message w3"); try { problems.throwIfHasErrors(); fail("Expected exception from problems object"); } catch (ConfigurationException e) { assertContainsAllOf(e.getMessage(), "message e1", "message e2", "message w1", "message w2", "message w3"); } }
@Test public void TestErrorsAndWarnings() { Problems problems = new Problems(); problems.addError("message e%d", 1); problems.addError("message e%d", 2); problems.addWarning("message w%d", 1); problems.addWarning("message w%d", 2); problems.addWarning("message w%d", 3); Message [] errors = problems.getErrors().toArray(new Message[]{}); Assert.assertEquals(errors.length, 2); Assertions.assertContainsAllOf(errors[0].toString(), "Error", "message e1"); Assertions.assertContainsAllOf(errors[1].toString(), "Error", "message e2"); Message [] warnings = problems.getWarnings().toArray(new Message[]{}); Assert.assertEquals(warnings.length, 3); Assertions.assertContainsAllOf(warnings[0].toString(), "Warning", "message w1"); Assertions.assertContainsAllOf(warnings[1].toString(), "Warning", "message w2"); Assertions.assertContainsAllOf(warnings[2].toString(), "Warning", "message w3"); try { problems.throwIfHasErrors(); Assert.fail("Expected exception from problems object"); } catch(ConfigurationException e) { Assertions.assertContainsAllOf(e.getMessage(), "message e1", "message e2", "message w1", "message w2", "message w3"); } }