@Test(groups = "requiresTempFile")
  public void testAliasedBindingBindsCorrectly() {
    final String prefix = "test";
    Map<String, String> properties =
        createDefaultConfigurationProperties(prefix, temporaryFile.getAbsolutePath());

    Injector injector =
        createInjector(
            properties,
            new H2EmbeddedDataSourceModule(prefix, MainBinding.class, AliasBinding.class),
            new Module() {
              @Override
              public void configure(Binder binder) {
                binder.bind(TwoObjectsHolder.class);
              }
            });

    ObjectHolder objectHolder = injector.getInstance(ObjectHolder.class);
    TwoObjectsHolder twoObjectsHolder = injector.getInstance(TwoObjectsHolder.class);

    // Held data source objects should all be of the correct type
    Assertions.assertInstanceOf(twoObjectsHolder.mainDataSource, H2EmbeddedDataSource.class);
    Assertions.assertInstanceOf(twoObjectsHolder.aliasedDataSource, H2EmbeddedDataSource.class);

    // And should all be references to the same object
    assertSame(objectHolder.dataSource, twoObjectsHolder.mainDataSource);
    assertSame(objectHolder.dataSource, twoObjectsHolder.aliasedDataSource);
  }
  @Test
  public void checkElementDB() {
    ElementDatabase edb = ElementDatabase.getInstance();

    Element s = edb.getElement("S");
    Assertion.isNotNull(s, "Could not find sulphur by name");

    Element s16 = edb.getElement(16);
    Assertion.isNotNull(s16, "Could not find sulphur by element number");

    assertSame(s, s16);

    ElementTest et = new ElementTest();
    et.sulphurTests(s);

    Element o = edb.getElement("o");
    Assertion.isNotNull(o, "Could not find oxygen by name");

    Element o8 = edb.getElement(8);
    Assertion.isNotNull(o8, "Could not find oxygen by element number");

    assertSame(o, o8);

    for (int i = 1; i <= 83; i++) {
      Element e = edb.getElement(i);
      Assertion.isNotNull(e, "Could not find element no. " + i);
    }

    Element mg = edb.getElement("Mg");
    Assertion.isNotNull(mg, "Could not find manganese by name");

    et.manganeseTests(mg);
  }
Esempio n. 3
0
 @Test
 public void testGetId() throws Exception {
   assertNotSame(test1.getId(), test2.getId());
   assertSame(test1.getId(), test1.getId());
   assertSame(test2.getId(), test2.getId());
   System.out.println(test1.getId());
   System.out.println(test2.getId());
 }
Esempio n. 4
0
 public void testMinBy() {
   Comparator<People> cmp = Comparator.comparing(People::getFirstName);
   // lesser
   assertSame(minBy(cmp).apply(people[0], people[1]), people[0]);
   // euqal
   cmp = Comparator.comparing(People::getLastName);
   assertSame(minBy(cmp).apply(people[0], people[1]), people[0]);
   // greater
   cmp = Comparator.comparingInt(People::getAge);
   assertSame(minBy(cmp).apply(people[0], people[1]), people[1]);
 }
Esempio n. 5
0
 public void test_iteration_childWithOneChild_FlexiBean() {
   FlexiBean bean1 = new FlexiBean();
   FlexiBean bean2 = new FlexiBean();
   bean1.set("a", bean2);
   Iterator<Bean> it = JodaBeanUtils.beanIterator(bean1);
   assertEquals(it.hasNext(), true);
   assertSame(it.next(), bean1);
   assertEquals(it.hasNext(), true);
   assertSame(it.next(), bean2);
   assertEquals(it.hasNext(), false);
 }
  @Test
  public void testUpdateMultiDomainServerState() throws Exception {
    final MultiDomainServerState state1 = new MultiDomainServerState();
    state1.update(dn1, csn3);
    state1.update(dn2, csn2);
    final MultiDomainServerState state2 = new MultiDomainServerState();
    state2.update(state1);

    assertSame(csn3, state2.getCSN(dn1, csn3.getServerId()));
    assertSame(csn2, state2.getCSN(dn2, csn2.getServerId()));
    assertTrue(state1.equalsTo(state2));
  }
 public void testCloneShouldReturnClonedObjectWithClonedSuccessAndFailure()
     throws CloneNotSupportedException {
   // GIVEN
   expectTc(success, successCloned);
   expectTc(failure, failureCloned);
   mockControl.replay();
   // WHEN
   final AttributeTestCommand returned = underTest.clone();
   // THEN
   Assert.assertSame(returned.getSuccess().get(0).getData(), successCloned);
   Assert.assertSame(returned.getFailure().get(0).getData(), failureCloned);
 }
