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

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

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

Assert.assertNull介绍

[英]Asserts that an object is null. If it isn't an AssertionError is thrown. Message contains: Expected: but was: object
[中]断言对象为空。如果不是断言,则抛出断言错误。消息包含:应为:但为:对象

代码示例

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

/**
   * Checks correctness of the state after unmarshalling.
   */
  void checkAfterUnmarshalled() {
    assertEquals(shortVal.shortValue(), 0x1122);
    assertEquals(longVal, 0x8877665544332211L);
    assertNull(aArr);
    assertNull(strVal);
    assertEquals(doubleVal, 123.456);
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

void put(FileLruCache cache, String key, byte[] data) {
  try {
    OutputStream stream = cache.openPutStream(key);
    assertNotNull(stream);
    stream.write(data);
    stream.close();
  } catch (IOException e) {
    // Fail test and print Exception
    assertNull(e);
  }
}

代码示例来源:origin: airbnb/lottie-android

@Test
public void testLoadInvalidAssetName() {
 LottieResult<LottieComposition> result = LottieCompositionFactory.fromAssetSync(RuntimeEnvironment.application, "square2.json");
 assertEquals(FileNotFoundException.class, result.getException().getClass());
 assertNull(result.getValue());
}

代码示例来源:origin: facebook/facebook-android-sdk

@Test
  public void testX() throws Exception {
    JSONObject serverResponse = new JSONObject(errorClassificationJSON);
    JSONArray jsonArray = serverResponse.getJSONArray("android_sdk_error_categories");
    FacebookRequestErrorClassification errorClassification =
        FacebookRequestErrorClassification.createFromJSON(jsonArray);
    assertNotNull(errorClassification);
    assertNull(errorClassification.getRecoveryMessage(FacebookRequestError.Category.OTHER));
    assertNull(errorClassification.getRecoveryMessage(FacebookRequestError.Category.TRANSIENT));
    assertNotNull(errorClassification.getRecoveryMessage(
        FacebookRequestError.Category.LOGIN_RECOVERABLE));
    assertEquals(2, errorClassification.getOtherErrors().size());
    assertEquals(2, errorClassification.getLoginRecoverableErrors().size());
    assertEquals(6, errorClassification.getTransientErrors().size());
    // test subcodes
    assertEquals(2, errorClassification.getOtherErrors().get(102).size());
    assertNull(errorClassification.getLoginRecoverableErrors().get(102));
  }
}

代码示例来源:origin: airbnb/lottie-android

@Test
public void testLoadInvalidJsonString() {
 LottieResult<LottieComposition> result = LottieCompositionFactory.fromJsonStringSync(NOT_JSON, "not_json");
 assertNotNull(result.getException());
 assertNull(result.getValue());
}

代码示例来源:origin: Impetus/Kundera

public void deleteCounter()
{
  EntityManager em = emf.createEntityManager();
  Counters counters = new Counters();
  counters = em.find(Counters.class, id3);
  Assert.assertNotNull(counters);
  Assert.assertNotNull(counters.getCounter());
  em.remove(counters);
  EntityManager em1 = emf.createEntityManager();
  counters = em1.find(Counters.class, id3);
  Assert.assertNull(counters);
  em.close();
}

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

@Override
public void serverReceiveRequest(RPCContext context) {
 Map<String,ByteBuffer> meta = context.requestCallMeta();
 Assert.assertNotNull(meta);
 Assert.assertNotNull(context.getMessage());
 Assert.assertNull(context.getResponsePayload());
 if (!meta.containsKey(key)) return;
 ByteBuffer buf = meta.get(key);
 Assert.assertNotNull(buf);
 Assert.assertNotNull(buf.array());
 String partialstr = new String(buf.array());
 Assert.assertNotNull(partialstr);
 Assert.assertEquals("partial string mismatch", "ap", partialstr);
 buf = ByteBuffer.wrap((partialstr + "a").getBytes());
 Assert.assertTrue(buf.remaining() > 0);
 meta.put(key, buf);
}

代码示例来源:origin: Impetus/Kundera

/**
 * Test delete.
 */
