Java Code Examples for junit.framework.Assert.assertNotNull()

The following are Jave code examples for showing how to use assertNotNull() of the junit.framework.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: incubator-netbeans   File: ExecutionCompatibilityTest.java   View Source Code Vote up 6 votes
/** Executes the execution compatibility kit tests on the provided instance
 * of execution engine.
 */
public static Test suite(ExecutionEngine engine) {
    System.setProperty("org.openide.util.Lookup", ExecutionCompatibilityTest.class.getName() + "$Lkp");
    Object o = Lookup.getDefault();
    if (!(o instanceof Lkp)) {
        Assert.fail("Wrong lookup object: " + o);
    }
    
    Lkp l = (Lkp)o;
    l.assignExecutionEngine(engine);
    
    if (engine != null) {
        Assert.assertEquals("Same engine found", engine, ExecutionEngine.getDefault());
    } else {
        o = ExecutionEngine.getDefault();
        Assert.assertNotNull("Engine found", o);
        Assert.assertEquals(ExecutionEngine.Trivial.class, o.getClass());
    }
    
    TestSuite ts = new TestSuite();
    ts.addTestSuite(ExecutionEngineHid.class);
    
    return ts;
}
 
Example 2
Project: incubator-netbeans   File: PerfCountingSecurityManager.java   View Source Code Vote up 6 votes
static void initWrites() throws IOException {
    Set<String> allowedFiles = new HashSet<String>();
    InputStream is = PerfCountingSecurityManager.class.getResourceAsStream("allowed-file-writes.txt");
    Assert.assertNotNull("file found", is);
    BufferedReader r = new BufferedReader(new InputStreamReader(is));
    for (;;) {
        String line = r.readLine();
        if (line == null) {
            break;
        }
        if (line.startsWith("#")) {
            continue;
        }
        allowedFiles.add(line);
    }
    PerfCountingSecurityManager.initialize(null, PerfCountingSecurityManager.Mode.CHECK_WRITE, allowedFiles);
}
 
Example 3
Project: flume-release-1.7.0   File: TestLog4jAppender.java   View Source Code Vote up 6 votes
@Test
public void testLog4jAppender() throws IOException {
  configureSource();
  PropertyConfigurator.configure(props);
  Logger logger = LogManager.getLogger(TestLog4jAppender.class);
  for (int count = 0; count <= 1000; count++) {
    /*
     * Log4j internally defines levels as multiples of 10000. So if we
     * create levels directly using count, the level will be set as the
     * default.
     */
    int level = ((count % 5) + 1) * 10000;
    String msg = "This is log message number" + String.valueOf(count);

    logger.log(Level.toLevel(level), msg);
    Transaction transaction = ch.getTransaction();
    transaction.begin();
    Event event = ch.take();
    Assert.assertNotNull(event);
    Assert.assertEquals(new String(event.getBody(), "UTF8"), msg);

    Map<String, String> hdrs = event.getHeaders();

    Assert.assertNotNull(hdrs.get(Log4jAvroHeaders.TIMESTAMP.toString()));

    Assert.assertEquals(Level.toLevel(level),
        Level.toLevel(Integer.valueOf(hdrs.get(Log4jAvroHeaders.LOG_LEVEL
            .toString()))
        ));

    Assert.assertEquals(logger.getName(),
        hdrs.get(Log4jAvroHeaders.LOGGER_NAME.toString()));

    Assert.assertEquals("UTF8",
        hdrs.get(Log4jAvroHeaders.MESSAGE_ENCODING.toString()));
    transaction.commit();
    transaction.close();
  }

}
 
Example 4
Project: flume-release-1.7.0   File: TestReplicatingChannelSelector.java   View Source Code Vote up 6 votes
@Test
public void testMultipleOptionalChannels() throws Exception {
  Context context = new Context();
  context.put(ReplicatingChannelSelector.CONFIG_OPTIONAL, "ch1 ch4");
  Configurables.configure(selector, context);
  List<Channel> channels = selector.getRequiredChannels(new MockEvent());
  Assert.assertNotNull(channels);
  Assert.assertEquals(2, channels.size());
  Assert.assertEquals("ch2", channels.get(0).getName());
  Assert.assertEquals("ch3", channels.get(1).getName());

  List<Channel> optCh = selector.getOptionalChannels(new MockEvent());
  Assert.assertEquals(2, optCh.size());
  Assert.assertEquals("ch1", optCh.get(0).getName());
  Assert.assertEquals("ch4", optCh.get(1).getName());
}
 
