Java Code Examples for junit.framework.Assert#assertTrue()

The following examples show how to use junit.framework.Assert#assertTrue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBagOfWordsEditDistance.java    From ensemble-clustering with MIT License 6 votes vote down vote up
@Test
public void testDistance5() {
	BagOfWordsFeature t1 = new BagOfWordsFeature();
	t1.incrementValue("cats");
	t1.incrementValue("felines");
	t1.incrementValue("tigers");
	
	BagOfWordsFeature t2 = new BagOfWordsFeature();
	t2.incrementValue("dogs");
	t2.incrementValue("canines");
	
	EditDistance d = new EditDistance();
	double distance = d.aveMinDistance(Collections.singletonList(t1), Collections.singletonList(t2));
	System.out.println(distance);
	Assert.assertTrue(isEqual(distance, 0.555556));  //0.5714 + 0.4286 + 0.666667 / 3
}
 
Example 2
Source File: SingleDBLifeCycleTest.java    From Zebra with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiRouterResult15() throws Exception {
	DataSource ds = (DataSource) context.getBean("zebraDS");
	Connection conn = null;
	try {
		conn = ds.getConnection();
		Statement stmt = conn.createStatement();
		stmt.execute("select distinct score from test order by score asc limit 16,3");
		ResultSet rs = stmt.getResultSet();
		while (rs.next()) {
			Assert.fail();
		}
		Assert.assertTrue(true);
	} catch (Exception e) {
		Assert.fail();
	} finally {
		if (conn != null) {
			conn.close();
		}
	}
}
 
Example 3
Source File: SybaseBcpTest.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private void assertEndBits()
{
    BcpEndBits happy = BcpEndBitsFinder.findOneBypassCache(BcpEndBitsFinder.name().eq("Happy"));
    Assert.assertFalse(happy.isDopey());
    Assert.assertTrue(happy.isHappy());

    BcpEndBits dopey = BcpEndBitsFinder.findOneBypassCache(BcpEndBitsFinder.name().eq("Dopey"));
    Assert.assertTrue(dopey.isDopey());
    Assert.assertFalse(dopey.isHappy());

    BcpEndBits snowWhite = BcpEndBitsFinder.findOneBypassCache(BcpEndBitsFinder.id().eq(100));
    Assert.assertTrue(snowWhite.isDopey());
    Assert.assertFalse(snowWhite.isHappy());

    final BcpEndBitsList list = new BcpEndBitsList(BcpEndBitsFinder.all());
    list.setBypassCache(true);
    Assert.assertEquals(7, list.size());

    BcpEndBits evilQueen = BcpEndBitsFinder.findOneBypassCache(BcpEndBitsFinder.id().eq(101));
    Assert.assertFalse(evilQueen.isDopey());
    Assert.assertFalse(evilQueen.isHappy());
}
 
Example 4
Source File: BackwardRegisterTrackingTransformationProviderTest.java    From binnavi with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransformBsh() {
  final RegisterTrackingTransformationProvider transformationProvider =
      new RegisterTrackingTransformationProvider(new RegisterTrackingOptions(false,
          new TreeSet<String>(), false, AnalysisDirection.UP));
  final ReilInstruction instruction =
      ReilHelpers.createBsh(0, OperandSize.DWORD, "eax", OperandSize.DWORD, "ebx",
          OperandSize.DWORD, "ecx");
  final Pair<RegisterSetLatticeElement, RegisterSetLatticeElement> transformationResult =
      transformationProvider.transformBsh(instruction, createTaintedState("ecx"));
  Assert.assertFalse(transformationResult.first().getTaintedRegisters().contains("ecx"));
  Assert.assertTrue(transformationResult.first().getTaintedRegisters().contains("eax"));
  Assert.assertTrue(transformationResult.first().getTaintedRegisters().contains("ebx"));

  transformationResult.first().onInstructionExit();

  Assert.assertTrue(transformationResult.first().getReadRegisters().contains("ecx"));
  Assert.assertTrue(transformationResult.first().getNewlyTaintedRegisters().contains("eax"));
  Assert.assertTrue(transformationResult.first().getNewlyTaintedRegisters().contains("ebx"));
  Assert.assertTrue(transformationResult.first().getUpdatedRegisters().isEmpty());
  Assert.assertTrue(transformationResult.first().getUntaintedRegisters().contains("ecx"));
}
 