private void testDelete()
{
  PersonMTM p1 = em.find(PersonMTM.class, "p1");
  Assert.assertNotNull(p1);
  em.remove(p1);
  PersonMTM p = em.find(PersonMTM.class, "p1");
  Assert.assertNull(p);
}

代码示例来源:origin: Impetus/Kundera

/**
 * Test delete.
 */
private void testDelete()
{
  Metrics m = em.find(Metrics.class, getMetricsId());
  em.remove(m);
  em.clear();
  Metrics m1 = em.find(Metrics.class, getMetricsId());
  Assert.assertNull(m1);
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
  * PDI-6960 - Group by and Memory group by ignores NULL values ("sum" aggregation)
  * 
  * We do not assign 0 instead of null.
  */
 @Test
 public void newAggregateInitializationTest() {
  Object[] r = new Object[18];
  Arrays.fill( r, null );
  step.newAggregate( r );

  Object[] agg = data.agg;

  Assert.assertEquals( "All possible aggregation cases considered", 18, agg.length );

  // all aggregations types is int values, filled in ascending order in perconditions
  for ( int i = 0; i < agg.length; i++ ) {
   int type = i + 1;
   if ( strings.contains( type ) ) {
    Assert.assertTrue( "This is appendable type, type=" + type, agg[i] instanceof Appendable );
   } else if ( statistics.contains( type ) ) {
    Assert.assertTrue( "This is collection, type=" + type, agg[i] instanceof Collection );
   } else {
    Assert.assertNull( "Aggregation initialized with null, type=" + type, agg[i] );
   }
  }
 }
}

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

@Test
public void testMarkCleaned() throws Exception {
 CompactionRequest rqst = new CompactionRequest("foo", "bar", CompactionType.MINOR);
 rqst.setPartitionname("ds=today");
 txnHandler.compact(rqst);
 assertEquals(0, txnHandler.findReadyToClean().size());
 CompactionInfo ci = txnHandler.findNextToCompact("fred");
 assertNotNull(ci);
 assertEquals(0, txnHandler.findReadyToClean().size());
 txnHandler.markCompacted(ci);
 assertNull(txnHandler.findNextToCompact("fred"));
 List<CompactionInfo> toClean = txnHandler.findReadyToClean();
 assertEquals(1, toClean.size());
 assertNull(txnHandler.findNextToCompact("fred"));
 txnHandler.markCleaned(ci);
 assertNull(txnHandler.findNextToCompact("fred"));
 assertEquals(0, txnHandler.findReadyToClean().size());
 ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
 assertEquals(1, rsp.getCompactsSize());
 assertTrue(TxnHandler.SUCCEEDED_RESPONSE.equals(rsp.getCompacts().get(0).getState()));
}

代码示例来源:origin: airbnb/lottie-android

@Test
public void testLoadJsonString() {
 LottieResult<LottieComposition> result = LottieCompositionFactory.fromJsonStringSync(JSON, "json");
 assertNull(result.getException());
 assertNotNull(result.getValue());
}

代码示例来源:origin: Impetus/Kundera

public void testDelete(boolean useSameEm)
{
  EntityManager em = emf.createEntityManager();
  StudentDoublePrimitive studentMax = em.find(StudentDoublePrimitive.class, maxValue);
  Assert.assertNotNull(studentMax);
  Assert.assertEquals(getMaxValue(short.class), studentMax.getAge());
  Assert.assertEquals("Kuldeep", studentMax.getName());
  em.remove(studentMax);
  if (!useSameEm)
  {
    em.close();
    em = emf.createEntityManager();
  }
  studentMax = em.find(StudentDoublePrimitive.class, maxValue);
  Assert.assertNull(studentMax);
  em.close();
}

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

@Override
public void clientFinishConnect(RPCContext context) {
 Map<String,ByteBuffer> handshakeMeta = context.responseHandshakeMeta();
 Assert.assertNull(context.getRequestPayload());
 Assert.assertNull(context.getResponsePayload());
 Assert.assertNotNull(handshakeMeta);
 if (!handshakeMeta.containsKey(key)) return;
 ByteBuffer buf = handshakeMeta.get(key);
 Assert.assertNotNull(buf);
 Assert.assertNotNull(buf.array());
 String partialstr = new String(buf.array());
 Assert.assertNotNull(partialstr);
 Assert.assertEquals("partial string mismatch", "apac", partialstr);
 buf = ByteBuffer.wrap((partialstr + "he").getBytes());
 Assert.assertTrue(buf.remaining() > 0);
 handshakeMeta.put(key, buf);
 checkRPCMetaMap(handshakeMeta);
}