Esempio n. 8
0
  public void test_iteration_childWithListOfChildren() {
    ImmTreeNode node1a = ImmTreeNode.builder().name("1a").build();
    ImmTreeNode node1b = ImmTreeNode.builder().name("1b").build();
    ImmTreeNode node1 = ImmTreeNode.builder().name("1").child1(node1a).child2(node1b).build();
    ImmTreeNode node2a = ImmTreeNode.builder().name("2a").build();
    ImmTreeNode node2b = ImmTreeNode.builder().name("2b").build();
    ImmTreeNode node2 = ImmTreeNode.builder().name("2").child1(node2a).child2(node2b).build();
    ImmTreeNode node3 = ImmTreeNode.builder().name("3").build();
    ImmTreeNode root =
        ImmTreeNode.builder()
            .name("root")
            .child1(node3)
            .childList(ImmutableList.of(node1, node2))
            .build();

    Iterator<Bean> it = JodaBeanUtils.beanIterator(root);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), root);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), node3);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), node1);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), node1a);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), node1b);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), node2);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), node2a);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), node2b);
    assertEquals(it.hasNext(), false);
  }
Esempio n. 9
0
  public void test_iteration_childWithChildren() {
    ImmTreeNode node1 = ImmTreeNode.builder().name("1").build();
    ImmTreeNode node2 = ImmTreeNode.builder().name("2").build();
    ImmTreeNode root = ImmTreeNode.builder().name("root").child1(node1).child2(node2).build();

    Iterator<Bean> it = JodaBeanUtils.beanIterator(root);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), root);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), node1);
    assertEquals(it.hasNext(), true);
    assertSame(it.next(), node2);
    assertEquals(it.hasNext(), false);
  }
Esempio n. 10
0
 public void test_iteration_nullChild() {
   Address bean = new Address();
   Iterator<Bean> it = JodaBeanUtils.beanIterator(bean);
   assertEquals(it.hasNext(), true);
   assertSame(it.next(), bean);
   assertEquals(it.hasNext(), false);
 }
Esempio n. 11
0
 public void test_iteration_noChildren() {
   ImmEmpty bean = ImmEmpty.builder().build();
   Iterator<Bean> it = JodaBeanUtils.beanIterator(bean);
   assertEquals(it.hasNext(), true);
   assertSame(it.next(), bean);
   assertEquals(it.hasNext(), false);
 }
Esempio n. 12
0
 // -----------------------------------------------------------------------
 public void test_iteration_childWithNoChildren_FlexiBean() {
   FlexiBean bean1 = new FlexiBean();
   Iterator<Bean> it = JodaBeanUtils.beanIterator(bean1);
   assertEquals(it.hasNext(), true);
   assertSame(it.next(), bean1);
   assertEquals(it.hasNext(), false);
 }