Example 5
Source File: ESBJAVA4423CustomStatusDescriptionTest.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb", description = "Test custom status description", enabled = true)
public void testCustomStatusDescription() {
    String expectedResponse = "HTTP/1.1 417 Custom response\r\nServer: testServer\r\n" +
            "Content-Type: text/xml; charset=UTF-8\r\n" +
            "Transfer-Encoding: chunked\r\n" +
            "\r\n" + "\"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<test></test>";
    //start socket server
    simpleSocketServer = new SimpleSocketServer(5389, expectedResponse);
    simpleSocketServer.start();

    try {
        //this will spawn an exception with the custom response included
        axis2Client.sendSimpleStockQuoteRequest(getProxyServiceURLHttp("ESBJAVA4423HttpCustomProxyTest"), "", "IBM");
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("Custom response"));
    }
}
 
Example 6
Source File: MockClusterInvokerTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@Test
public void testMockInvokerFromOverride_Invoke_force_throwCustemExceptionNotFound(){
	URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
			.addParameter("getBoolean2.mock","force:throw java.lang.RuntimeException2")
			.addParameter("invoke_return_error", "true" );
	Invoker<IHelloService> cluster = getClusterInvoker(url);        
	//方法配置了mock
       RpcInvocation invocation = new RpcInvocation();
	invocation.setMethodName("getBoolean2");
	try {
		cluster.invoke(invocation);
		Assert.fail();
	} catch (Exception e) {
		Assert.assertTrue(e.getCause() instanceof IllegalStateException);
	}
}
 
Example 7
Source File: TestJobConf.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
public void testProfileParamsDefaults() {
  JobConf configuration = new JobConf();

  Assert.assertNull(configuration.get("mapred.task.profile.params"));

  String result = configuration.getProfileParams();

  Assert.assertNotNull(result);
  Assert.assertTrue(result.contains("file=%s"));
  Assert.assertTrue(result.startsWith("-agentlib:hprof"));
}
 
Example 8
Source File: CellTimestampComparatorTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Test_greater.
 */
@Test
public void test_greater() {
  // mocking
  Cell cell1 = Mockito.mock(Cell.class);
  Mockito.when(cell1.getTimestamp()).thenReturn(13745345808L);
  Cell cell2 = Mockito.mock(Cell.class);
  Mockito.when(cell2.getTimestamp()).thenReturn(13945345808L);

  CellTimestampComparator comparator = new CellTimestampComparator();

  // actual call and verify
  Assert.assertTrue(comparator.compare(cell2, cell1) == 1);

}
 
Example 9
Source File: Merovingian2Test.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
@Test
public void testLockAndRelease() {

    s_logger.info("Testing first acquire");
    boolean result = _lockMaster.acquire("first" + 1234, 5);
    Assert.assertTrue(result);

    s_logger.info("Testing acquire of different lock");
    result = _lockMaster.acquire("second" + 1234, 5);
    Assert.assertTrue(result);

    s_logger.info("Testing reacquire of the same lock");
    result = _lockMaster.acquire("first" + 1234, 5);
    Assert.assertTrue(result);

    int count = _lockMaster.owns("first" + 1234);
    Assert.assertEquals(count, 2);

    count = _lockMaster.owns("second" + 1234);
    Assert.assertEquals(count, 1);

    s_logger.info("Testing release of the first lock");
    result = _lockMaster.release("first" + 1234);
    Assert.assertTrue(result);

    count = _lockMaster.owns("first" + 1234);
    Assert.assertEquals(count, 1);

    s_logger.info("Testing release of the second lock");
    result = _lockMaster.release("second" + 1234);
    Assert.assertTrue(result);

    result = _lockMaster.release("first" + 1234);
    Assert.assertTrue(result);
}
 
