/**
   * Tests {@link ExternalResource#clone()}.
   *
   * @throws CloneNotSupportedException if it fails.
   */
  @Test
  public void testClone() throws CloneNotSupportedException {
    String name = "name";
    String description = "description";
    String id = "id";
    ExternalResource resource =
        new ExternalResource(name, description, id, true, new LinkedList<MetadataValue>());
    String me = "me";
    resource.setReserved(
        new StashInfo(
            StashInfo.StashType.INTERNAL, me, new Lease(Calendar.getInstance(), "iso"), "key"));
    TreeStructureUtil.addValue(resource, "value", "descript", "some", "path");

    ExternalResource other = resource.clone();

    assertEquals(name, other.getName());
    assertEquals(id, other.getId());
    assertNotNull(other.getReserved());
    assertNotSame(resource.getReserved(), other.getReserved());
    assertEquals(resource.getReserved().getStashedBy(), other.getReserved().getStashedBy());
    assertNotSame(resource.getReserved().getLease(), other.getReserved().getLease());
    assertEquals(
        resource.getReserved().getLease().getSlaveIsoTime(),
        other.getReserved().getLease().getSlaveIsoTime());
    assertNotSame(
        TreeStructureUtil.getPath(resource, "some", "path"),
        TreeStructureUtil.getPath(other, "some", "path"));
    assertEquals(
        TreeStructureUtil.getPath(resource, "some", "path").getValue(),
        TreeStructureUtil.getPath(other, "some", "path").getValue());
    assertTrue(other.isEnabled());
  }
 @Test
 public void testOverrideCreate() {
   JDBCMockObjectFactory factory = new TestJDBCMockObjectFactory();
   assertNotSame(factory.getMockConnection().getClass(), MockConnection.class);
   assertNotSame(factory.getMockDataSource().getClass(), MockDataSource.class);
   assertNotSame(factory.getMockDriver().getClass(), MockDriver.class);
 }
