本文整理汇总了Java中com.google.inject.spi.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于com.google.inject.spi包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessage
import com.google.inject.spi.Message; //导入依赖的package包/类
public static List<Message> getMessage( String response )
{
ObjectMapper mapper = new ObjectMapper();
List<Message> messages = null;
try
{
messages = mapper.readValue( response, new TypeReference<List<Message>>()
{
} );
}
catch ( IOException e )
{
e.printStackTrace();
}
return messages;
}
示例2: getOnlyCause
import com.google.inject.spi.Message; //导入依赖的package包/类
/**
* Returns the cause throwable if there is exactly one cause in
* {@code messages}. If there are zero or multiple messages with causes,
* null is returned.
*/
public static Throwable getOnlyCause(Collection<Message> messages) {
Throwable onlyCause = null;
for (Message message : messages) {
Throwable messageCause = message.getCause();
if (messageCause == null) {
continue;
}
if (onlyCause != null) {
return null;
}
onlyCause = messageCause;
}
return onlyCause;
}
示例3: testUserReportedError
import com.google.inject.spi.Message; //导入依赖的package包/类
@Test
public void testUserReportedError() {
final Message message = new Message(getClass(), "Whoops!");
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
addError(message);
}
});
fail();
} catch (SaltaException expected) {
if (!expected.getMessage().contains("Whoops"))
throw expected;
}
}
示例4: testGenericErrorMessageMakesSense
import com.google.inject.spi.Message; //导入依赖的package包/类
public void testGenericErrorMessageMakesSense() {
try {
Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().build(Key.get(Foo.Factory.class)));
}
});
fail();
} catch (CreationException ce) {
// Assert not only that it's the correct message, but also that it's the *only* message.
Collection<Message> messages = ce.getErrorMessages();
assertEquals(
Foo.Factory.class.getName() + " cannot be used as a key; It is not fully specified.",
Iterables.getOnlyElement(messages).getMessage());
}
}
示例5: testRecursiveJitBindingsCleanupCorrectly
import com.google.inject.spi.Message; //导入依赖的package包/类
/**
* Ensure that when we cleanup failed JIT bindings, we don't break.
* The test here requires a sequence of JIT bindings:
* A-> B
* B -> C, A
* C -> A, D
* D not JITable
* The problem was that C cleaned up A's binding and then handed control back to B,
* which tried to continue processing A.. but A was removed from the jitBindings Map,
* so it attempts to create a new JIT binding for A, but we haven't yet finished
* constructing the first JIT binding for A, so we get a recursive
* computation exception from ComputingConcurrentHashMap.
*
* We also throw in a valid JIT binding, E, to guarantee that if
* something fails in this flow, it can be recreated later if it's
* not from a failed sequence.
*/
public void testRecursiveJitBindingsCleanupCorrectly() throws Exception {
Injector injector = Guice.createInjector();
try {
injector.getInstance(A.class);
fail("Expected failure");
} catch(ConfigurationException expected) {
Message msg = Iterables.getOnlyElement(expected.getErrorMessages());
Asserts.assertContains(msg.getMessage(),
"Could not find a suitable constructor in " + D.class.getName());
}
// Assert that we've removed all the bindings.
assertNull(injector.getExistingBinding(Key.get(A.class)));
assertNull(injector.getExistingBinding(Key.get(B.class)));
assertNull(injector.getExistingBinding(Key.get(C.class)));
assertNull(injector.getExistingBinding(Key.get(D.class)));
// Confirm that we didn't prevent 'E' from working.
assertNotNull(injector.getBinding(Key.get(E.class)));
}
示例6: mergeSources
import com.google.inject.spi.Message; //导入依赖的package包/类
/** 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());
}
示例7: getOnlyCause
import com.google.inject.spi.Message; //导入依赖的package包/类
/**
* Returns the cause throwable if there is exactly one cause in {@code messages}. If there are
* zero or multiple messages with causes, null is returned.
*/
public static Throwable getOnlyCause(Collection<Message> messages) {
Throwable onlyCause = null;
for (Message message : messages) {
Throwable messageCause = message.getCause();
if (messageCause == null) {
continue;
}
if (onlyCause != null && !ThrowableEquivalence.INSTANCE.equivalent(onlyCause, messageCause)) {
return null;
}
onlyCause = messageCause;
}
return onlyCause;
}
示例8: testDuplicateCausesCollapsed
import com.google.inject.spi.Message; //导入依赖的package包/类
public void testDuplicateCausesCollapsed() {
final RuntimeException sharedException = new RuntimeException("fail");
try {
Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
addError(sharedException);
addError(sharedException);
}
});
fail();
} catch (CreationException ce) {
assertEquals(sharedException, ce.getCause());
assertEquals(2, ce.getErrorMessages().size());
for (Message message : ce.getErrorMessages()) {
assertEquals(sharedException, message.getCause());
}
}
}
示例9: assertFailure
import com.google.inject.spi.Message; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void assertFailure(Injector injector, Class clazz) {
try {
injector.getBinding(clazz);
fail("Shouldn't have been able to get binding of: " + clazz);
} catch (ConfigurationException expected) {
Message msg = Iterables.getOnlyElement(expected.getErrorMessages());
Asserts.assertContains(
msg.getMessage(),
"No implementation for " + InvalidInterface.class.getName() + " was bound.");
List<Object> sources = msg.getSources();
// Assert that the first item in the sources if the key for the class we're looking up,
// ensuring that each lookup is "new".
assertEquals(Key.get(clazz).toString(), sources.get(0).toString());
// Assert that the last item in each lookup contains the InvalidInterface class
Asserts.assertContains(
sources.get(sources.size() - 1).toString(), Key.get(InvalidInterface.class).toString());
}
}
示例10: testRecursiveJitBindingsCleanupCorrectly
import com.google.inject.spi.Message; //导入依赖的package包/类
/**
* Ensure that when we cleanup failed JIT bindings, we don't break. The test here requires a
* sequence of JIT bindings:
*
* <ol>
* <li> A-> B
* <li> B -> C, A
* <li> C -> A, D
* <li> D not JITable
* </ol>
*
* <p>The problem was that C cleaned up A's binding and then handed control back to B, which tried
* to continue processing A.. but A was removed from the jitBindings Map, so it attempts to create
* a new JIT binding for A, but we haven't yet finished constructing the first JIT binding for A,
* so we get a recursive computation exception from ComputingConcurrentHashMap.
*
* <p>We also throw in a valid JIT binding, E, to guarantee that if something fails in this flow,
* it can be recreated later if it's not from a failed sequence.
*/
public void testRecursiveJitBindingsCleanupCorrectly() throws Exception {
Injector injector = Guice.createInjector();
try {
injector.getInstance(A.class);
fail("Expected failure");
} catch (ConfigurationException expected) {
Message msg = Iterables.getOnlyElement(expected.getErrorMessages());
Asserts.assertContains(
msg.getMessage(), "Could not find a suitable constructor in " + D.class.getName());
}
// Assert that we've removed all the bindings.
assertNull(injector.getExistingBinding(Key.get(A.class)));
assertNull(injector.getExistingBinding(Key.get(B.class)));
assertNull(injector.getExistingBinding(Key.get(C.class)));
assertNull(injector.getExistingBinding(Key.get(D.class)));
// Confirm that we didn't prevent 'E' from working.
assertNotNull(injector.getBinding(Key.get(E.class)));
}
示例11: testUserReportedErrorsAreAlsoLogged
import com.google.inject.spi.Message; //导入依赖的package包/类
public void testUserReportedErrorsAreAlsoLogged() {
try {
Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
addError(new Message("Whoops!", new IllegalArgumentException()));
}
});
fail();
} catch (CreationException expected) {
}
LogRecord logRecord = Iterables.getOnlyElement(this.logRecords);
assertContains(
logRecord.getMessage(),
"An exception was caught and reported. Message: java.lang.IllegalArgumentException");
}
示例12: initialize
import com.google.inject.spi.Message; //导入依赖的package包/类
/**
* At injector-creation time, we initialize the invocation handler. At this time we make sure
* all factory methods will be able to build the target types.
*/
@Inject @Toolable
void initialize(Injector injector) {
if (this.injector != null) {
throw new ConfigurationException(ImmutableList.of(new Message(FactoryProvider2.class,
"Factories.create() factories may only be used in one Injector!")));
}
this.injector = injector;
for (Map.Entry<Method, AssistData> entry : assistDataByMethod.entrySet()) {
Method method = entry.getKey();
AssistData data = entry.getValue();
Object[] args;
if(!data.optimized) {
args = new Object[method.getParameterTypes().length];
Arrays.fill(args, "dummy object for validating Factories");
} else {
args = null; // won't be used -- instead will bind to data.providers.
}
getBindingFromNewInjector(method, args, data); // throws if the binding isn't properly configured
}
}
示例13: testGenericErrorMessageMakesSense
import com.google.inject.spi.Message; //导入依赖的package包/类
public void testGenericErrorMessageMakesSense() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().build(Key.get(Foo.Factory.class)));
}
});
fail();
} catch(CreationException ce ) {
// Assert not only that it's the correct message, but also that it's the *only* message.
Collection<Message> messages = ce.getErrorMessages();
assertEquals(
Foo.Factory.class.getName() + " cannot be used as a key; It is not fully specified.",
Iterables.getOnlyElement(messages).getMessage());
}
}
示例14: testAddErrors
import com.google.inject.spi.Message; //导入依赖的package包/类
public void testAddErrors() {
try {
Guice.createInjector(new AbstractModule() {
@Override protected void configure() {
requestInjection(new Object());
bindListener(Matchers.any(), new TypeListener() {
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
encounter.addError("There was an error on %s", type);
encounter.addError(new IllegalArgumentException("whoops!"));
encounter.addError(new Message("And another problem"));
encounter.addError(new IllegalStateException());
}
});
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(),
"1) There was an error on java.lang.Object",
"2) An exception was caught and reported. Message: whoops!",
"3) And another problem",
"4) An exception was caught and reported. Message: null",
"4 errors");
}
}
示例15: testUserReportedErrorsAreAlsoLogged
import com.google.inject.spi.Message; //导入依赖的package包/类
public void testUserReportedErrorsAreAlsoLogged() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
addError(new Message("Whoops!", new IllegalArgumentException()));
}
});
fail();
} catch (CreationException expected) {
}
LogRecord logRecord = Iterables.getOnlyElement(this.logRecords);
assertContains(logRecord.getMessage(),
"An exception was caught and reported. Message: java.lang.IllegalArgumentException");
}