Esempio n. 13
0
 @Test
 public void testGetTable() {
   GraphStore graphStore = GraphGenerator.generateTinyGraphStore();
   for (Node n : graphStore.getNodes()) {
     Assert.assertSame(n.getTable(), graphStore.getModel().getNodeTable());
   }
 }
 // -------------------------------------------------------------------------
 public void test_cloned() {
   BondFutureOptionSensitivity base =
       BondFutureOptionSensitivity.of(
           NAME, OPTION_EXPIRY, FUTURE_EXPIRY, STRIKE_PRICE, FUTURE_PRICE, GBP, SENSITIVITY);
   BondFutureOptionSensitivity test = base.cloned();
   assertSame(test, base);
 }
  @Test
  public void testWholeIndelReadInIsolation() {
    final int firstLocus = 44367789;

    // create a test version of the Reads object
    ReadProperties readAttributes = createTestReadProperties();

    SAMRecord indelOnlyRead =
        ArtificialSAMUtils.createArtificialRead(header, "indelOnly", 0, firstLocus, 76);
    indelOnlyRead.setReadBases(Utils.dupBytes((byte) 'A', 76));
    indelOnlyRead.setBaseQualities(Utils.dupBytes((byte) '@', 76));
    indelOnlyRead.setCigarString("76I");

    List<SAMRecord> reads = Arrays.asList(indelOnlyRead);

    // create the iterator by state with the fake reads and fake records
    li = makeLTBS(reads, readAttributes);

    // Traditionally, reads that end with indels bleed into the pileup at the following locus.
    // Verify that the next pileup contains this read
    // and considers it to be an indel-containing read.
    Assert.assertTrue(
        li.hasNext(),
        "Should have found a whole-indel read in the normal base pileup without extended events enabled");
    AlignmentContext alignmentContext = li.next();
    Assert.assertEquals(
        alignmentContext.getLocation().getStart(),
        firstLocus,
        "Base pileup is at incorrect location.");
    ReadBackedPileup basePileup = alignmentContext.getBasePileup();
    Assert.assertEquals(basePileup.getReads().size(), 1, "Pileup is of incorrect size");
    Assert.assertSame(basePileup.getReads().get(0), indelOnlyRead, "Read in pileup is incorrect");
  }
  @Test
  /** for {@link SingleThumbnailAdapter#get()} */
  public void should_return_proper_operation_result() {

    // Given
    mockStatic(JerseyRequest.class);
    when(buildRequest(
            eq(sessionStorageMock),
            eq(InputStream.class),
            eq(new String[] {"/thumbnails", "/public/Samples/Reports/07g.RevenueDetailReport"}),
            any(DefaultErrorHandler.class)))
        .thenReturn(jerseyRequestMock);
    when(jerseyRequestMock.setAccept("image/jpeg")).thenReturn(jerseyRequestMock);
    when(jerseyRequestMock.get()).thenReturn(operationResultMock);
    SingleThumbnailAdapter thumbnailAdapter = new SingleThumbnailAdapter(sessionStorageMock);
    thumbnailAdapter.report("/public/Samples/Reports/07g.RevenueDetailReport");

    // When
    OperationResult<InputStream> retrieved = thumbnailAdapter.get();

    // Then
    assertNotNull(retrieved);
    assertSame(retrieved, operationResultMock);
    verify(jerseyRequestMock).setAccept(eq("image/jpeg"));
    verify(jerseyRequestMock).get();
    verifyStatic(times(1));
    buildRequest(
        eq(sessionStorageMock),
        eq(InputStream.class),
        eq(new String[] {"/thumbnails", "/public/Samples/Reports/07g.RevenueDetailReport"}),
        any(DefaultErrorHandler.class));
  }
Esempio n. 17
0
  @Test(dataProvider = "builders")
  public void testUsingInWithProvider(LifecycleInjectorBuilder lifecycleInjectorBuilder) {
    Injector injector =
        lifecycleInjectorBuilder
            .withModules(
                new Module() {
                  @Override
                  public void configure(Binder binder) {
                    binder.bind(LazySingletonObject.class).in(LazySingletonScope.get());
                  }
                })
            .createInjector();

    Assert.assertEquals(LazySingletonObject.constructorCount.get(), 0);
    Assert.assertEquals(LazySingletonObject.postConstructCount.get(), 0);

    InjectedProvider injectedProvider = injector.getInstance(InjectedProvider.class);
    Assert.assertEquals(LazySingletonObject.constructorCount.get(), 0);
    Assert.assertEquals(LazySingletonObject.postConstructCount.get(), 0);

    LazySingletonObject instance = injectedProvider.provider.get();
    Assert.assertEquals(LazySingletonObject.constructorCount.get(), 1);
    Assert.assertEquals(LazySingletonObject.postConstructCount.get(), 1);

    LazySingletonObject instance2 = injectedProvider.provider.get();
    Assert.assertEquals(LazySingletonObject.constructorCount.get(), 1);
    Assert.assertEquals(LazySingletonObject.postConstructCount.get(), 1);

    Assert.assertSame(instance, instance2);
  }