Example #3
0
  @Test
  public void shouldNotBeEqualToNullOrOtherObjects() {
    final Token expected = new Token("access", "secret", "response");

    assertNotSame(expected, null);
    assertNotSame(expected, new Object());
  }
  @Test
  public void testGetIdentifier_newEqual() {

    String pairwise1 = service.getIdentifier(userInfoRegular, pairwiseClient1);
    Mockito.verify(pairwiseIdentifierRepository, Mockito.atLeast(1))
        .save(Matchers.any(PairwiseIdentifier.class));

    PairwiseIdentifier pairwiseId = new PairwiseIdentifier();
    pairwiseId.setUserSub(regularSub);
    pairwiseId.setIdentifier(pairwise1);
    pairwiseId.setSectorIdentifier(sectorHost12);

    Mockito.when(pairwiseIdentifierRepository.getBySectorIdentifier(regularSub, sectorHost12))
        .thenReturn(pairwiseId);

    String pairwise2 = service.getIdentifier(userInfoRegular, pairwiseClient2);

    assertNotSame(pairwiseSub, pairwise1);
    assertNotSame(pairwiseSub, pairwise2);

    assertEquals(pairwise1, pairwise2);

    // see if the pairwise id's are actual UUIDs
    UUID uudi1 = UUID.fromString(pairwise1);
    UUID uuid2 = UUID.fromString(pairwise2);
  }
  /**
   * The merge method should copy all entity data into entity manager. Entity itself in not attached
   * nor persisted.
   */
  @Test
  public void entityEquality_mergeInto_EntityManager() {
    // load and detach entity
    EntityManager em1 = factory.createEntityManager();
    Person person1 = em1.find(Person.class, SIMON_SLASH_ID);
    em1.close();

    // change its property
    person1.setFirstName("New Name");

    // merge it into some entity manager
    EntityManager em2 = factory.createEntityManager();
    em2.merge(person1);

    // this change will be ignored
    person1.setFirstName("Ignored Change");

    Person person2 = em2.find(Person.class, SIMON_SLASH_ID);
    em2.close();

    // entity itself was not attached
    assertNotSame(person1, person2);
    // however, its changed data was
    assertEquals("New Name", person2.getFirstName());

    // changed data are NOT available in different entity manager
    EntityManager em3 = factory.createEntityManager();
    Person person3 = em3.find(Person.class, SIMON_SLASH_ID);
    em3.close();

    assertNotSame("New Name", person3.getFirstName());
  }
  @Test
  public void testTemplateOverridingStoreByValue() throws Exception {
    cacheManager =
        cachingProvider.getCacheManager(
            getClass()
                .getResource("/org/ehcache/docs/ehcache-jsr107-template-override.xml")
                .toURI(),
            getClass().getClassLoader());

    MutableConfiguration<Long, String> mutableConfiguration =
        new MutableConfiguration<Long, String>();
    mutableConfiguration.setTypes(Long.class, String.class);

    Cache<Long, String> myCache = null;
    myCache = cacheManager.createCache("anyCache", mutableConfiguration);
    myCache.put(1L, "foo");
    assertNotSame("foo", myCache.get(1L));
    assertTrue(myCache.getConfiguration(Configuration.class).isStoreByValue());

    myCache = cacheManager.createCache("byRefCache", mutableConfiguration);
    myCache.put(1L, "foo");
    assertSame("foo", myCache.get(1L));
    assertFalse(myCache.getConfiguration(Configuration.class).isStoreByValue());

    myCache = cacheManager.createCache("weirdCache1", mutableConfiguration);
    myCache.put(1L, "foo");
    assertNotSame("foo", myCache.get(1L));
    assertTrue(myCache.getConfiguration(Configuration.class).isStoreByValue());

    myCache = cacheManager.createCache("weirdCache2", mutableConfiguration);
    myCache.put(1L, "foo");
    assertSame("foo", myCache.get(1L));
    assertFalse(myCache.getConfiguration(Configuration.class).isStoreByValue());
  }
  @Test
  public void testValidateHtml() {
    // check for null handling
    String expected = null;
    String actual = StringUtils.validateHtml(expected);
    Assert.assertEquals(expected, actual);

    // check for empty string handling
    expected = "";
    actual = StringUtils.validateHtml(expected);
    Assert.assertNull(actual);

    // check unclosed tags
    expected = "<input type=something that is not correct";
    actual = StringUtils.validateHtml(expected);
    Assert.assertNotNull(actual);
    Assert.assertNotSame(expected, actual);

    // check invalid tags
    expected = "<p>This paragraph is <b>not</p> correct!</b>";
    Assert.assertNotNull(actual);
    Assert.assertNotSame(expected, actual);

    // check closing html block
    expected = "</body></html>";
    Assert.assertNotNull(actual);
    Assert.assertNotSame(expected, actual);
  }
  private void test(Object original, boolean same) throws IOException, ClassNotFoundException {
    try {
      Object marshalled = this.marshaller.marshal(original);

      if (original != null) {
        assertTrue(original instanceof Serializable);
      }
      if (marshalled != null) {
        assertTrue(marshalled instanceof Serializable);
      }

      if (same) {
        assertSame(original, marshalled);
      } else {
        assertNotSame(original, marshalled);
      }

      Object unmarshalled = this.marshaller.unmarshal(marshalled);

      if (same) {
        assertSame(marshalled, unmarshalled);
      } else {
        assertNotSame(marshalled, unmarshalled);
        assertEquals(original, unmarshalled);
      }
    } catch (IllegalArgumentException e) {
      assertFalse(same);
      assertFalse(original instanceof Serializable);
    }
  }
 @Test(timeout = TIMEOUT)
 public void testDeepCopyNestedCollection() {
   ArrayList<ArrayList<?>> elmMatrix = new ArrayList<ArrayList<?>>();
   CloneableCopy elm1 = new CloneableCopy("elm1");
   CloneableCopy elm2 = new CloneableCopy("elm2");
   CloneableCopy elm3 = null;
   ArrayList<CloneableCopy> nested = new ArrayList<CloneableCopy>(2);
   Collections.addAll(nested, elm1, elm2, elm3);
   elmMatrix.add(nested);
   // try adding itself as element
   // elmMatrix.add(elmMatrix);
   ArrayList<ArrayList<?>> copy = MiscUtils.deepCollectionCopy(elmMatrix);
   assertNotNull(copy);
   assertNotSame(elmMatrix, copy);
   assertEquals(elmMatrix, copy);
   assertNotSame(elmMatrix.get(0), copy.get(0));
   // assertNotSame(elmMatrix.get(1),copy.get(1));
   // make sure nested was also copied
   ArrayList<?> nestedCopy = copy.get(0);
   for (int i = 0; i < nestedCopy.size(); ++i) {
     if (nested.get(i) != null) assertNotSame(nestedCopy.get(i), nested.get(i));
     else assertNull(nestedCopy.get(i));
     // assertEquals(nestedCopy.get(i),nested.get(i));
   }
 }
  /** The transition action must be part of the reaction effect sequence */
  @Test
  public void testStateReaction_WithTransitionAction() {
    SimpleFlatTSC tsc = new SimpleFlatTSC();
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
    ReactionEffect effect = _createReactionEffect(tsc.t1);
    AssignmentExpression assign =
        _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), effect);

    ExecutionFlow flow = sequencer.transform(tsc.sc);

    // test state with one outgoing transition
    ExecutionState s1 = flow.getStates().get(0);
    ExecutionState s2 = flow.getStates().get(1);
    assertEquals(tsc.s1.getName(), s1.getSimpleName());
    assertEquals(tsc.s2.getName(), s2.getSimpleName());

    assertEquals(1, s1.getReactions().size());
    Reaction reaction = s1.getReactions().get(0);

    assertNotNull(reaction.getCheck());

    assertNotNull(reaction.getEffect());
    Sequence seq = (Sequence) reaction.getEffect();

    assertCall(seq, 0, s1.getExitSequence());

    assertClass(Sequence.class, seq.getSteps().get(1));
    Execution _exec = (Execution) ((Sequence) seq.getSteps().get(1)).getSteps().get(0);
    AssignmentExpression _assign = (AssignmentExpression) _exec.getStatement();
    assertNotSame(_assign, assign);
    assertNotSame(_assign.getVarRef(), assign.getVarRef());
    assertNotSame(_assign.getVarRef(), v1);

    assertCall(seq, 2, s2.getEnterSequences().get(0));
  }
