Java 类com.google.inject.Asserts 实例源码

项目:guice    文件:ManyConstructorsTest.java   
public void testTooManyMatchingConstructors() {
  try {
    Guice.createInjector(
        new AbstractModule() {
          @Override
          protected void configure() {
            install(
                new FactoryModuleBuilder()
                    .implement(Foo.class, TooManyMatches.class)
                    .build(SimpleFactory2.class));
          }
        });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(
        expected.getMessage(),
        "1) "
            + TooManyMatches.class.getName()
            + " has more than one constructor annotated with @AssistedInject that "
            + "matches the parameters in method "
            + SimpleFactory2.class.getName());
  }
}
项目:guice    文件:ManyConstructorsTest.java   
public void testNoMatchingConstructorsBecauseTooManyParams() {
  try {
    Guice.createInjector(
        new AbstractModule() {
          @Override
          protected void configure() {
            install(new FactoryModuleBuilder().build(ComplexFactory.class));
          }
        });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(
        expected.getMessage(),
        "1) "
            + Foo.class.getName()
            + " has @AssistedInject constructors, but none of them match the parameters in method "
            + ComplexFactory.class.getName());
  }
}
项目:guice    文件:ManyConstructorsTest.java   
public void testNoMatchingConstrucotsBecauseTooLittleParams() {
  try {
    Guice.createInjector(
        new AbstractModule() {
          @Override
          protected void configure() {
            install(new FactoryModuleBuilder().build(NullFactory.class));
          }
        });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(
        expected.getMessage(),
        "1) "
            + Foo.class.getName()
            + " has @AssistedInject constructors, but none of them match the parameters in method "
            + NullFactory.class.getName());
  }
}
项目:guice    文件:ToolStageInjectorTest.java   
public void testToolStageWarnsOfMissingObjectGraph() {
  final Bar bar = new Bar();
  try {
    Guice.createInjector(
        Stage.TOOL,
        new AbstractModule() {
          @Override
          protected void configure() {
            requestStaticInjection(Bar.class);
            requestInjection(bar);
          }
        });
    fail("expected exception");
  } catch (CreationException expected) {
    Asserts.assertContains(
        expected.toString(),
        "No implementation for java.util.Collection was bound.",
        "No implementation for java.util.Map was bound.",
        "No implementation for java.util.List was bound.",
        "No implementation for java.util.Set was bound.");
  }
}
项目:guice-old    文件:ManyConstructorsTest.java   
public void testTooManyMatchingConstructors() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        install(new FactoryModuleBuilder()
          .implement(Foo.class, TooManyMatches.class)
          .build(SimpleFactory2.class));
      }
    });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(expected.getMessage(), "1) " + TooManyMatches.class.getName()
        + " has more than one constructor annotated with @AssistedInject that "
        + "matches the parameters in method " + SimpleFactory2.class.getName());
  }
}
项目:guice-old    文件:ToolStageInjectorTest.java   
public void testToolStageWarnsOfMissingObjectGraph() {
  final Bar bar = new Bar();
  try {
    Guice.createInjector(Stage.TOOL, new AbstractModule() {
      @Override
      protected void configure() {
        requestStaticInjection(Bar.class);
        requestInjection(bar);
      }
    });
    fail("expected exception");
  } catch(CreationException expected) {
    Asserts.assertContains(expected.toString(), "No implementation for java.util.Collection was bound.",
        "No implementation for java.util.Map was bound.",
        "No implementation for java.util.List was bound.",
        "No implementation for java.util.Set was bound.");
  }
}
项目:google-guice    文件:ManyConstructorsTest.java   
public void testTooManyMatchingConstructors() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        install(new FactoryModuleBuilder()
          .implement(Foo.class, TooManyMatches.class)
          .build(SimpleFactory2.class));
      }
    });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(expected.getMessage(), "1) " + TooManyMatches.class.getName()
        + " has more than one constructor annotated with @AssistedInject that "
        + "matches the parameters in method " + SimpleFactory2.class.getName());
  }
}
项目:google-guice    文件:ToolStageInjectorTest.java   
public void testToolStageWarnsOfMissingObjectGraph() {
  final Bar bar = new Bar();
  try {
    Guice.createInjector(Stage.TOOL, new AbstractModule() {
      @Override
      protected void configure() {
        requestStaticInjection(Bar.class);
        requestInjection(bar);
      }
    });
    fail("expected exception");
  } catch(CreationException expected) {
    Asserts.assertContains(expected.toString(), "No implementation for java.util.Collection was bound.",
        "No implementation for java.util.Map was bound.",
        "No implementation for java.util.List was bound.",
        "No implementation for java.util.Set was bound.");
  }
}
项目:guice    文件:CheckedProviderTest.java   
public void testResultExceptionSerializes() throws Exception {
  Result result = Result.forException(new Exception("boo"));
  result = Asserts.reserialize(result);
  try {
    result.getOrThrow();
    fail();
  } catch (Exception ex) {
    assertEquals("boo", ex.getMessage());
  }
}
项目:guice    文件:MapBinderTest.java   
public void testWeakKeySet_integration_mapbinder() {
  Key<Map<String, String>> mapKey = Key.get(new TypeLiteral<Map<String, String>>() {});

  Injector parentInjector =
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              bind(String.class).toInstance("hi");
            }
          });
  WeakKeySetUtils.assertNotBlacklisted(parentInjector, mapKey);

  Injector childInjector =
      parentInjector.createChildInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              MapBinder<String, String> binder =
                  MapBinder.newMapBinder(binder(), String.class, String.class);
              binder.addBinding("bar").toInstance("foo");
            }
          });
  WeakReference<Injector> weakRef = new WeakReference<>(childInjector);
  WeakKeySetUtils.assertBlacklisted(parentInjector, mapKey);

  // Clear the ref, GC, and ensure that we are no longer blacklisting.
  childInjector = null;

  Asserts.awaitClear(weakRef);
  WeakKeySetUtils.assertNotBlacklisted(parentInjector, mapKey);
}
项目:guice    文件:OptionalBinderTest.java   
public void testWeakKeySet_integration() {
  Injector parentInjector =
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              bind(String.class).toInstance("hi");
            }
          });
  WeakKeySetUtils.assertNotBlacklisted(parentInjector, Key.get(Integer.class));

  Injector childInjector =
      parentInjector.createChildInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              OptionalBinder.newOptionalBinder(binder(), Integer.class)
                  .setDefault()
                  .toInstance(4);
            }
          });
  WeakReference<Injector> weakRef = new WeakReference<>(childInjector);
  WeakKeySetUtils.assertBlacklisted(parentInjector, Key.get(Integer.class));

  // Clear the ref, GC, and ensure that we are no longer blacklisting.
  childInjector = null;

  Asserts.awaitClear(weakRef);
  WeakKeySetUtils.assertNotBlacklisted(parentInjector, Key.get(Integer.class));
}
项目:guice-old    文件:ManyConstructorsTest.java   
public void testNoMatchingConstructorsBecauseTooManyParams() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        install(new FactoryModuleBuilder().build(ComplexFactory.class));
      }
    });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(expected.getMessage(), "1) " + Foo.class.getName()
        + " has @AssistedInject constructors, but none of them match the parameters in method "
        + ComplexFactory.class.getName());
  }
}
项目:guice-old    文件:ManyConstructorsTest.java   
public void testNoMatchingConstrucotsBecauseTooLittleParams() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        install(new FactoryModuleBuilder().build(NullFactory.class));
      }
    });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(expected.getMessage(), "1) " + Foo.class.getName()
        + " has @AssistedInject constructors, but none of them match the parameters in method "
        + NullFactory.class.getName());
  }
}
项目:guice-old    文件:CheckedProviderTest.java   
public void testResultExceptionSerializes() throws Exception {
  Result result = Result.forException(new Exception("boo"));
  result = Asserts.reserialize(result);
  try {
    result.getOrThrow();
    fail();
  } catch(Exception ex) {
    assertEquals("boo", ex.getMessage());
  }
}
项目:google-guice    文件:ManyConstructorsTest.java   
public void testNoMatchingConstructorsBecauseTooManyParams() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        install(new FactoryModuleBuilder().build(ComplexFactory.class));
      }
    });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(expected.getMessage(), "1) " + Foo.class.getName()
        + " has @AssistedInject constructors, but none of them match the parameters in method "
        + ComplexFactory.class.getName());
  }
}
项目:google-guice    文件:ManyConstructorsTest.java   
public void testNoMatchingConstrucotsBecauseTooLittleParams() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        install(new FactoryModuleBuilder().build(NullFactory.class));
      }
    });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(expected.getMessage(), "1) " + Foo.class.getName()
        + " has @AssistedInject constructors, but none of them match the parameters in method "
        + NullFactory.class.getName());
  }
}
项目:google-guice    文件:CheckedProviderTest.java   
public void testResultExceptionSerializes() throws Exception {
  Result result = Result.forException(new Exception("boo"));
  result = Asserts.reserialize(result);
  try {
    result.getOrThrow();
    fail();
  } catch(Exception ex) {
    assertEquals("boo", ex.getMessage());
  }
}
项目:guice    文件:CheckedProviderTest.java   
public void testResultSerializes() throws Exception {
  Result result = Result.forValue("foo");
  result = Asserts.reserialize(result);
  assertEquals("foo", result.getOrThrow());
}
项目:guice-old    文件:CheckedProviderTest.java   
public void testResultSerializes() throws Exception {
  Result result = Result.forValue("foo");
  result = Asserts.reserialize(result);
  assertEquals("foo", result.getOrThrow());
}
项目:google-guice    文件:CheckedProviderTest.java   
public void testResultSerializes() throws Exception {
  Result result = Result.forValue("foo");
  result = Asserts.reserialize(result);
  assertEquals("foo", result.getOrThrow());
}