Example 5
Project: xitk   File: ConfPairsTest.java   View Source Code Vote up 5 votes
private static void check(ConfPairs confPairs, String expEncoded,
        Map<String, String> expNameValues) {
    String isEncoded = confPairs.getEncoded();
    Assert.assertEquals("encoded", expEncoded, isEncoded);

    Set<String> isNames = confPairs.names();
    Assert.assertEquals("names", expNameValues.size(), isNames.size());

    for (String isName : isNames) {
        String expValue = expNameValues.get(isName);
        Assert.assertNotNull("name " + isName + " is not expected", expValue);
        Assert.assertEquals("value of name " + isName, expValue, confPairs.value(isName));
    }
}
 
Example 6
Project: sjk   File: AppMapperTest.java   View Source Code Vote up 5 votes
@Test
public void testget() {
    int id = 1;
    App app = null;
    while (true) {
        app = appMapper.get(id);
        id++;
        if (app != null) {
            break;
        }
    }
    Assert.assertNotNull(app.getId());
}
 
Example 7
Project: redirector   File: FileSystemBackupFilesTest.java   View Source Code Vote up 5 votes
@Test
@UseDataProvider("data")
public void testWithoutNamespacedListsFile(IBackupManagerFactory.BackupEntity entity, String expectedFilename) throws Exception {
    String result = testee.getFilename(entity);
    Assert.assertNotNull(result);
    Assert.assertEquals(basePath + File.separator + appName + File.separator + expectedFilename, result);
}
 
Example 8
Project: Runnest   File: TrackTest.java   View Source Code Vote up 5 votes
@Test
public void correctConstructionFromACheckPoint() {
    Track testTrack = new Track(buildCheckPoint(50, 50));

    Assert.assertEquals(0, testTrack.getDistance(), 0);
    Assert.assertEquals(1, testTrack.getTotalCheckPoints(), 0);
    Assert.assertNotNull(testTrack.getCheckpoints());
    Assert.assertEquals(50, testTrack.getLastPoint().getLatitude(), 0);
    Assert.assertEquals(50, testTrack.getLastPoint().getLongitude(), 0);
}
 
Example 9
Project: ZooKeeper   File: SessionTrackerTest.java   View Source Code Vote up 5 votes
/**
 * Verify the create session call in the Leader.FinalRequestProcessor after
 * the session expiration.
 */
@Test(timeout = 20000)
public void testAddSessionAfterSessionExpiry() throws Exception {
    ZooKeeperServer zks = setupSessionTracker();

    latch = new CountDownLatch(1);
    zks.sessionTracker.addSession(sessionId, sessionTimeout);
    SessionTrackerImpl sessionTrackerImpl = (SessionTrackerImpl) zks.sessionTracker;
    SessionImpl sessionImpl = sessionTrackerImpl.sessionsById
            .get(sessionId);
    Assert.assertNotNull("Sessionid:" + sessionId
            + " doesn't exists in sessiontracker", sessionImpl);

    // verify the session existence
    Object sessionOwner = new Object();
    sessionTrackerImpl.checkSession(sessionId, sessionOwner);

    // waiting for the session expiry
    latch.await(sessionTimeout * 2, TimeUnit.MILLISECONDS);

    // Simulating FinalRequestProcessor logic: create session request has
    // delayed and now reaches FinalRequestProcessor. Here the leader zk
    // will do sessionTracker.addSession(id, timeout)
    sessionTrackerImpl.addSession(sessionId, sessionTimeout);
    try {
        sessionTrackerImpl.checkSession(sessionId, sessionOwner);
        Assert.fail("Should throw session expiry exception "
                + "as the session has expired and closed");
    } catch (KeeperException.SessionExpiredException e) {
        // expected behaviour
    }
    Assert.assertTrue("Session didn't expired", sessionImpl.isClosing());
    Assert.assertFalse("Session didn't expired", sessionTrackerImpl
            .touchSession(sessionId, sessionTimeout));
    Assert.assertEquals(
            "Duplicate session expiry request has been generated", 1,
            firstProcessor.getCountOfCloseSessionReq());
}
 
