io.airlift.testing.Assertions.assertContainsAllOf()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(82)

本文整理了Java中io.airlift.testing.Assertions.assertContainsAllOf()方法的一些代码示例,展示了Assertions.assertContainsAllOf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assertions.assertContainsAllOf()方法的具体详情如下:
包路径:io.airlift.testing.Assertions
类名称:Assertions
方法名:assertContainsAllOf

Assertions.assertContainsAllOf介绍

暂无

代码示例

代码示例来源:origin: airlift/airlift

@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");
  }
}

代码示例来源:origin: com.teradata.airlift/configuration

@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") ;
  }
}

代码示例来源:origin: io.airlift/configuration

@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");
  }
}

代码示例来源:origin: com.teradata.airlift/configuration

@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);
  }
}

代码示例来源:origin: airlift/airlift

@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");
  }
}

代码示例来源:origin: io.airlift/configuration

@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");
  }
}

代码示例来源:origin: io.airlift/configuration

@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");
  }
}

代码示例来源:origin: airlift/airlift

@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);
  }
}

代码示例来源:origin: airlift/airlift

@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);
  }
}

代码示例来源:origin: io.airlift/configuration

@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);
  }
}

代码示例来源:origin: io.airlift/configuration

@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);
  }
}

代码示例来源:origin: io.airlift/configuration

@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);
  }
}

代码示例来源:origin: com.teradata.airlift/configuration

@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);
  }
}

代码示例来源:origin: airlift/airlift

@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);
  }
}

代码示例来源:origin: airlift/airlift

@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]");
  }
}

代码示例来源:origin: io.airlift/configuration

@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]");
  }
}

代码示例来源:origin: airlift/airlift

@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");
  }
}

代码示例来源:origin: io.airlift/configuration

@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");
  }
}

代码示例来源:origin: com.teradata.airlift/configuration

@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") ;
  }
}

代码示例来源:origin: airlift/airlift

@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");
  }
}

相关文章