Example #11
0
  @Test
  public void testLifecycle() throws Exception {
    Timer timer = SettingsRefreshInterval.timer;
    RefreshInterval interval = SettingsRefreshInterval.CLASSPATH;
    interval.setMilliseconds(1);
    PS ps = new PS(interval);
    Settings s = new SettingsBuilder().add(ps).build();
    Reference<Settings> ref = new WeakReference<>(s);
    Thread.sleep(20);
    int cc = ps.callCount;
    assertNotSame("Refresh task not called", 0, cc);
    Thread.sleep(20);
    assertNotSame("Refresh task not being called continuously", cc, ps.callCount);
    s = null;
    for (int i = 0; i < 10; i++) {
      System.gc();
      if (ref.get() == null) {
        break;
      }
      Thread.sleep(200);
    }
    assertNull("Settings not garbage collected", ref.get());

    cc = ps.callCount;
    Thread.sleep(30);
    assertSame(
        "Settings garbage collected, but its internals are " + "still being refreshed",
        cc,
        ps.callCount);
  }
  @Test
  public void offspringCreation() {
    Individual i1 = new Individual();
    Individual i2 = new Individual();

    i1.put(Property.CANDIDATE_SOLUTION, Vector.of(0.0, 1.0, 2.0, 3.0, 4.0));
    i2.put(Property.CANDIDATE_SOLUTION, Vector.of(5.0, 6.0, 7.0, 8.0, 9.0));

    i1.setFitnessCalculator(new MockFitnessCalculator());
    i2.setFitnessCalculator(new MockFitnessCalculator());

    List<Individual> parents = Lists.newArrayList(i1, i2);

    CrossoverOperator crossoverStrategy = new CrossoverOperator();
    crossoverStrategy.setCrossoverStrategy(new OnePointCrossoverStrategy());
    crossoverStrategy.setCrossoverProbability(ConstantControlParameter.of(1.0));
    List<Individual> children = crossoverStrategy.crossover(fj.data.List.iterableList(parents));

    Vector child1 = (Vector) children.get(0).getPosition();
    Vector child2 = (Vector) children.get(1).getPosition();
    Vector parent1 = (Vector) i1.getPosition();
    Vector parent2 = (Vector) i2.getPosition();

    Assert.assertEquals(2, children.size());
    for (int i = 0; i < i1.getDimension(); i++) {
      Assert.assertNotSame(child1.get(i), parent1.get(i));
      Assert.assertNotSame(child1.get(i), parent2.get(i));
      Assert.assertNotSame(child2.get(i), parent1.get(i));
      Assert.assertNotSame(child2.get(i), parent2.get(i));
    }
  }
 @Test
 public void testClone() {
   DataSet clonedSet = (DataSet) this.sampleDataSet.clone();
   Assert.assertNotSame(clonedSet, this.sampleDataSet);
   Assert.assertNotSame(clonedSet.getContent(), this.sampleDataSet.getContent());
   Assert.assertNotSame(clonedSet.getHeadings(), this.sampleDataSet.getHeadings());
 }
  @Test
  public void testMultipleKernels() {
    assertNotNull(kernelImpl);
    kernelImpl.start();
    DSpaceKernel kernel = kernelImpl.getManagedBean();
    assertNotNull(kernel);
    assertNotNull(kernelImpl.getConfigurationService());
    assertNotNull(kernelImpl.getServiceManager());
    assertNotNull(kernel.getConfigurationService());
    assertNotNull(kernel.getServiceManager());
    assertEquals(kernel.getConfigurationService(), kernelImpl.getConfigurationService());
    assertEquals(kernel.getServiceManager(), kernelImpl.getServiceManager());

    DSpaceKernelImpl kernelImpl2 =
        DSpaceKernelInit.getKernel("AZ-kernel"); // checks for the existing kernel but does not init
    kernelImpl2.start();
    DSpaceKernel kernel2 = kernelImpl2.getManagedBean();
    assertNotNull(kernel2);
    assertNotNull(kernelImpl2.getConfigurationService());
    assertNotNull(kernelImpl2.getServiceManager());
    assertNotNull(kernel2.getConfigurationService());
    assertNotNull(kernel2.getServiceManager());
    assertEquals(kernel2.getConfigurationService(), kernelImpl2.getConfigurationService());
    assertEquals(kernel2.getServiceManager(), kernelImpl2.getServiceManager());

    assertNotSame(kernel, kernel2);
    assertNotSame(kernel.getConfigurationService(), kernel2.getConfigurationService());
    assertNotSame(kernel.getServiceManager(), kernel2.getServiceManager());

    kernelImpl2.stop();
    kernelImpl.stop();
  }
  // dependency bundle - depends on service2, service3 and, through a nested
  // reference, to service1
  // simple.service2 - publishes service2
  // simple.service3 - publishes service3
  // simple - publishes service1
  @Test
  public void testDependencies() throws Exception {
    System.setProperty(DELAY_PROP, "10000");

    final Bundle dependencyTestBundle = installTestBundle("dependencies");
    final Bundle simpleService2Bundle = installTestBundle("simple.service2");
    final Bundle simpleService3Bundle = installTestBundle("simple.service3");
    final Bundle factoryServiceBundle = installTestBundle("dependendencies.factory");

    assertNotNull("Cannot find the factory service bundle", factoryServiceBundle);
    assertNotNull("Cannot find the simple service 2 bundle", simpleService2Bundle);
    assertNotNull("Cannot find the simple service 3 bundle", simpleService3Bundle);
    assertNotNull("dependencyTest can't be resolved", dependencyTestBundle);

    assertNotSame(
        "simple service bundle is in the activated state!",
        Bundle.ACTIVE,
        factoryServiceBundle.getState());
    assertNotSame(
        "simple service 2 bundle is in the activated state!",
        Bundle.ACTIVE,
        simpleService2Bundle.getState());
    assertNotSame(
        "simple service 3 bundle is in the activated state!",
        Bundle.ACTIVE,
        simpleService3Bundle.getState());

    startDependencyAsynch(dependencyTestBundle);
    Thread.sleep(2000); // Yield to give bundle time to get into waiting
    // state.
    ServiceReference dependentRef = bundleContext.getServiceReference(DEPENDENT_CLASS_NAME);

    assertNull("Service with unsatisfied dependencies has been started!", dependentRef);

    startDependency(simpleService3Bundle);

    dependentRef = bundleContext.getServiceReference(DEPENDENT_CLASS_NAME);

    assertNull("Service with unsatisfied dependencies has been started!", dependentRef);

    startDependency(simpleService2Bundle);

    assertNull("Service with unsatisfied dependencies has been started!", dependentRef);

    dependentRef = bundleContext.getServiceReference(DEPENDENT_CLASS_NAME);

    startDependency(factoryServiceBundle);

    assertNull("Service with unsatisfied dependencies has been started!", dependentRef);

    waitOnContextCreation("org.eclipse.gemini.blueprint.iandt.dependencies");

    dependentRef = bundleContext.getServiceReference(DEPENDENT_CLASS_NAME);

    assertNotNull("Service has not been started!", dependentRef);

    Object dependent = bundleContext.getService(dependentRef);

    assertNotNull("Service is not available!", dependent);
  }
  @Test
  public void testDefaultConsequenceWithMultipleNamedConsequenceCompilation() {
    String defaultCon = " System.out.println(\"this is a test\" + $cheese);\n ";

    Map<String, Object> namedConsequences = new HashMap<String, Object>();
    String name1 = " System.out.println(\"this is a test name1\" + $cheese);\n ";
    namedConsequences.put("name1", name1);
    String name2 = " System.out.println(\"this is a test name2\" + $cheese);\n ";
    namedConsequences.put("name2", name2);

    setupTest(defaultCon, namedConsequences);
    assertEquals(2, context.getRule().getNamedConsequences().size());

    assertTrue(context.getRule().getConsequence() instanceof MVELConsequence);

    assertTrue(context.getRule().getNamedConsequences().get("name1") instanceof MVELConsequence);

    assertTrue(context.getRule().getNamedConsequences().get("name2") instanceof MVELConsequence);

    assertNotSame(
        context.getRule().getConsequence(), context.getRule().getNamedConsequences().get("name1"));
    assertNotSame(
        context.getRule().getConsequence(), context.getRule().getNamedConsequences().get("name2"));
    assertNotSame(
        context.getRule().getNamedConsequences().get("name1"),
        context.getRule().getNamedConsequences().get("name2"));
  }