代码示例来源:origin: facebook/facebook-android-sdk

void checkInputStream(byte[] expected, InputStream actual) {
  try {
    for (int i = 0; i < expected.length; i++) {
      int b = actual.read();
      assertEquals(((int)expected[i]) & 0xff, b);
    }
    int eof = actual.read();
    assertEquals(-1, eof);
  } catch (IOException e) {
    // Fail test and print Exception
    assertNull(e);
  }
}

代码示例来源:origin: Impetus/Kundera

/**
 * Test delete.
 */
private void testDelete()
{
  Person p = em.find(Person.class, "101");
  Assert.assertNotNull(p);
  em.remove(p);
  em.clear();
  Person p1 = em.find(Person.class, "101");
  Assert.assertNull(p1);
}

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

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Nullable @Override public Object onGet(Object key, Object val) {
  if (disabled)
    return val;
  assertNotNull(retInterceptor);
  Object ret = retInterceptor.onGet(key, val);
  System.out.println("Get [key=" + key + ", val=" + val + ", ret=" + ret + ']');
  if (val != null) {
    Object old = getMap.put(key, val);
    assertNull(old); // Fot get interceptor is called on near node only.
  }
  invokeCnt.incrementAndGet();
  return ret;
}

代码示例来源:origin: pentaho/pentaho-kettle

@Test
 public void testNewAggregate() throws KettleException {
  Object[] r = new Object[16];
  Arrays.fill( r, null );

  Aggregate agg = new Aggregate();

  step.newAggregate( r, agg );

  Assert.assertEquals( "All possible aggregation cases considered", 16, agg.agg.length );

  // all aggregations types is int values, filled in ascending order in perconditions
  for ( int i = 0; i < agg.agg.length; i++ ) {
   int type = i + 1;
   if ( strings.contains( type ) ) {
    Assert.assertTrue( "This is appendable type, type=" + type, agg.agg[i] instanceof Appendable );
   } else if ( statistics.contains( type ) ) {
    Assert.assertTrue( "This is collection, type=" + type, agg.agg[i] instanceof Collection );
   } else {
    Assert.assertNull( "Aggregation initialized with null, type=" + type, agg.agg[i] );
   }
  }
 }
}

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

@Test
public void testFindNextToClean() throws Exception {
 CompactionRequest rqst = new CompactionRequest("foo", "bar", CompactionType.MINOR);
 rqst.setPartitionname("ds=today");
 txnHandler.compact(rqst);
 assertEquals(0, txnHandler.findReadyToClean().size());
 CompactionInfo ci = txnHandler.findNextToCompact("fred");
 assertNotNull(ci);
 assertEquals(0, txnHandler.findReadyToClean().size());
 txnHandler.markCompacted(ci);
 assertNull(txnHandler.findNextToCompact("fred"));
 List<CompactionInfo> toClean = txnHandler.findReadyToClean();
 assertEquals(1, toClean.size());
 assertNull(txnHandler.findNextToCompact("fred"));
 ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
 List<ShowCompactResponseElement> compacts = rsp.getCompacts();
 assertEquals(1, compacts.size());
 ShowCompactResponseElement c = compacts.get(0);
 assertEquals("foo", c.getDbname());
 assertEquals("bar", c.getTablename());
 assertEquals("ds=today", c.getPartitionname());
 assertEquals(CompactionType.MINOR, c.getType());
 assertEquals("ready for cleaning", c.getState());
 assertNull(c.getWorkerid());
}

代码示例来源:origin: airbnb/lottie-android

@Test
public void testLoadInvalidJsonReader() {
 JsonReader reader = new JsonReader(new StringReader(NOT_JSON));
 LottieResult<LottieComposition> result = LottieCompositionFactory.fromJsonReaderSync(reader, "json");
 assertNotNull(result.getException());
 assertNull(result.getValue());
}

相关文章