Esempio n. 18
0
  @Test
  public void testBrokenOperatorCloseWhileProcessing() throws Exception {
    BrokenOperator brokenOperator =
        new BrokenOperator(
            driverContext.addOperatorContext(0, new PlanNodeId("test"), "source"), false);
    final Driver driver =
        new Driver(driverContext, brokenOperator, createSinkOperator(brokenOperator));

    assertSame(driver.getDriverContext(), driverContext);

    // block thread in operator processing
    Future<Boolean> driverProcessFor =
        executor.submit(
            new Callable<Boolean>() {
              @Override
              public Boolean call() throws Exception {
                return driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone();
              }
            });
    brokenOperator.waitForLocked();

    driver.close();
    assertTrue(driver.isFinished());

    try {
      driverProcessFor.get(1, TimeUnit.SECONDS);
      fail("Expected InterruptedException");
    } catch (ExecutionException e) {
      checkArgument(
          getRootCause(e) instanceof InterruptedException,
          "Expected root cause exception to be an instance of InterruptedException");
    }
  }
Esempio n. 19
0
  @Test
  public void testBrokenOperatorProcessWhileClosing() throws Exception {
    BrokenOperator brokenOperator =
        new BrokenOperator(
            driverContext.addOperatorContext(0, new PlanNodeId("test"), "source"), true);
    final Driver driver =
        new Driver(driverContext, brokenOperator, createSinkOperator(brokenOperator));

    assertSame(driver.getDriverContext(), driverContext);

    // block thread in operator close
    Future<Boolean> driverClose =
        executor.submit(
            new Callable<Boolean>() {
              @Override
              public Boolean call() throws Exception {
                driver.close();
                return true;
              }
            });
    brokenOperator.waitForLocked();

    assertTrue(driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone());
    assertTrue(driver.isFinished());

    brokenOperator.unlock();

    assertTrue(driverClose.get());
  }
  @Test
  public void testUnwrapToInterfaceTypesSucceeds() {
    Context context =
        new MessageInterpolatorContext(null, null, null, Collections.<String, Object>emptyMap());

    MessageInterpolator.Context asMessageInterpolatorContext =
        context.unwrap(MessageInterpolator.Context.class);
    assertSame(asMessageInterpolatorContext, context);

    HibernateMessageInterpolatorContext asHibernateMessageInterpolatorContext =
        context.unwrap(HibernateMessageInterpolatorContext.class);
    assertSame(asHibernateMessageInterpolatorContext, context);

    Object asObject = context.unwrap(Object.class);
    assertSame(asObject, context);
  }
Esempio n. 21
0
  @Test
  public void testAbruptFinish() {
    List<Type> types = ImmutableList.<Type>of(VARCHAR, BIGINT, BIGINT);
    ValuesOperator source =
        new ValuesOperator(
            driverContext.addOperatorContext(0, new PlanNodeId("test"), "values"),
            types,
            rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());

    PageConsumerOperator sink = createSinkOperator(source);
    Driver driver = new Driver(driverContext, source, sink);

    assertSame(driver.getDriverContext(), driverContext);

    assertFalse(driver.isFinished());
    driver.close();
    assertTrue(driver.isFinished());

    // finish is only called in normal operations
    assertFalse(source.isFinished());
    assertFalse(sink.isFinished());

    // close is always called (values operator doesn't have a closed state)
    assertTrue(sink.isClosed());
  }
Esempio n. 22
0
 // -----------------------------------------------------------------------
 private void serialize(DateTimeRule rule) throws Exception {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   ObjectOutputStream oos = new ObjectOutputStream(baos);
   oos.writeObject(rule);
   oos.close();
   ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
   assertSame(ois.readObject(), rule);
 }
Esempio n. 23
0
 @Test(groups = {"implementation"})
 public void factory_ofNanoOfDay_singletons() {
   for (int i = 0; i < 24; i++) {
     LocalTime test1 = LocalTime.ofNanoOfDay(i * 1000000000L * 60L * 60L);
     LocalTime test2 = LocalTime.of(i, 0);
     assertSame(test1, test2);
   }
 }