Example #17
0
 @Test
 public void test2() throws Exception {
   FatherRel rel1 = new FatherRel("Jens", "Max");
   FatherRel rel2 = new FatherRel("Jen", "Max");
   assertNotSame(rel1, rel2);
   assertNotSame(rel1.hashCode(), rel2.hashCode());
 }
  @Test
  public void testClassLoaderIsolation() throws Exception {

    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      AnObject obj = new AnObjectImpl();
      byte[] bytes = ObjectInputStreamWithClassLoaderTest.toBytes(obj);

      // Class.isAnonymousClass() call used in ObjectInputStreamWithClassLoader
      // need to access the enclosing class and its parent class of the obj
      // i.e. ActiveMQTestBase and Assert.
      ClassLoader testClassLoader =
          ObjectInputStreamWithClassLoaderTest.newClassLoader(
              obj.getClass(), ActiveMQTestBase.class, Assert.class);
      Thread.currentThread().setContextClassLoader(testClassLoader);

      ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
      ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais);

      Object deserializedObj = ois.readObject();

      Assert.assertNotSame(obj, deserializedObj);
      Assert.assertNotSame(obj.getClass(), deserializedObj.getClass());
      Assert.assertNotSame(
          obj.getClass().getClassLoader(), deserializedObj.getClass().getClassLoader());
      Assert.assertSame(testClassLoader, deserializedObj.getClass().getClassLoader());
    } finally {
      Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
  }
  @Test
  public void testCopiers() throws Exception {
    Configuration configuration =
        new XmlConfiguration(this.getClass().getResource("/configs/cache-copiers.xml"));
    final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
    cacheManager.init();

    Cache<Description, Person> bar = cacheManager.getCache("bar", Description.class, Person.class);
    Description desc = new Description(1234, "foo");
    Person person = new Person("Bar", 24);
    bar.put(desc, person);
    assertEquals(person, bar.get(desc));
    assertNotSame(person, bar.get(desc));

    Cache<Long, Person> baz = cacheManager.getCache("baz", Long.class, Person.class);
    baz.put(1L, person);
    assertEquals(person, baz.get(1L));
    assertNotSame(person, baz.get(1L));

    Employee empl = new Employee(1234, "foo", 23);
    Cache<Long, Employee> bak = cacheManager.getCache("bak", Long.class, Employee.class);
    bak.put(1L, empl);
    assertSame(empl, bak.get(1L));
    cacheManager.close();
  }
  @Test
  public void testAcceptsComponentParametersForComponent() {
    Reader script =
        new StringReader(
            "A = org.picocontainer.script.testmodel.A\n"
                + "B = org.picocontainer.script.testmodel.B\n"
                + "container {\n"
                + "    component(:key => 'a1', :class => A)\n"
                + "    component(:key => 'a2', :class => A)\n"
                + "    component(:key => 'b1', :class => B, :parameters => [ key('a1') ])\n"
                + "    component(:key => 'b2', :class => B, :parameters => key('a2'))\n"
                + "}");

    PicoContainer pico = buildContainer(script, null, ASSEMBLY_SCOPE);
    A a1 = (A) pico.getComponent("a1");
    A a2 = (A) pico.getComponent("a2");
    B b1 = (B) pico.getComponent("b1");
    B b2 = (B) pico.getComponent("b2");

    assertNotNull(a1);
    assertNotNull(a2);
    assertNotNull(b1);
    assertNotNull(b2);

    assertSame(a1, b1.getA());
    assertSame(a2, b2.getA());
    assertNotSame(a1, a2);
    assertNotSame(b1, b2);
  }
  /**
   * Refresh method test loads an entity with two different entity managers. One updates the entity
   * and another refreshes it. The test checks whether refreshed entity contains changes.
   */
  @Test
  public void entityEquality_refresh_EntityManager() {
    // load an entity
    EntityManager emRefresh = factory.createEntityManager();
    Person person1 = emRefresh.find(Person.class, SIMON_SLASH_ID);

    // load the same entity by different entity manager
    EntityManager emChange = factory.createEntityManager();
    Person person2 = emChange.find(Person.class, SIMON_SLASH_ID);

    // change the first entity - second entity remains the same
    emRefresh.getTransaction().begin();
    person1.setFirstName("refreshDemo");
    assertNotSame("refreshDemo", person2.getFirstName());

    // commit the transaction - second entity still remains the same
    emRefresh.getTransaction().commit();
    assertNotSame("refreshDemo", person2.getFirstName());

    // refresh second entity - it changes
    emChange.refresh(person2);
    assertEquals("refreshDemo", person2.getFirstName());

    emRefresh.close();
    emChange.close();
  }
  /**
   * Test the old reader is still open until all searchers using it are closed
   *
   * @throws Exception
   */
  @Test
  public void testOldReaderStillOpenTillAllSearchersClosed() throws Exception {
    final DefaultIndexEngine engine = getRamDirectory();

    final IndexSearcher oldSearcher1 = engine.getSearcher();
    final IndexSearcher oldSearcher2 = engine.getSearcher();
    final IndexSearcher oldSearcher3 = engine.getSearcher();
    final IndexReader reader = oldSearcher1.getIndexReader();
    assertSame("should be same until something is written", oldSearcher1, oldSearcher2);
    assertSame("should be same until something is written", oldSearcher1, oldSearcher3);

    writeTestDocument(engine);

    oldSearcher1.close();

    final IndexSearcher newSearcher = engine.getSearcher();
    assertNotSame(oldSearcher1, newSearcher);
    final IndexReader newReader = newSearcher.getIndexReader();
    assertNotSame(reader, newReader);
    assertReaderOpen(reader);
    assertReaderOpen(newReader);
    oldSearcher2.close();
    assertReaderOpen(reader);
    oldSearcher3.close();
    assertReaderClosed(reader);
    assertReaderOpen(newReader);
  }
  @Test
  public void retainAllFromEntrySet() {
    MutableMapIterable<String, Integer> map =
        this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3);
    Assert.assertFalse(
        map.entrySet()
            .retainAll(
                FastList.newListWith(
                    ImmutableEntry.of("One", 1),
                    ImmutableEntry.of("Two", 2),
                    ImmutableEntry.of("Three", 3),
                    ImmutableEntry.of("Four", 4))));

    Assert.assertTrue(
        map.entrySet()
            .retainAll(
                FastList.newListWith(
                    ImmutableEntry.of("One", 1),
                    ImmutableEntry.of("Three", 3),
                    ImmutableEntry.of("Four", 4))));
    Assert.assertEquals(UnifiedMap.newWithKeysValues("One", 1, "Three", 3), map);

    MutableMapIterable<Integer, Integer> integers = this.newMapWithKeysValues(1, 1, 2, 2, 3, 3);
    Integer copy = new Integer(1);
    Assert.assertTrue(integers.entrySet().retainAll(mList(ImmutableEntry.of(copy, copy))));
    Assert.assertEquals(iMap(copy, copy), integers);
    Assert.assertNotSame(copy, Iterate.getOnly(integers.entrySet()).getKey());
    Assert.assertNotSame(copy, Iterate.getOnly(integers.entrySet()).getValue());
  }
  /**
   * Makes sure the builder returns a copy so that making changes in the builder doesn't mutate
   * previously built objects.
   */
  @Test
  public void testBuilder_returnsCopies() throws Exception {
    Builder builder =
        new Builder()
            .skipReportHeader(true)
            .skipColumnHeader(false)
            .skipReportSummary(true)
            .includeZeroImpressions(false);

    ReportingConfiguration config1 = builder.build();
    assertTrue(config1.isSkipReportHeader());
    assertFalse(config1.isSkipColumnHeader());
    assertTrue(config1.isSkipReportSummary());
    assertFalse(config1.isIncludeZeroImpressions());

    assertNotSame(
        "Build did not return a new instance on multiple invocations", config1, builder.build());

    builder.skipReportHeader(false);

    ReportingConfiguration config2 = builder.build();

    assertNotSame("Build did not return a new instance on multiple invocations", config1, config2);

    assertTrue(
        "Changes to builder should not pass through to built instances",
        config1.isSkipReportHeader());

    assertFalse(
        "Lastest changes to builder should be reflected in each call to build",
        config2.isSkipReportHeader());
  }
 @Test
 public void testGetVelocity() throws Exception {
   assertNotSame(VELOCITY, moveRequest1.getVelocity());
   assertNotSame(VELOCITY, moveRequest2.getVelocity());
   assertArrayEquals(VELOCITY, moveRequest1.getVelocity(), 0.00001);
   assertArrayEquals(VELOCITY, moveRequest2.getVelocity(), 0.00001);
 }
