Java Code Examples for org.junit.Assert.assertSame()

The following are Jave code examples for showing how to use assertSame() of the org.junit.Assert class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: oscm   File: VOFinderTest.java   View Source Code Vote up 6 votes
@Test
public void testFindPricedOption() {
    List<VOPricedOption> list = new ArrayList<VOPricedOption>();
    parameterDefinitionWithOption.getParameterOptions().get(3);

    for (VOParameterOption option : parameterDefinitionWithOption
            .getParameterOptions()) {
        VOPricedOption pricedOption = new VOPricedOption();
        pricedOption.setParameterOptionKey(option.getKey());
        list.add(pricedOption);
    }
    Assert.assertSame(list.get(3), VOFinder.findPricedOption(list,
            parameterDefinitionWithOption.getParameterOptions().get(3)));

    Assert.assertNull(VOFinder.findPricedOption(list,
            new VOParameterOption("", "", "")));
    Assert.assertNull(VOFinder.findPricedOption(null,
            parameterDefinitionWithOption.getParameterOptions().get(0)));
    Assert.assertNull(VOFinder.findPricedOption(list, null));
}
 
Example 2
Project: incubator-servicecomb-java-chassis   File: TestAbstractRestInvocation.java   View Source Code Vote up 6 votes
@Test
public void sendFailResponseHaveProduceProcessor() {
  Holder<Response> result = new Holder<>();
  restInvocation = new AbstractRestInvocationForTest() {
    @Override
    protected void doInvoke() throws Throwable {
    }

    @Override
    protected void sendResponseQuietly(Response response) {
      result.value = response;
    }
  };
  initRestInvocation();
  restInvocation.produceProcessor = ProduceProcessorManager.PLAIN_PROCESSOR;

  Throwable e = new InvocationException(Status.BAD_GATEWAY, "");
  restInvocation.sendFailResponse(e);
  Assert.assertSame(e, result.value.getResult());
  Assert.assertSame(ProduceProcessorManager.PLAIN_PROCESSOR, restInvocation.produceProcessor);
}
 
Example 3
Project: incubator-servicecomb-java-chassis   File: TestEndpointDiscoveryFilter.java   View Source Code Vote up 6 votes
@Test
public void createEndpointNormal(@Mocked Transport transport, @Mocked MicroserviceInstance instance) {
  String endpoint = "rest://ip:port";
  Object address = new Object();

  new Expectations() {
    {
      transportManager.findTransport(Const.RESTFUL);
      result = transport;
      transport.parseAddress(endpoint);
      result = address;
    }
  };

  Endpoint ep = (Endpoint) filter.createEndpoint(Const.RESTFUL, endpoint, instance);
  Assert.assertSame(transport, ep.getTransport());
  Assert.assertSame(address, ep.getAddress());
  Assert.assertSame(instance, ep.getMicroserviceInstance());
  Assert.assertEquals(endpoint, ep.getEndpoint());
}
 
Example 4
Project: incubator-servicecomb-java-chassis   File: TestDefaultMicroserviceVersionFactory.java   View Source Code Vote up 6 votes
@Test
public void create(@Mocked Microservice microservice) {
  String microserviceId = "id";
  new Expectations(RegistryUtils.class) {
    {
      RegistryUtils.getMicroservice(microserviceId);
      result = microservice;
      microservice.getVersion();
      result = "1.0.0";
    }
  };

  MicroserviceVersion microserviceVersion = new DefaultMicroserviceVersionFactory().create("", microserviceId);
  Assert.assertSame(microservice, microserviceVersion.getMicroservice());
  Assert.assertEquals("1.0.0", microserviceVersion.getVersion().getVersion());
}
 
Example 5
Project: GitHub   File: JSONPath_field_access_filter_in_int.java   View Source Code Vote up 6 votes
public void test_list_not_in_null() throws Exception {
    JSONPath path = new JSONPath("[id not in (null)]");
    
    List<Entity> entities = new ArrayList<Entity>();
    entities.add(new Entity(1001, "ljw2083"));
    entities.add(new Entity(1002, "wenshao"));
    entities.add(new Entity(1003, "yakolee"));
    entities.add(new Entity(1004, null));
    
    List<Object> result = (List<Object>) path.eval(entities);
    Assert.assertEquals(4, result.size());
    Assert.assertSame(entities.get(0), result.get(0));
    Assert.assertSame(entities.get(1), result.get(1));
    Assert.assertSame(entities.get(2), result.get(2));
    Assert.assertSame(entities.get(3), result.get(3));
}
 
Example 6
Project: GitHub   File: JSONPath_field_access_filter_like.java   View Source Code Vote up 5 votes
public void test_list_like_right_match() throws Exception {
    JSONPath path = new JSONPath("$[?(@.name like '%2083')]");

    List<Entity> entities = new ArrayList<Entity>();
    entities.add(new Entity(1001, "ljw2083"));
    entities.add(new Entity(1002, "wenshao"));
    entities.add(new Entity(1003, "yakolee"));
    entities.add(new Entity(null, null));

    List<Object> result = (List<Object>) path.eval(entities);
    Assert.assertEquals(1, result.size());
    Assert.assertSame(entities.get(0), result.get(0));
}
 