Esempio n. 24
0
 @Test(groups = {"implementation"})
 public void factory_time_4ints_singletons() {
   for (int i = 0; i < 24; i++) {
     LocalTime test1 = LocalTime.of(i, 0, 0, 0);
     LocalTime test2 = LocalTime.of(i, 0, 0, 0);
     assertSame(test1, test2);
   }
 }
  @Test
  public void testCacheListenerCopying() {
    RegisteredEventListeners registeredEventListeners =
        _ehcachePortalCache.ehcache.getCacheEventNotificationService();

    Set<CacheEventListener> cacheEventListeners = registeredEventListeners.getCacheEventListeners();

    Assert.assertEquals(1, cacheEventListeners.size());

    Iterator<CacheEventListener> iterator = cacheEventListeners.iterator();

    CacheEventListener cacheEventListener = iterator.next();

    Assert.assertTrue(cacheEventListener instanceof PortalCacheCacheEventListener);

    PortalCacheCacheEventListener<Serializable, Serializable> portalCacheCacheEventListener =
        (PortalCacheCacheEventListener<Serializable, Serializable>) cacheEventListener;

    Assert.assertSame(_defaultCacheListener, portalCacheCacheEventListener.getCacheListener());
    Assert.assertSame(_ehcachePortalCache, portalCacheCacheEventListener.getPortalCache());

    String newCacheName = "newCache";

    _cacheManager.addCache(newCacheName);

    Cache newCache = _cacheManager.getCache(newCacheName);

    _ehcachePortalCache.setEhcache(newCache);

    registeredEventListeners = newCache.getCacheEventNotificationService();

    Assert.assertEquals(1, cacheEventListeners.size());

    iterator = cacheEventListeners.iterator();

    cacheEventListener = iterator.next();

    Assert.assertTrue(cacheEventListener instanceof PortalCacheCacheEventListener);

    portalCacheCacheEventListener =
        (PortalCacheCacheEventListener<Serializable, Serializable>) cacheEventListener;

    Assert.assertSame(_defaultCacheListener, portalCacheCacheEventListener.getCacheListener());
    Assert.assertSame(_ehcachePortalCache, portalCacheCacheEventListener.getPortalCache());
  }
 @Test
 /** for {@link SingleThumbnailAdapter#SingleThumbnailAdapter(SessionStorage)} */
 public void should_pass_session_storage_to_parent_adapter() {
   // When
   SingleThumbnailAdapter thumbnailAdapter = new SingleThumbnailAdapter(sessionStorageMock);
   SessionStorage retrieved = thumbnailAdapter.getSessionStorage();
   // Then
   assertSame(retrieved, sessionStorageMock);
 }
 public void testArbitratyImageName() {
   GoogleComputeEngineImageToImage imageToImage = new GoogleComputeEngineImageToImage();
   Image image = imageBuilder.name("arbitratyname").build();
   org.jclouds.compute.domain.Image transformed = imageToImage.apply(image);
   assertEquals(transformed.getName(), image.getName());
   assertEquals(transformed.getId(), image.getName());
   assertEquals(transformed.getProviderId(), image.getId());
   assertSame(transformed.getOperatingSystem().getFamily(), OsFamily.LINUX);
 }
Esempio n. 28
0
 // -----------------------------------------------------------------------
 // serialize
 // -----------------------------------------------------------------------
 public void test_serialize() throws Exception {
   SystemUtcRules test = SystemUtcRules.INSTANCE; // use real rules, not our hacked copy
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   ObjectOutputStream oos = new ObjectOutputStream(baos);
   oos.writeObject(test);
   oos.close();
   ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
   assertSame(ois.readObject(), test);
 }
 public void testGetCommandViewShouldReturnCommandViewWithModelContainingSelf() {
   // GIVEN
   mockControl.replay();
   // WHEN
   final CommandView returned = underTest.getCommandView("ff");
   // THEN
   Assert.assertSame(returned.getModel().get("attribTest"), underTest);
   Assert.assertEquals(returned.getViewName(), "ffAttributeTest");
 }
 // -------------------------------------------------------------------------
 public void test_buildInto() {
   BondFutureOptionSensitivity base =
       BondFutureOptionSensitivity.of(
           NAME, OPTION_EXPIRY, FUTURE_EXPIRY, STRIKE_PRICE, FUTURE_PRICE, GBP, SENSITIVITY);
   MutablePointSensitivities combo = new MutablePointSensitivities();
   MutablePointSensitivities test = base.buildInto(combo);
   assertSame(test, combo);
   assertEquals(test.getSensitivities(), ImmutableList.of(base));
 }