Example #26
0
  @Test
  public void DynamicContainerProviderInServiceLocator() throws Exception {
    ServiceLocator.setContainerProvider(new DynamicContainerProvider());
    SimpleContainer c1 = ServiceLocator.getCurrent().getInstance(SimpleContainer.class);
    SimpleContainer c2 = ServiceLocator.getCurrent().getInstance(SimpleContainer.class);

    assertNotSame(c1, c2);
    assertNotSame(c, c1);
  }
 @Test
 public void toSortedList() {
   MutableList<Integer> integers = SingletonListTest.newWith(1);
   MutableList<Integer> list = integers.toSortedList(Collections.<Integer>reverseOrder());
   Verify.assertStartsWith(list, 1);
   Assert.assertNotSame(integers, list);
   MutableList<Integer> list2 = integers.toSortedList();
   Verify.assertStartsWith(list2, 1);
   Assert.assertNotSame(integers, list2);
 }
Example #28
0
 /** Tests the equality with the same Game set (the Game does not contains any Hit). */
 @Test
 public void testGamesNotEqual01() {
   Game game1 = JUnitTestConstants.getFilledGame();
   Game game2 = JUnitTestConstants.getFilledGame();
   game2.setBlack("otherBlackValue");
   games1.getGame().add(game1);
   games2.getGame().add(game2);
   assertNotSame(games1, games2);
   assertNotSame(games2, games1);
 }