Example 7
Project: https-github.com-apache-zookeeper   File: AsyncOps.java   View Source Code Vote up 5 votes
void latch_await(){
    try {
        latch.await(10000, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        Assert.fail("unexpected interrupt");
    }
    Assert.assertSame(0L, latch.getCount());
}
 
Example 8
Project: plugin-id-ldap   File: LdapCacheRepositoryTest.java   View Source Code Vote up 5 votes
@Test
public void updateUser() {
	user.setFirstName("L");

	repository.update(user);

	Mockito.verify(repository.ldapCacheDao).update(user);
	Assert.assertSame("L", users.get("u").getFirstName());
}
 
Example 9
Project: GitHub   File: JSONPath_between_int.java   View Source Code Vote up 5 votes
public void test_between() throws Exception {
    List list = new ArrayList();
    list.add(new Entity(101, "kiki"));
    list.add(new Entity(102, "ljw2083"));
    list.add(new Entity(103, "ljw2083"));
    List<Object> result = (List<Object>) JSONPath.eval(list, "$[id between 101 and 101]");
    Assert.assertEquals(1, result.size());
    Assert.assertSame(list.get(0), result.get(0));
}
 
Example 10
Project: rskj   File: BlockStoreTest.java   View Source Code Vote up 5 votes
@Test
public void saveAndGetBlockByHash() {
    BlockStore store = new BlockStore();
    Block block = BlockGenerator.getInstance().getGenesisBlock();

    store.saveBlock(block);

    Assert.assertSame(block, store.getBlockByHash(block.getHash()));
    Assert.assertEquals(0, store.minimalHeight());
    Assert.assertEquals(0, store.maximumHeight());
}
 
Example 11
Project: crnk-framework   File: DocumentMapperTest.java   View Source Code Vote up 5 votes
@Test
public void testErrors() {
	JsonApiResponse response = new JsonApiResponse();

	ErrorData error = Mockito.mock(ErrorData.class);
	response.setErrors(Arrays.asList(error));

	Document document = mapper.toDocument(response, createAdapter(Task.class));
	List<ErrorData> errors = document.getErrors();
	Assert.assertEquals(1, errors.size());
	Assert.assertSame(error, errors.get(0));
}
 
Example 12
Project: incubator-servicecomb-java-chassis   File: TestMicroserviceVersionRule.java   View Source Code Vote up 5 votes
@Test
public void setInstances() {
  MicroserviceVersion v1 = MicroserviceVersionTestUtils.createMicroserviceVersion("1", "0.0.1");
  microserviceVersionRule.addMicroserviceVersion(v1);

  MicroserviceVersion v2 = MicroserviceVersionTestUtils.createMicroserviceVersion("2", "2.0.0");
  microserviceVersionRule.addMicroserviceVersion(v2);

  MicroserviceInstance instance1 = new MicroserviceInstance();
  instance1.setServiceId("1");
  instance1.setInstanceId("i1");

  MicroserviceInstance instance2 = new MicroserviceInstance();
  instance2.setServiceId("2");
  instance2.setInstanceId("i2");

  MicroserviceInstance instance3 = new MicroserviceInstance();
  instance3.setServiceId("3");
  instance3.setInstanceId("i3");

  InstanceCache orgCache = microserviceVersionRule.getInstanceCache();
  microserviceVersionRule.setInstances(Arrays.asList(instance1, instance2, instance3));

  Assert.assertThat(microserviceVersionRule.getInstances().values(), Matchers.contains(instance2));
  Assert.assertNotSame(orgCache, microserviceVersionRule.getInstanceCache());
  Assert.assertSame(microserviceVersionRule.getInstances(),
      microserviceVersionRule.getInstanceCache().getInstanceMap());
  Assert.assertSame(microserviceVersionRule.getInstances(),
      microserviceVersionRule.getVersionedCache().data());
}
 
Example 13
Project: crnk-framework   File: CrnkBootTest.java   View Source Code Vote up 5 votes
@Test
public void setQuerySpecDeserializer() {
	CrnkBoot boot = new CrnkBoot();
	boot.setServiceDiscoveryFactory(serviceDiscoveryFactory);
	boot.setDefaultServiceUrlProvider(Mockito.mock(ServiceUrlProvider.class));

	QuerySpecDeserializer deserializer = Mockito.mock(QuerySpecDeserializer.class);
	boot.setQuerySpecDeserializer(deserializer);
	Assert.assertSame(deserializer, boot.getQuerySpecDeserializer());
	boot.boot();

	HttpRequestProcessorImpl requestDispatcher = boot.getRequestDispatcher();
	QueryAdapterBuilder queryAdapterBuilder = requestDispatcher.getQueryAdapterBuilder();
	Assert.assertTrue(queryAdapterBuilder instanceof QuerySpecAdapterBuilder);
}
 
Example 14
Project: incubator-servicecomb-java-chassis   File: TestAbstractDiscoveryFilter.java   View Source Code Vote up 5 votes
@Test
public void discoveryInited() {
  doDiscovery();

  Assert.assertEquals(1, childrenInitedCallCount);
  Assert.assertEquals(0, initCallCount);
  Assert.assertSame(child, result);
}
 
Example 15
Project: java-threading   File: AsyncQueueTest.java   View Source Code Vote up 5 votes
@Test
public void testCompleteThenPoll() {
	GenericParameterHelper enqueuedValue = new GenericParameterHelper(1);
	queue.add(enqueuedValue);
	queue.complete();
	Assert.assertFalse(queue.getFuture().isDone());

	GenericParameterHelper dequeuedValue = queue.poll();
	Assert.assertNotNull(dequeuedValue);
	Assert.assertSame(enqueuedValue, dequeuedValue);
	Assert.assertTrue(queue.getFuture().isDone());
}
 
Example 16
Project: incubator-servicecomb-java-chassis   File: TestDefaultHttpClientFilter.java   View Source Code Vote up 5 votes
@Test
public void testFindProduceProcessorJsonWithCharset(@Mocked RestOperationMeta restOperation,
    @Mocked HttpServletResponseEx responseEx, @Mocked ProduceProcessor produceProcessor) {
  new Expectations() {
    {
      responseEx.getHeader(HttpHeaders.CONTENT_TYPE);
      result = "json; UTF-8";
      restOperation.findProduceProcessor("json");
      result = produceProcessor;
    }
  };

  Assert.assertSame(produceProcessor, filter.findProduceProcessor(restOperation, responseEx));
}
 
Example 17
Project: jrpip   File: PacketTest.java   View Source Code Vote up 5 votes
@Test
public void testReturnByteArrayToThePool()
{
    ByteArrayPool byteArrayPool = new ByteArrayPool(10, 3);
    byte[] data = new byte[3];
    Packet packet = new Packet(10, data, 3);
    packet.returnByteArrayToThePool(byteArrayPool);
    Assert.assertSame(data, byteArrayPool.borrowByteArray(3));
}
 
Example 18
Project: GitHub   File: RefTest2.java   View Source Code Vote up 4 votes
public void test_parse_1() throws Exception {
    Object[] array2 = JSON.parseObject("[{\"$ref\":\"@\"}]", Object[].class);
    Assert.assertSame(array2, array2[0]);
}
 
Example 19
Project: Bartout   File: BartoutTest.java   View Source Code Vote up 4 votes
@Test
public void testGetInstance() throws Exception {
    Bartout one = Bartout.getInstance();
    Bartout two = Bartout.getInstance();
    Assert.assertSame("Check if Instance 'one' is same referance as Instance 'two'", one, two);
}
 
Example 20
Project: hashsdn-controller   File: FollowerTest.java   View Source Code Vote up 4 votes
/**
 * This test verifies that when a new AppendEntries message is received with
 * new entries and the logs of the sender and receiver are out-of-sync that
 * the log is first corrected by removing the out of sync entries from the
 * log and then adding in the new entries sent with the AppendEntries message.
 */
@Test
public void testHandleAppendEntriesCorrectReceiverLogEntries() {
    logStart("testHandleAppendEntriesCorrectReceiverLogEntries");

    MockRaftActorContext context = createActorContext();

    // First set the receivers term to lower number
    context.getTermInformation().update(1, "test");

    // Prepare the receivers log
    MockRaftActorContext.SimpleReplicatedLog log = new MockRaftActorContext.SimpleReplicatedLog();
    log.append(newReplicatedLogEntry(1, 0, "zero"));
    log.append(newReplicatedLogEntry(1, 1, "one"));
    log.append(newReplicatedLogEntry(1, 2, "two"));

    context.setReplicatedLog(log);

    // Prepare the entries to be sent with AppendEntries
    List<ReplicatedLogEntry> entries = new ArrayList<>();
    entries.add(newReplicatedLogEntry(2, 2, "two-1"));
    entries.add(newReplicatedLogEntry(2, 3, "three"));

    // Send appendEntries with the same term as was set on the receiver
    // before the new behavior was created (1 in this case)
    // This will not work for a Candidate because as soon as a Candidate
    // is created it increments the term
    AppendEntries appendEntries = new AppendEntries(2, "leader", 1, 1, entries, 3, -1, (short)0);

    follower = createBehavior(context);

    RaftActorBehavior newBehavior = follower.handleMessage(leaderActor, appendEntries);

    Assert.assertSame(follower, newBehavior);

    // The entry at index 2 will be found out-of-sync with the leader
    // and will be removed
    // Then the two new entries will be added to the log
    // Thus making the log to have 4 entries
    assertEquals("Next index", 4, log.last().getIndex() + 1);
    //assertEquals("Entry 2", entries.get(0), log.get(2));

    assertEquals("Entry 1 data", "one", log.get(1).getData().toString());

    // Check that the entry at index 2 has the new data
    assertEquals("Entry 2", entries.get(0), log.get(2));

    assertEquals("Entry 3", entries.get(1), log.get(3));

    expectAndVerifyAppendEntriesReply(2, true, context.getId(), 2, 3);
}