Example 10
Source File: TestDatasetDescriptor.java    From kite with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmbeddedPartitionStrategy() {
  Schema schema = new Schema.Parser().parse("{" +
      "  \"type\": \"record\"," +
      "  \"name\": \"User\"," +
      "  \"partitions\": [" +
      "    {\"type\": \"hash\", \"source\": \"username\", \"buckets\": 16}," +
      "    {\"type\": \"identity\", \"source\": \"username\", \"name\": \"u\"}" +
      "  ]," +
      "  \"fields\": [" +
      "    {\"name\": \"id\", \"type\": \"long\"}," +
      "    {\"name\": \"username\", \"type\": \"string\"}," +
      "    {\"name\": \"real_name\", \"type\": \"string\"}" +
      "  ]" +
      "}");

  DatasetDescriptor descriptor = new DatasetDescriptor.Builder()
      .schema(schema)
      .build();
  Assert.assertTrue("Descriptor should have partition strategy",
      descriptor.isPartitioned());

  PartitionStrategy expected = new PartitionStrategy.Builder()
      .hash("username", 16)
      .identity("username", "u")
      .build();
  Assert.assertEquals(expected, descriptor.getPartitionStrategy());

  // check that strategies set on the builder override those in the schema
  expected = new PartitionStrategy.Builder()
      .identity("real_name", "n")
      .build();
  DatasetDescriptor override = new DatasetDescriptor.Builder()
      .schema(schema)
      .partitionStrategy(expected)
      .build();
  Assert.assertEquals(expected, override.getPartitionStrategy());
}
 
Example 11
Source File: WorkingWeekTest.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
public void testIsWorkingDayFromCalendar() {
    final WorkingWeek ww = new WorkingWeek();
    Assert.assertTrue("Calendar.MONDAY", ww.isWorkingDayFromCalendar(Calendar.MONDAY));
    Assert.assertTrue("Calendar.TUESDAY", ww.isWorkingDayFromCalendar(Calendar.TUESDAY));
    Assert.assertTrue("Calendar.WEDNESDAY", ww.isWorkingDayFromCalendar(Calendar.WEDNESDAY));
    Assert.assertTrue("Calendar.THURSDAY", ww.isWorkingDayFromCalendar(Calendar.THURSDAY));
    Assert.assertTrue("Calendar.FRIDAY", ww.isWorkingDayFromCalendar(Calendar.FRIDAY));
    Assert.assertFalse("Calendar.SATURDAY", ww.isWorkingDayFromCalendar(Calendar.SATURDAY));
    Assert.assertFalse("Calendar.SUNDAY", ww.isWorkingDayFromCalendar(Calendar.SUNDAY));
}
 
Example 12
Source File: DeerletRedisClientStringTest.java    From deerlet-redis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetex() throws InterruptedException {
	Assert.assertTrue(deerletRedisClient.setex("testKey", 3, "testValue"));
	Assert.assertTrue(deerletRedisClient.exists("testKey"));
	Thread.sleep(3000);
	Assert.assertFalse(deerletRedisClient.exists("testKey"));
}
 
Example 13
Source File: ComplexIDLGenerateTest.java    From jprotobuf with Apache License 2.0 5 votes vote down vote up
@Test
public void testProtobufIDLGeneratorGetIDLTypesReturns() {
    
    final Set<Class<?>> cachedTypes = new HashSet<Class<?>>();
    final Set<Class<?>> cachedEnumTypes = new HashSet<Class<?>>();
    
    String code = ProtobufIDLGenerator.getIDL(EmptyClass.class, cachedTypes, cachedEnumTypes);
    Assert.assertTrue(code.indexOf("message") !=  -1);
    
    Assert.assertEquals(1, cachedTypes.size());
    Assert.assertEquals(0, cachedEnumTypes.size());
    code = ProtobufIDLGenerator.getIDL(EmptyClass.class, cachedTypes, cachedEnumTypes);
    Assert.assertNull(code);
}
 
Example 14
Source File: GroupMembersMethods.java    From YiBo with Apache License 2.0 5 votes vote down vote up
@Test
public void addGroupMember() {
	try {
		Paging<User> paging = new Paging<User>();
		paging.moveToFirst();
		List<User> users = weibo.getFriends(paging);
		Group userList = weibo.createGroupMember(testGroup.getId(), users.get(0).getUserId());
		Assert.assertTrue(userList != null);
	} catch (Exception e) {
		e.printStackTrace();
		Assert.assertTrue(false);
	}
}
 
Example 15
Source File: TestKafkaPolicyNegative.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
@Test
public void testauthorizedKafkaInPolicyFile() throws Exception {
  append("[groups]", globalPolicyFile);
  append("other_group = other_role", globalPolicyFile);
  append("[roles]", globalPolicyFile);
  append("other_role = host=host1->topic=t1->action=read, host=host1->consumergroup=l1->action=read", globalPolicyFile);
  PolicyEngine policy = new KafkaPolicyFileProviderBackend(globalPolicyFile.getPath());
  //malicious_group has no privilege
  ImmutableSet<String> permissions = policy.getAllPrivileges(Sets.newHashSet("malicious_group"), ActiveRoleSet.ALL);
  Assert.assertTrue(permissions.toString(), permissions.isEmpty());
  //other_group has two privileges
  permissions = policy.getAllPrivileges(Sets.newHashSet("other_group"), ActiveRoleSet.ALL);
  Assert.assertTrue(permissions.toString(), permissions.size() == 2);
}
 
