public ProvisionException(String message, Throwable cause) { super(cause); this.messages = ImmutableSet.of(new Message(message, cause)); }
public ProvisionException(String message) { this.messages = ImmutableSet.of(new Message(message)); }
@Override public Message apply(String input) { return new Message(StringUtils.format("%s%s", propertyBase, input)); } }
@Override public void addError(Throwable t) { String message = "An exception was caught and reported. Message: " + t.getMessage(); elements.add(new Message(ImmutableList.of((Object) getElementSource()), message, t)); }
/** * Throws a ConfigurationException with an NullPointerExceptions as the cause if the given * reference is {@code null}. */ static <T> T checkNotNull(T reference, String name) { if (reference != null) { return reference; } NullPointerException npe = new NullPointerException(name); throw new ConfigurationException(ImmutableSet.of(new Message(npe.toString(), npe))); }
/** * Throws a ConfigurationException with a formatted {@link Message} if this condition is {@code * false}. */ static void checkConfiguration(boolean condition, String format, Object... args) { if (condition) { return; } throw new ConfigurationException(ImmutableSet.of(new Message(Errors.format(format, args)))); }
/** * When serialized, we eagerly convert sources to strings. This hurts our formatting, but it * guarantees that the receiving end will be able to read the message. */ private Object writeReplace() throws ObjectStreamException { Object[] sourcesAsStrings = sources.toArray(); for (int i = 0; i < sourcesAsStrings.length; i++) { sourcesAsStrings[i] = Errors.convert(sourcesAsStrings[i]).toString(); } return new Message(ImmutableList.copyOf(sourcesAsStrings), message, cause); }
/** * Creates a new Message with the given cause and a binding source stack. * * @param cause The exception that caused the error * @param sources The binding sources for the source stack * @param messageFormat Format string * @param arguments format string arguments */ public static Message create( Throwable cause, List<Object> sources, String messageFormat, Object... arguments) { String message = format(messageFormat, arguments); return new Message(sources, message, cause); }
/** Prepends the list of sources to the given {@link Message} */ static Message mergeSources(List<Object> sources, Message message) { List<Object> messageSources = message.getSources(); // It is possible that the end of getSources() and the beginning of message.getSources() are // equivalent, in this case we should drop the repeated source when joining the lists. The // most likely scenario where this would happen is when a scoped binding throws an exception, // due to the fact that InternalFactoryToProviderAdapter applies the binding source when // merging errors. if (!sources.isEmpty() && !messageSources.isEmpty() && Objects.equal(messageSources.get(0), sources.get(sources.size() - 1))) { messageSources = messageSources.subList(1, messageSources.size()); } return new Message( ImmutableList.builder().addAll(sources).addAll(messageSources).build(), message.getMessage(), message.getCause()); }
@Override public void addError(String message, Object... arguments) { elements.add(new Message(getElementSource(), Errors.format(message, arguments))); }
return new Message(Thread.currentThread(), sb.toString());
@Test public void testPropertySetting() throws Exception { IMocksControl control = createControl(); TypeEncounter<SomeInjectableBean> encounter = control.createMock(TypeEncounter.class); Provider<Injector> injectorProvider = control.createMock(Provider.class); Injector injector = control.createMock(Injector.class); expect(encounter.getProvider(Injector.class)).andReturn(injectorProvider); expect(injectorProvider.get()).andReturn(injector).anyTimes(); Capture<MembersInjector<SomeInjectableBean>> capture = new Capture<MembersInjector<SomeInjectableBean>>(); encounter.register(and(anyObject(MembersInjector.class), capture(capture))); SecurityManager securityManager = control.createMock(SecurityManager.class); String property = "myPropertyValue"; expect(injector.getInstance(Key.get(SecurityManager.class))).andReturn(securityManager); expect(injector.getInstance(Key.get(String.class, Names.named("shiro.myProperty")))).andReturn(property); expect(injector.getInstance(Key.get(String.class, Names.named("shiro.unavailableProperty")))) .andThrow(new ConfigurationException(Collections.singleton(new Message("Not Available!")))); expect((Map)injector.getInstance(BeanTypeListener.MAP_KEY)).andReturn(Collections.EMPTY_MAP).anyTimes(); control.replay(); BeanTypeListener underTest = new BeanTypeListener(); underTest.hear(TypeLiteral.get(SomeInjectableBean.class), encounter); SomeInjectableBean bean = new SomeInjectableBean(); capture.getValue().injectMembers(bean); assertSame(securityManager, bean.securityManager); assertSame(property, bean.myProperty); assertNull(bean.unavailableProperty); control.verify(); }
/** * Throws a ConfigurationException with a formatted {@link Message} if this condition is {@code * false}. */ static void checkConfiguration(boolean condition, String format, Object... args) { if (condition) { return; } throw new ConfigurationException(ImmutableSet.of(new Message(Errors.format(format, args)))); }
public void addError(Throwable e, String format, Object... params) { Message message = new Message(emptyList(), "Error: " + format(format, params), e); errors.add(message); monitor.onError(message); }
@Test(expectedExceptions = AuthorizationException.class) public void testPropagateCreationExceptionAuthorizationException() throws Throwable { Exception e = new AuthorizationException(); propagateIfPossible( new CreationException(ImmutableSet.of(new Message(ImmutableList.of(), "Error in custom provider", e))), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
public void testGetCauseCreation() { AuthorizationException aex = createMock(AuthorizationException.class); Message message = new Message(ImmutableList.of(), "test", aex); CreationException pex = new CreationException(ImmutableSet.of(message)); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), aex); }
public void testGetFirstThrowableOfTypeFailCreation() { TimeoutException aex = createMock(TimeoutException.class); Message message = new Message(ImmutableList.of(), "test", aex); CreationException pex = new CreationException(ImmutableSet.of(message)); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null); }
public void testGetFirstThrowableOfTypeFail() { TimeoutException aex = createMock(TimeoutException.class); Message message = new Message(ImmutableList.of(), "test", aex); ProvisionException pex = new ProvisionException(ImmutableSet.of(message)); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null); }
public void testGetFirstThrowableOfTypeWhenCauseIsNullCreation() { Message message = new Message(ImmutableList.of(), "test", null); CreationException pex = new CreationException(ImmutableSet.of(message)); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null); }
public void testGetFirstThrowableOfTypeWhenCauseIsNull() { Message message = new Message(ImmutableList.of(), "test", null); ProvisionException pex = new ProvisionException(ImmutableSet.of(message)); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null); }