junit.framework.Assert.assertNotSame()方法的使用及代码示例

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

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

Assert.assertNotSame介绍

[英]Asserts that two objects do not refer to the same object. If they do refer to the same object an AssertionFailedError is thrown.
[中]断言两个对象不引用同一个对象。如果它们引用同一个对象,则抛出断言FailedError。

代码示例

代码示例来源:origin: junit-team/junit4

/**
 * Asserts that two objects do not refer to the same object. If they do
 * refer to the same object an AssertionFailedError is thrown.
 */
static public void assertNotSame(Object expected, Object actual) {
  assertNotSame(null, expected, actual);
}

代码示例来源:origin: junit-team/junit4

/**
 * Asserts that two objects do not refer to the same object. If they do
 * refer to the same object an AssertionFailedError is thrown.
 */
public static void assertNotSame(Object expected, Object actual) {
  Assert.assertNotSame(expected, actual);
}

代码示例来源:origin: junit-team/junit4

/**
 * Asserts that two objects do not refer to the same object. If they do
 * refer to the same object an AssertionFailedError is thrown with the
 * given message.
 */
public static void assertNotSame(String message, Object expected, Object actual) {
  Assert.assertNotSame(message, expected, actual);
}

代码示例来源:origin: google/j2objc

/**
 * Asserts that two objects do not refer to the same object. If they do
 * refer to the same object an AssertionFailedError is thrown.
 */
static public void assertNotSame(Object expected, Object actual) {
  assertNotSame(null, expected, actual);
}

代码示例来源:origin: google/j2objc

/**
 * Asserts that two objects do not refer to the same object. If they do
 * refer to the same object an AssertionFailedError is thrown with the
 * given message.
 */
@SuppressWarnings("deprecation")
public static void assertNotSame(String message, Object expected, Object actual) {
  Assert.assertNotSame(message, expected, actual);
}

代码示例来源:origin: google/j2objc

/**
 * Asserts that two objects do not refer to the same object. If they do
 * refer to the same object an AssertionFailedError is thrown.
 */
@SuppressWarnings("deprecation")
public static void assertNotSame(Object expected, Object actual) {
  Assert.assertNotSame(expected, actual);
}

代码示例来源:origin: RobotiumTech/robotium

/**
 * Asserts that an expected {@link Activity} is currently active one, with the possibility to
 * verify that the expected {@code Activity} is a new instance of the {@code Activity}.
 * 
 * @param message the message that should be displayed if the assert fails
 * @param expectedClass the {@code Class} object that is expected to be active e.g. {@code MyActivity.class}
 * @param isNewInstance {@code true} if the expected {@code Activity} is a new instance of the {@code Activity}
 */
public void assertCurrentActivity(String message, Class<? extends Activity> expectedClass,
    boolean isNewInstance) {
  boolean found = false;
  assertCurrentActivity(message, expectedClass);
  Activity activity = activityUtils.getCurrentActivity(false);
  if(activity == null){
    Assert.assertNotSame(message, isNewInstance, false);
    return;
  }
  
  for (int i = 0; i < activityUtils.getAllOpenedActivities().size() - 1; i++) {
    String instanceString = activityUtils.getAllOpenedActivities().get(i).toString();
    if (instanceString.equals(activity.toString()))
      found = true;
  }
  Assert.assertNotSame(message, isNewInstance, found);
}

代码示例来源:origin: apache/ignite

@Override public void onAfterRemove(Cache.Entry<TestKey, TestValue> entry) {
    assertNotSame(key, entry.getKey());
    assertNotSame(newTestVal, entry.getValue());
  }
});

代码示例来源:origin: apache/ignite

@Override public IgniteBiTuple onBeforeRemove(Cache.Entry<TestKey, TestValue> entry) {
  assertNotSame(key, entry.getKey());
  assertNotSame(newTestVal, entry.getValue());
  return super.onBeforeRemove(entry);
}

代码示例来源:origin: apache/ignite

@Override public TestValue onBeforePut(Cache.Entry<TestKey, TestValue> entry, TestValue newVal) {
  assertNotSame(key, entry.getKey());
  assertNotSame(val, entry.getValue());
  assertEquals(newTestVal, newVal);
  // Try change value.
  entry.getValue().val(WRONG_VALUE);
  return newVal;
}

代码示例来源:origin: oasisfeng/condom