Example 10
Project: sjk   File: AppMapperTest.java   View Source Code Vote up 5 votes
@Test
public void testgetLatestDate() {
    Boolean noAds = true;
    Boolean official = false;
    List<LatestDate> list = appMapper.getLatestDate(noAds, official);
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
}
 
Example 11
Project: Alerter   File: AlertTest.java   View Source Code Vote up 5 votes
@Test
public void testBackgroundColour() {
    alert.setAlertBackgroundColor(ContextCompat.getColor(activityRule.getActivity(), android.R.color.darker_gray));

    Assert.assertNotNull(alert.getAlertBackground().getBackground());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        Assert.assertEquals(((ColorDrawable) alert.getAlertBackground().getBackground()).getColor(), ContextCompat.getColor(activityRule.getActivity(), android.R.color.darker_gray));
    }
}
 
Example 12
Project: flume-release-1.7.0   File: TestTransactionEventRecordV3.java   View Source Code Vote up 5 votes
@Test
public void testPutSerializationNullHeader() throws IOException, CorruptEventException {
  Put in = new Put(System.currentTimeMillis(),
      WriteOrderOracle.next(),
      new FlumeEvent(null, new byte[0]));
  Put out = (Put)TransactionEventRecord.fromByteArray(toByteArray(in));
  Assert.assertEquals(in.getClass(), out.getClass());
  Assert.assertEquals(in.getRecordType(), out.getRecordType());
  Assert.assertEquals(in.getTransactionID(), out.getTransactionID());
  Assert.assertEquals(in.getLogWriteOrderID(), out.getLogWriteOrderID());
  Assert.assertNull(in.getEvent().getHeaders());
  Assert.assertNotNull(out.getEvent().getHeaders());
  Assert.assertTrue(Arrays.equals(in.getEvent().getBody(), out.getEvent().getBody()));
}
 
Example 13
Project: date-helper   File: DateConvertUtilTest.java   View Source Code Vote up 5 votes
public void testConvertAsLocalDate() {
	//Datum ohne Zeit
	LocalDate nowAsLocalDate = DateConvertUtils.asLocalDate(DateHelper.stripTime(now));
	Date convertedBack = DateConvertUtils.asUtilDate(nowAsLocalDate);

	Calendar cal1 = Calendar.getInstance();
	Calendar cal2 = Calendar.getInstance();
	cal1.setTime(now);
	Assert.assertNotNull(convertedBack);
	cal2.setTime(convertedBack);
	boolean sameDay = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
		cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
	Assert.assertTrue(sameDay);

}
 
Example 14
Project: mycat-src-1.6.1-RELEASE   File: DruidMysqlRouteStrategyTest.java   View Source Code Vote up 4 votes
public NodeNameAsserter(String... expectNames) {
    Assert.assertNotNull(expectNames);
    this.expectNames = expectNames;
}
 
Example 15
Project: sjk   File: BaseTest.java   View Source Code Vote up 4 votes
@Before
public void init() {
    Assert.assertNotNull(appConfig);
    logger.info("Test bootstrap OK!");
}
 
Example 16
Project: fuck_zookeeper   File: NettyServerCnxnTest.java   View Source Code Vote up 4 votes
/**
 * Test verifies the channel closure - while closing the channel
 * servercnxnfactory should remove all channel references to avoid
 * duplicate channel closure. Duplicate closure may result in 
 * indefinite hanging due to netty open issue.
 * 
 * @see <a href="https://issues.jboss.org/browse/NETTY-412">NETTY-412</a>
 */