Example #29
0
 @Test
 public void testSerializableExtra() throws Exception {
   Intent intent = new Intent();
   TestSerializable serializable = new TestSerializable("some string");
   assertSame(intent, intent.putExtra("foo", serializable));
   assertEquals(serializable, intent.getExtras().get("foo"));
   assertNotSame(serializable, intent.getExtras().get("foo"));
   assertEquals(serializable, intent.getSerializableExtra("foo"));
   assertNotSame(serializable, intent.getSerializableExtra("foo"));
 }
  @Test
  public void testDuplicateArchimateElements() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IFolder folder = model.getFolder(FolderType.BUSINESS);

    IArchimateElement element1 =
        (IArchimateElement)
            tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
    element1.setName("Actor 1");
    element1.setDocumentation("Doc 1");
    assertEquals(1, folder.getElements().size());
    assertSame(element1, folder.getElements().get(0));

    IArchimateElement element2 =
        (IArchimateElement)
            tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
    element2.setName("Actor 2");
    element2.setDocumentation("Doc 2");
    assertEquals(2, folder.getElements().size());
    assertSame(element2, folder.getElements().get(1));

    IArchimateRelationship relation =
        (IArchimateRelationship)
            tm.createModelElementAndAddToModel(
                IArchimatePackage.eINSTANCE.getAssociationRelationship());
    relation.connect(element1, element2);
    assertTrue(element1.getSourceRelationships().contains(relation));
    assertTrue(element2.getTargetRelationships().contains(relation));

    DuplicateCommandHandler handler =
        new DuplicateCommandHandler(new Object[] {element1, element2});
    handler.duplicate();

    assertEquals(4, folder.getElements().size());
    assertSame(element1, folder.getElements().get(0));
    assertSame(element2, folder.getElements().get(1));

    IArchimateElement copy1 = (IArchimateElement) folder.getElements().get(2);
    assertNotSame(element1, copy1);
    assertNotEquals(element1.getId(), copy1.getId());
    assertEquals(element1.getName() + " (copy)", copy1.getName());
    assertEquals(element1.getDocumentation(), copy1.getDocumentation());

    IArchimateElement copy2 = (IArchimateElement) folder.getElements().get(3);
    assertNotSame(element2, copy2);
    assertNotEquals(element2.getId(), copy2.getId());
    assertEquals(element2.getName() + " (copy)", copy2.getName());
    assertEquals(element2.getDocumentation(), copy2.getDocumentation());

    assertTrue(copy1.getSourceRelationships().isEmpty());
    assertTrue(copy1.getTargetRelationships().isEmpty());
    assertTrue(copy2.getSourceRelationships().isEmpty());
    assertTrue(copy2.getTargetRelationships().isEmpty());
  }