@Test public void testApplicationAsApplicationContextOfBaseContext() throws Exception {
  final Context context = InstrumentationRegistry.getTargetContext();
  final Context app_context = context.getApplicationContext();
  assertTrue(app_context instanceof Application);
  final CondomContext condom_context = CondomContext.wrap(context, TAG);
  final Context condom_app_context = condom_context.getApplicationContext();
  assertTrue(condom_app_context instanceof Application);
  assertNotSame(app_context, condom_app_context);
  assertTrue(((Application) condom_app_context).getBaseContext() instanceof CondomContext);
}

代码示例来源:origin: google/guava

/**
 * Assuming the given cache has maximum size {@code maxSize}, this method populates the cache (by
 * getting a bunch of different keys), then makes sure all the items in the cache are also in the
 * eviction queue. It will invoke the given {@code operation} on the first element in the eviction
 * queue, and then reverify that all items in the cache are in the eviction queue, and verify that
 * the head of the eviction queue has changed as a result of the operation.
 */
static void checkRecency(
  LoadingCache<Integer, Integer> cache,
  int maxSize,
  Receiver<ReferenceEntry<Integer, Integer>> operation) {
 checkNotNull(operation);
 if (hasLocalCache(cache)) {
  warmUp(cache, 0, 2 * maxSize);
  LocalCache<Integer, Integer> cchm = toLocalCache(cache);
  Segment<?, ?> segment = cchm.segments[0];
  drainRecencyQueue(segment);
  assertEquals(maxSize, accessQueueSize(cache));
  assertEquals(maxSize, cache.size());
  ReferenceEntry<?, ?> originalHead = segment.accessQueue.peek();
  @SuppressWarnings("unchecked")
  ReferenceEntry<Integer, Integer> entry = (ReferenceEntry) originalHead;
  operation.accept(entry);
  drainRecencyQueue(segment);
  assertNotSame(originalHead, segment.accessQueue.peek());
  assertEquals(cache.size(), accessQueueSize(cache));
 }
}

代码示例来源:origin: airbnb/epoxy

Assert.assertNotSame("The inserted model should not exist in the original list",
   oldModel.id(), expected.id());
   .assertNotSame("Incorrectly updated an item.", model.hashCode(), expected.hashCode());
} else {
 assertEquals("Models should have same hashcode when not updated",

代码示例来源:origin: airbnb/epoxy

@Test
public void modelClickListenerOverridesViewClickListener() {
 final ModelWithClickListener_ model = new ModelWithClickListener_();
 TestController controller = new TestController();
 controller.setModel(model);
 ViewClickListener viewClickListener = new ViewClickListener();
 model.clickListener(viewClickListener);
 assertNotNull(model.clickListener());
 ModelClickListener modelClickListener = new ModelClickListener();
 model.clickListener(modelClickListener);
 assertNotSame(model.clickListener(), viewClickListener);
 lifecycleHelper.buildModelsAndBind(controller);
 mockModelForClicking(model);
 assertNotNull(model.clickListener());
 View viewMock = mockModelForClicking(model);
 model.clickListener().onClick(viewMock);
 assertTrue(modelClickListener.clicked);
 assertFalse(viewClickListener.clicked);
}

代码示例来源:origin: apache/incubator-pinot

@Test
public void deleteRealtimeSegmentFromGetAPI()
  throws Exception {
 long currRealtimeRows = numRowsReturned(CommonConstants.Helix.TableType.REALTIME);
 String segmentList = sendGetRequest(_controllerRequestURLBuilder.
   forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.REALTIME.toString()));
 JsonNode realtimeSegmentsList =
   getSegmentsFromJsonSegmentAPI(segmentList, CommonConstants.Helix.TableType.REALTIME.toString());
 String removedSegment = realtimeSegmentsList.get(0).asText();
 long removedSegmentRows = getNumRowsFromRealtimeMetadata(removedSegment);
 Assert.assertNotSame(removedSegmentRows, 0L);
 sendGetRequest(_controllerRequestURLBuilder.
   forDeleteSegmentWithGetAPI(TABLE_NAME, removedSegment, CommonConstants.Helix.TableType.REALTIME.toString()));
 waitForNumRows(currRealtimeRows - removedSegmentRows, CommonConstants.Helix.TableType.REALTIME);
 String postDeleteSegmentList = sendGetRequest(_controllerRequestURLBuilder
   .forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.REALTIME.toString()));
 JsonNode realtimeSegmentsListReturn =
   getSegmentsFromJsonSegmentAPI(postDeleteSegmentList, CommonConstants.Helix.TableType.REALTIME.toString());
 removeValue(realtimeSegmentsList, removedSegment);
 Assert.assertEquals(realtimeSegmentsListReturn, realtimeSegmentsList);
}