Example 16
Source File: EdOrgOwnershipArbiterTest.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testEdOrgReferenceEntities() {
    securityContextInjector.setEducatorContext();

 Entity edorg = createEntity(EntityNames.SCHOOL, "edorg1", new HashMap<String, Object>());
 Mockito.when(repo.findAll(Mockito.eq(EntityNames.EDUCATION_ORGANIZATION), argThat(new BaseMatcher<NeutralQuery>() {

     @Override
     public boolean matches(Object item) {
         NeutralQuery matching =  new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, "edorg1"));
         NeutralQuery other = (NeutralQuery) item;
         return matching.getCriteria().equals(other.getCriteria());
     }

     @Override
     public void describeTo(Description description) {
         // TODO Auto-generated method stub

     }
 }))).thenReturn(Arrays.asList(edorg));
 Map<String, Object> attendanceBody = new HashMap<String, Object>();
 attendanceBody.put(ParameterConstants.SCHOOL_ID, "edorg1");
 Entity attendance = createEntity(EntityNames.ATTENDANCE, "attendance1", attendanceBody);

 Set<String> edorgIds = arbiter.determineEdorgs(Arrays.asList(attendance), EntityNames.ATTENDANCE);

 Assert.assertEquals(1, edorgIds.size());
 Assert.assertTrue(edorgIds.contains("edorg1"));

}
 
Example 17
Source File: TestHelper.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
public static void verifyServiceStats(ServiceStats stats) {
	Assert.assertNotNull(stats);
	if (stats.getGeoReplication().getLastSyncTime() != null) {
		Assert.assertEquals(GeoReplicationStatus.LIVE, stats.getGeoReplication().getStatus());
	}
	else {
		Assert.assertTrue(stats.getGeoReplication().getStatus() == GeoReplicationStatus.BOOTSTRAP
				|| stats.getGeoReplication().getStatus() == GeoReplicationStatus.UNAVAILABLE);
	}
}
 
Example 18
Source File: CassandraModelTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void test_getColumnFamily_RetrievesNumericCF_ForNullMetadata() {
    RollupType nullType = null;
    MetricColumnFamily cf = CassandraModel.getColumnFamily(nullType, Granularity.FULL);
    Assert.assertTrue(cf != null);
    Assert.assertTrue(cf.getName().equals(CassandraModel.CF_METRICS_FULL.getName()));

    cf = CassandraModel.getColumnFamily(nullType, Granularity.MIN_5);
    Assert.assertTrue(cf != null);
    Assert.assertTrue(cf.getName().equals(CassandraModel.CF_METRICS_5M.getName()));

    cf = CassandraModel.getColumnFamily(nullType, Granularity.MIN_20);
    Assert.assertTrue(cf != null);
    Assert.assertTrue(cf.getName().equals(CassandraModel.CF_METRICS_20M.getName()));

    cf = CassandraModel.getColumnFamily(nullType, Granularity.MIN_60);
    Assert.assertTrue(cf != null);
    Assert.assertTrue(cf.getName().equals(CassandraModel.CF_METRICS_60M.getName()));

    cf = CassandraModel.getColumnFamily(nullType, Granularity.MIN_240);
    Assert.assertTrue(cf != null);
    Assert.assertTrue(cf.getName().equals(CassandraModel.CF_METRICS_240M.getName()));

    cf = CassandraModel.getColumnFamily(nullType, Granularity.MIN_1440);
    Assert.assertTrue(cf != null);
    Assert.assertTrue(cf.getName().equals(CassandraModel.CF_METRICS_1440M.getName()));
}
 
Example 19
Source File: ForumRTFFormatterTest.java    From olat with Apache License 2.0 4 votes vote down vote up
@Test
public void testListsWithDollarSign() throws Exception {
    Assert.assertTrue(convert("<ol> <li>$</li> </ol>").contains("$"));
}
 
Example 20
Source File: TestBase.java    From natasha with MIT License 2 votes vote down vote up
/**
 * Short for Assert.assertTrue
 *
 * @param condition
 */
protected void at(String msg, boolean condition) {
    Assert.assertTrue(msg, condition);
}