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

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

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

Assert.assertSame介绍

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

代码示例

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

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

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

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

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

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

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

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

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

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

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

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

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

/**
 * Verify that the listener completes in a reasonable amount of time, and Asserts that the future
 * throws an {@code ExecutableException} and that the cause of the {@code ExecutableException} is
 * {@code expectedCause}.
 */
public void assertException(Throwable expectedCause) throws Exception {
 // Verify that the listener executed in a reasonable amount of time.
 Assert.assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS));
 try {
  future.get();
  Assert.fail("This call was supposed to throw an ExecutionException");
 } catch (ExecutionException expected) {
  Assert.assertSame(expectedCause, expected.getCause());
 }
}

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

/**
 * Causes this thread to call the named void method, and asserts that the call returns normally.
 */
public void callAndAssertReturns(String methodName, Object... arguments) throws Exception {
 checkNotNull(methodName);
 checkNotNull(arguments);
 sendRequest(methodName, arguments);
 assertSame(null, getResponse(methodName).getResult());
}

代码示例来源:origin: commons-collections/commons-collections

public void testGetKeysArrayConstructorCloned() {
  Object[] keys = new Object[] {ONE, TWO};
  MultiKey mk = new MultiKey(keys, true);
  Object[] array = mk.getKeys();
  Assert.assertTrue(array != keys);
  Assert.assertTrue(Arrays.equals(array, keys));
  Assert.assertSame(ONE, array[0]);
  Assert.assertSame(TWO, array[1]);
  Assert.assertEquals(2, array.length);
}

代码示例来源:origin: commons-collections/commons-collections

public void testGetKeysArrayConstructorNonCloned() {
  Object[] keys = new Object[] {ONE, TWO};
  MultiKey mk = new MultiKey(keys, false);
  Object[] array = mk.getKeys();
  Assert.assertTrue(array != keys);  // still not equal
  Assert.assertTrue(Arrays.equals(array, keys));
  Assert.assertSame(ONE, array[0]);
  Assert.assertSame(TWO, array[1]);
  Assert.assertEquals(2, array.length);
}

代码示例来源:origin: commons-collections/commons-collections

public void testGetKeysSimpleConstructor() {
  MultiKey mk = new MultiKey(ONE, TWO);
  Object[] array = mk.getKeys();
  Assert.assertSame(ONE, array[0]);
  Assert.assertSame(TWO, array[1]);
  Assert.assertEquals(2, array.length);
}

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

public void testExceptionConversion() {
  Exception ex1 = createException();
  ex1.initCause(createSimpleCause());
  Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1));
  Assert.assertSame(RuntimeException.class, ex.getClass());
  Assert.assertEquals("exception1", ex.getMessage());
  Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass());
  Assert.assertEquals("exception2", ex.getCause().getMessage());
 }
};

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

static void checkEviction(LocalCache<?, ?> map) {
 if (map.evictsBySize()) {
  for (Segment<?, ?> segment : map.segments) {
   drainRecencyQueue(segment);
   assertEquals(0, segment.recencyQueue.size());
   assertEquals(0, segment.readCount.get());
   ReferenceEntry<?, ?> prev = null;
   for (ReferenceEntry<?, ?> current : segment.accessQueue) {
    if (prev != null) {
     assertSame(prev, current.getPreviousInAccessQueue());
     assertSame(prev.getNextInAccessQueue(), current);
    }
    Object key = current.getKey();
    if (key != null) {
     assertSame(current, segment.getEntry(key, current.getHash()));
    }
    prev = current;
   }
  }
 } else {
  for (Segment<?, ?> segment : map.segments) {
   assertEquals(0, segment.recencyQueue.size());
  }
 }
}

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

static void checkValidState(LocalCache<?, ?> cchm) {
 for (Segment<?, ?> segment : cchm.segments) {
  segment.cleanUp();
  assertFalse(segment.isLocked());
  Map<?, ?> table = segmentTable(segment);
  // cleanup and then check count after we have a strong reference to all entries
  segment.cleanUp();
  // under high memory pressure keys/values may be nulled out but not yet enqueued
  assertThat(table.size()).isAtMost(segment.count);
  for (Entry<?, ?> entry : table.entrySet()) {
   assertNotNull(entry.getKey());
   assertNotNull(entry.getValue());
   assertSame(entry.getValue(), cchm.get(entry.getKey()));
  }
 }
 checkEviction(cchm);
 checkExpiration(cchm);
}

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

assertTrue(entries.add(current));
if (prev != null) {
 assertSame(prev, current.getPreviousInWriteQueue());
 assertSame(prev.getNextInWriteQueue(), current);
 assertThat(prev.getWriteTime()).isAtMost(current.getWriteTime());
 assertSame(current, segment.getEntry(key, current.getHash()));
assertTrue(entries.add(current));
if (prev != null) {
 assertSame(prev, current.getPreviousInAccessQueue());
 assertSame(prev.getNextInAccessQueue(), current);
 assertSame(current, segment.getEntry(key, current.getHash()));

代码示例来源:origin: k9mail/k-9

@Test
public void getFolder_calledTwice_shouldReturnFirstInstance() {
  String folderName = "Trash";
  Folder webDavFolder = webDavStore.getFolder(folderName);
  Folder result = webDavStore.getFolder(folderName);
  assertSame(webDavFolder, result);
}

代码示例来源:origin: commons-collections/commons-collections

public void testGetIndexed() {
  MultiKey mk = new MultiKey(ONE, TWO);
  Assert.assertSame(ONE, mk.getKey(0));
  Assert.assertSame(TWO, mk.getKey(1));
  try {
    mk.getKey(-1);
    fail();
  } catch (IndexOutOfBoundsException ex) {}
  try {
    mk.getKey(2);
    fail();
  } catch (IndexOutOfBoundsException ex) {}
}

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

@Override
public void run() {
 assertSame(this, Thread.currentThread());
 try {
  while (true) {
   Request request = requestQueue.take();
   Object result;
   try {
    result = invokeMethod(request.methodName, request.arguments);
   } catch (ThreadDeath death) {
    return;
   } catch (InvocationTargetException exception) {
    responseQueue.put(new Response(request.methodName, null, exception.getTargetException()));
    continue;
   } catch (Throwable throwable) {
    responseQueue.put(new Response(request.methodName, null, throwable));
    continue;
   }
   responseQueue.put(new Response(request.methodName, result, null));
  }
 } catch (ThreadDeath death) {
  return;
 } catch (InterruptedException ignored) {
  // SynchronousQueue sometimes throws InterruptedException while the threads are stopping.
 } catch (Throwable uncaught) {
  this.uncaughtThrowable = uncaught;
 }
}

代码示例来源: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);
  }
});

相关文章