当前位置: 首页>>代码示例>>Java>>正文


Java Message类代码示例

本文整理汇总了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;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:17,代码来源:JsonConverter.java

示例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;
}
 
开发者ID:ruediste,项目名称:salta,代码行数:23,代码来源:Errors.java

示例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;
    }
}
 
开发者ID:ruediste,项目名称:salta,代码行数:17,代码来源:BinderTest.java

示例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());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:19,代码来源:FactoryModuleBuilderTest.java

示例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)));
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:37,代码来源:ImplicitBindingTest.java

示例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());
}
 
开发者ID:google,项目名称:guice,代码行数:19,代码来源:Messages.java

示例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;
}
 
开发者ID:google,项目名称:guice,代码行数:22,代码来源:Messages.java

示例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());
    }
  }
}
 
开发者ID:google,项目名称:guice,代码行数:21,代码来源:ProvisionExceptionTest.java

示例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());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:20,代码来源:ImplicitBindingTest.java

示例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)));
}
 
开发者ID:google,项目名称:guice,代码行数:39,代码来源:ImplicitBindingTest.java

示例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");
}
 
开发者ID:google,项目名称:guice,代码行数:19,代码来源:BinderTest.java

示例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
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:27,代码来源:FactoryProvider2.java

示例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());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:18,代码来源:FactoryModuleBuilderTest.java

示例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");
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:26,代码来源:TypeListenerTest.java

示例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");
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:17,代码来源:BinderTest.java


注:本文中的com.google.inject.spi.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。