代码示例来源:origin: apache/incubator-pinot

@Test
public void deleteRealtimeSegmentFromDeleteAPI()
  throws Exception {
 long currRealtimeRows = numRowsReturned(CommonConstants.Helix.TableType.REALTIME);
 String segmentList = sendGetRequest(_controllerRequestURLBuilder
   .forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.REALTIME.toString()));
 JsonNode realtimeSegmentsList =
   getSegmentsFromJsonSegmentAPI(segmentList, CommonConstants.Helix.TableType.REALTIME.toString());
 String removedSegment = realtimeSegmentsList.get(0).asText();
 long removedSegmentRows = getNumRowsFromRealtimeMetadata(removedSegment);
 Assert.assertNotSame(removedSegmentRows, 0L);
 sendDeleteRequest(_controllerRequestURLBuilder.
   forSegmentDeleteAPI(TABLE_NAME, removedSegment, CommonConstants.Helix.TableType.REALTIME.toString()));
 waitForNumRows(currRealtimeRows - removedSegmentRows, CommonConstants.Helix.TableType.REALTIME);
 String postDeleteSegmentList = sendGetRequest(_controllerRequestURLBuilder
   .forSegmentListAPIWithTableType(TABLE_NAME, CommonConstants.Helix.TableType.REALTIME.toString()));
 JsonNode realtimeSegmentsListReturn =
   getSegmentsFromJsonSegmentAPI(postDeleteSegmentList, CommonConstants.Helix.TableType.REALTIME.toString());
 removeValue(realtimeSegmentsList, removedSegment);
 Assert.assertEquals(realtimeSegmentsListReturn, realtimeSegmentsList);
}

代码示例来源:origin: apache/ignite

@Override public void onAfterPut(Cache.Entry<TestKey, TestValue> entry) {
    assertNotSame(key, entry.getKey());
    assertSame(entry.getValue(), entry.getValue());
    assertSame(entry.getKey(), entry.getKey());
    // Try change value.
    entry.getValue().val(WRONG_VALUE);
  }
});

代码示例来源:origin: apache/ignite

@Override public void onAfterPut(Cache.Entry<TestKey, TestValue> entry) {
    assertNotSame(key, entry.getKey());
    assertSame(entry.getValue(), entry.getValue());
    assertSame(entry.getKey(), entry.getKey());
    // Try change value.
    entry.getValue().val(WRONG_VALUE);
  }
});

代码示例来源:origin: apache/incubator-pinot

Assert.assertNotSame(removedSegmentRows, 0L);

代码示例来源:origin: PipelineAI/pipeline

@Test
public void testMetricsPublisherReset() {
  // precondition: HystrixMetricsPublisherFactory class is not loaded. Calling HystrixPlugins.reset() here should be good enough to run this with other tests.
  // set first custom publisher
  HystrixCommandKey key = HystrixCommandKey.Factory.asKey("key");
  HystrixMetricsPublisherCommand firstCommand = new HystrixMetricsPublisherCommandDefault(key, null, null, null, null);
  HystrixMetricsPublisher firstPublisher = new CustomPublisher(firstCommand);
  HystrixPlugins.getInstance().registerMetricsPublisher(firstPublisher);
  // ensure that first custom publisher is used
  HystrixMetricsPublisherCommand cmd = HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(key, null, null, null, null);
  assertSame(firstCommand, cmd);
  // reset, then change to second custom publisher
  HystrixPlugins.reset();
  HystrixMetricsPublisherCommand secondCommand = new HystrixMetricsPublisherCommandDefault(key, null, null, null, null);
  HystrixMetricsPublisher secondPublisher = new CustomPublisher(secondCommand);
  HystrixPlugins.getInstance().registerMetricsPublisher(secondPublisher);
  // ensure that second custom publisher is used
  cmd = HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(key, null, null, null, null);
  assertNotSame(firstCommand, cmd);
  assertSame(secondCommand, cmd);
}

相关文章