@Test(timeout = 30000)
public void testSendCloseSession() throws Exception {
    Assert.assertTrue(
            "Didn't instantiate ServerCnxnFactory with NettyServerCnxnFactory!",
            serverFactory instanceof NettyServerCnxnFactory);

    NettyServerCnxnFactory nettyServerFactory = (NettyServerCnxnFactory) serverFactory;
    final CountDownLatch channelLatch = new CountDownLatch(1);
    CnxnChannelHandler channelHandler = nettyServerFactory.new CnxnChannelHandler() {
        @Override
        public void channelDisconnected(ChannelHandlerContext ctx,
                ChannelStateEvent e) throws Exception {
            LOG.info("Recieves channel disconnected event");
            channelLatch.countDown();
        }
    };
    LOG.info("Adding custom channel handler for simulation");
    nettyServerFactory.bootstrap.getPipeline().remove("servercnxnfactory");
    nettyServerFactory.bootstrap.getPipeline().addLast("servercnxnfactory",
            channelHandler);

    final ZooKeeper zk = createClient();
    final String path = "/a";
    try {
        // make sure zkclient works
        zk.create(path, "test".getBytes(), Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
        Assert.assertNotNull("Didn't create znode:" + path,
                zk.exists(path, false));
        Iterable<ServerCnxn> connections = serverFactory.getConnections();
        Assert.assertEquals("Mismatch in number of live connections!", 1,
                serverFactory.getNumAliveConnections());
        for (ServerCnxn serverCnxn : connections) {
            serverCnxn.sendCloseSession();
        }
        LOG.info("Waiting for the channel disconnected event");
        channelLatch.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
        Assert.assertEquals("Mismatch in number of live connections!", 0,
                serverFactory.getNumAliveConnections());
    } finally {
        zk.close();
    }
}
 
Example 17
Project: GitHub   File: BackstackActivityWithChildFragmentsTest.java   View Source Code Vote up 4 votes
@Ignore("We trust that FragmentManager implementation runs as expected")
@Test public void fragmentsOnBackstack() throws Exception {
  // Context of the app under test.
  BackstackActivityWithChildFragments activity = rule.getActivity();
  Thread.sleep(1000);

  FragmentOnBackstack fragmentOnBackstack;
  ChildFragmentOnBackstack childFragmentOnBackstack;
  ChildChildFragmentOnBackstack childChildFragmentOnBackstack;

  SimpleFragmentNotOnBackstack simpleFragmentNotOnBackstack;
  SimpleChildFragmentNotOnBackstack simpleChildFragmentNotOnBackstack;
  SimpleChildChildFragmentNotOnBackstack simpleChildChildFragmentNotOnBackstack;

  fragmentOnBackstack = activity.getFragmentOnBackstack();
  Assert.assertNotNull(fragmentOnBackstack);
  childFragmentOnBackstack = fragmentOnBackstack.getChilFragment();
  Assert.assertNotNull(childFragmentOnBackstack);
  childChildFragmentOnBackstack = childFragmentOnBackstack.getChildFragment();
  Assert.assertNotNull(childChildFragmentOnBackstack);

  simpleFragmentNotOnBackstack = activity.getFragmentNotOnBackstack();
  Assert.assertNotNull(simpleFragmentNotOnBackstack);
  simpleChildFragmentNotOnBackstack = simpleFragmentNotOnBackstack.getChilFragment();
  Assert.assertNotNull(simpleChildFragmentNotOnBackstack);
  simpleChildChildFragmentNotOnBackstack = simpleChildFragmentNotOnBackstack.getChildFragment();
  Assert.assertNotNull(simpleChildChildFragmentNotOnBackstack);

  Thread.sleep(1000);
  //
  // Screen orientation change
  //
  activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  // Will call onStop() where we set the onbackStack flag
  Thread.sleep(1000);

  Assert.assertTrue(fragmentOnBackstack.onBackStack);
  Assert.assertTrue(childFragmentOnBackstack.onBackStack);
  Assert.assertTrue(childChildFragmentOnBackstack.onBackStack);

  Assert.assertFalse(simpleFragmentNotOnBackstack.onBackStack);
  Assert.assertFalse(simpleChildFragmentNotOnBackstack.onBackStack);
  Assert.assertFalse(simpleChildChildFragmentNotOnBackstack.onBackStack);
}
 
Example 18
Project: sjk   File: CatalogMapperTest.java   View Source Code Vote up 4 votes
@Test
public void testlistCatalogInfoNoParameters() {
    List<CatalogInfo> list = catalogMapper.listCatalogInfo();
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
}
 
Example 19
Project: IPCInvoker   File: Singleton.java   View Source Code Vote up 4 votes
public Singleton(@NonNull Class<T> clazz) {
    Assert.assertNotNull(clazz);
    this.targetClass = clazz;
}
 
Example 20
Project: sjk   File: BaseTest.java   View Source Code Vote up 4 votes
@Before
public void init() {
    Assert.assertNotNull(appConfig);
    System.out.println("Test bootstrap OK!");

}