当前位置: 首页>>代码示例>>Java>>正文


Java Assert类代码示例

本文整理汇总了Java中junit.framework.Assert的典型用法代码示例。如果您正苦于以下问题:Java Assert类的具体用法?Java Assert怎么用?Java Assert使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Assert类属于junit.framework包,在下文中一共展示了Assert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testResetBadgeCount_shouldMakeRequest_viaRestClient

import junit.framework.Assert; //导入依赖的package包/类
@Test
public void testResetBadgeCount_shouldMakeRequest_viaRestClient() {
    RequestModel expected = createRequestModel("https://me-inbox.eservice.emarsys.net/api/reset-badge-count", RequestMethod.POST);

    RestClient mockRestClient = mock(RestClient.class);
    inbox.client = mockRestClient;

    inbox.setAppLoginParameters(appLoginParameters_withCredentials);
    inbox.resetBadgeCount(resetListenerMock);

    ArgumentCaptor<RequestModel> requestCaptor = ArgumentCaptor.forClass(RequestModel.class);
    verify(mockRestClient).execute(requestCaptor.capture(), any(CoreCompletionHandler.class));

    RequestModel requestModel = requestCaptor.getValue();
    Assert.assertNotNull(requestModel.getId());
    Assert.assertNotNull(requestModel.getTimestamp());
    Assert.assertEquals(expected.getUrl(), requestModel.getUrl());
    Assert.assertEquals(expected.getHeaders(), requestModel.getHeaders());
    Assert.assertEquals(expected.getMethod(), requestModel.getMethod());
}
 
开发者ID:emartech,项目名称:android-mobile-engage-sdk,代码行数:21,代码来源:InboxInternalTest.java

示例2: testSpecialCharDDL

import junit.framework.Assert; //导入依赖的package包/类
@Test
public void testSpecialCharDDL() throws Exception {
    SchemaConfig schema = schemaMap.get("TESTDB");
    CacheService cacheService = new CacheService(false);
    RouteService routerService = new RouteService(cacheService);

    // alter table test
    String sql = " ALTER TABLE COMPANY\r\nADD COLUMN TEST  VARCHAR(255) NULL AFTER CREATE_DATE,\r\n CHARACTER SET = UTF8";
    sql = RouterUtil.getFixedSql(sql);
    List<String> dataNodes = new ArrayList<>();
    String tablename = "COMPANY";
    Map<String, TableConfig> tables = schema.getTables();
    TableConfig tc;
    if (tables != null && (tc = tables.get(tablename)) != null) {
        dataNodes = tc.getDataNodes();
    }
    int nodeSize = dataNodes.size();

    int rs = ServerParse.parse(sql);
    int sqlType = rs & 0xff;
    RouteResultset rrs = routerService.route(schema, sqlType, sql, null);
    Assert.assertTrue("COMPANY".equals(tablename));
    Assert.assertTrue(rrs.getNodes().length == nodeSize);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:25,代码来源:DDLRouteTest.java

示例3: testMockInvokerInvoke_forcemock_defaultreturn

import junit.framework.Assert; //导入依赖的package包/类
@Test
public void testMockInvokerInvoke_forcemock_defaultreturn() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
    url = url.addParameter(Constants.MOCK_KEY, "force");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
            + "?getSomething.mock=return aa&getSomething3xx.mock=return xx&sayHello.mock=return ")
            .addParameters(url.getParameters());

    Protocol protocol = new MockProtocol();
    Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
    invokers.add(mInvoker1);

    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals(null, ret.getValue());
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:19,代码来源:MockClusterInvokerTest.java

示例4: test_getAdaptiveExtension_inject

import junit.framework.Assert; //导入依赖的package包/类
@Test
public void test_getAdaptiveExtension_inject() throws Exception {
    LogUtil.start();
    Ext6 ext = ExtensionLoader.getExtensionLoader(Ext6.class).getAdaptiveExtension();

    URL url = new URL("p1", "1.2.3.4", 1010, "path1");
    url = url.addParameters("ext6", "impl1");
    
    assertEquals("Ext6Impl1-echo-Ext1Impl1-echo", ext.echo(url, "ha"));
    
    Assert.assertTrue("can not find error.", LogUtil.checkNoError());
    LogUtil.stop();
    
    url = url.addParameters("simple.ext", "impl2");
    assertEquals("Ext6Impl1-echo-Ext1Impl2-echo", ext.echo(url, "ha"));
    
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:18,代码来源:ExtensionLoader_Adaptive_Test.java

示例5: testNofityOverrideUrls_Clean1

import junit.framework.Assert; //导入依赖的package包/类
/**
 * 测试清除override规则,同时下发清除规则和其他override规则
 * 测试是否能够恢复到推送时的providerUrl
 */
@Test
public void testNofityOverrideUrls_Clean1(){
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));
    registryDirectory.notify(durls);
    
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1000"));
    registryDirectory.notify(durls);
    
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
    durls.add(URL.valueOf("override://0.0.0.0"));
    registryDirectory.notify(durls);
    
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    //需要恢复到最初的providerUrl
    Assert.assertEquals("1",aInvoker.getUrl().getParameter("timeout"));
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:28,代码来源:RegistryDirectoryTest.java

示例6: generateData

import junit.framework.Assert; //导入依赖的package包/类
private static void generateData(File file, Charset charset,
    int numLines, int lineLen) throws IOException {

  OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
  StringBuilder junk = new StringBuilder();
  for (int x = 0; x < lineLen - 13; x++) {
    junk.append('x');
  }
  String payload = junk.toString();
  StringBuilder builder = new StringBuilder();
  for (int i = 0; i < numLines; i++) {
    builder.append(String.format("%010d: %s\n", i, payload));
    if (i % 1000 == 0 && i != 0) {
      out.write(builder.toString().getBytes(charset));
      builder.setLength(0);
    }
  }

  out.write(builder.toString().getBytes(charset));
  out.close();

  Assert.assertEquals(lineLen * numLines, file.length());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:24,代码来源:TestResettableFileInputStream.java

示例7: assertSrcCounterState

import junit.framework.Assert; //导入依赖的package包/类
private void assertSrcCounterState(ObjectName on, long eventReceivedCount,
    long eventAcceptedCount, long appendReceivedCount,
    long appendAcceptedCount, long appendBatchReceivedCount,
    long appendBatchAcceptedCount) throws Exception {
  Assert.assertEquals("SrcEventReceived",
      getSrcEventReceivedCount(on),
      eventReceivedCount);
  Assert.assertEquals("SrcEventAccepted",
      getSrcEventAcceptedCount(on),
      eventAcceptedCount);
  Assert.assertEquals("SrcAppendReceived",
      getSrcAppendReceivedCount(on),
      appendReceivedCount);
  Assert.assertEquals("SrcAppendAccepted",
      getSrcAppendAcceptedCount(on),
      appendAcceptedCount);
  Assert.assertEquals("SrcAppendBatchReceived",
      getSrcAppendBatchReceivedCount(on),
      appendBatchReceivedCount);
  Assert.assertEquals("SrcAppendBatchAccepted",
      getSrcAppendBatchAcceptedCount(on),
      appendBatchAcceptedCount);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:24,代码来源:TestMonitoredCounterGroup.java

示例8: testSaveWithConstructors

import junit.framework.Assert; //导入依赖的package包/类
public void testSaveWithConstructors() {
	Computer computer = new Computer("asus", 699.00);
	assertTrue(computer.save());
	Assert.assertTrue(isDataExists(getTableName(computer), computer.getId()));
	Computer c = getComputer(computer.getId());
	assertEquals("asus", c.getBrand());
	assertEquals(699.00, c.getPrice());
	Computer cc = DataSupport.find(Computer.class, computer.getId());
	assertEquals("asus", cc.getBrand());
	assertEquals(699.00, cc.getPrice());
	Product p = new Product(null);
	p.setBrand("apple");
	p.setPrice(1222.33);
	p.save();
	Product.find(Product.class, p.getId());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:SaveTest.java

示例9: testGenericFilter

import junit.framework.Assert; //导入依赖的package包/类
@Test
public void testGenericFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("$invoke", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "xxx", new String[] {}, new Object[] {} } );
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("xxx", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:22,代码来源:MonitorFilterTest.java

示例10: addListener

import junit.framework.Assert; //导入依赖的package包/类
@Override
public boolean addListener(final String eventId, final IDownloadListener listener) {
    if (FileDownloadLog.NEED_LOG) {
        FileDownloadLog.v(this, "setListener %s", eventId);
    }
    Assert.assertNotNull("EventPoolImpl.add", listener);

    LinkedList<IDownloadListener> container = listenersMap.get(eventId);

    if (container == null) {
        synchronized (eventId.intern()) {
            container = listenersMap.get(eventId);
            if (container == null) {
                listenersMap.put(eventId, container = new LinkedList<>());
            }
        }
    }


    synchronized (eventId.intern()) {
        return container.add(listener);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:DownloadEventPoolImpl.java

示例11: compareSkipLine

import junit.framework.Assert; //导入依赖的package包/类
/**
 * Compares the two given texts after removing the given line from both texts.
 *
 * @param expectedText
 * @param actualText
 * @param lineNumber to remove from both texts before comparing them. The first line is 1.
 * @throws IOException
 */
public static void compareSkipLine(String expectedText, String actualText, int lineNumber) throws IOException {
	//remove line.
	actualText = removeLine(actualText, lineNumber);
	if (actualText.isEmpty()) {
		Assert.fail("Actual text is empty after removing line " + lineNumber + ". Nothing to compare.");
	}

	expectedText = removeLine(expectedText, lineNumber);
	if (expectedText.isEmpty()) {
		Assert.fail("Expected text is empty after removing line " + lineNumber + ". Nothing to compare.");
	}

	Assert.assertEquals("Actual text does not equal expected text after removing line " + lineNumber + " from both texts.",
			expectedText, actualText);
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:24,代码来源:OpenDaTestSupport.java

示例12: run

import junit.framework.Assert; //导入依赖的package包/类
public void run() {
    if (check()) {
        return;
    }

    long timeout = mTimeout;
    while (timeout > 0) {
        try {
            Thread.sleep(TIME_SLICE);
        } catch (InterruptedException e) {
            Assert.fail("unexpected InterruptedException");
        }

        if (check()) {
            return;
        }

        timeout -= TIME_SLICE;
    }

    Assert.fail("unexpected timeout");
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:23,代码来源:PollingCheck.java

示例13: cropAndRescaleBitmap

import junit.framework.Assert; //导入依赖的package包/类
public static void cropAndRescaleBitmap(final Bitmap src, final Bitmap dst, int sensorOrientation) {
    Assert.assertEquals(dst.getWidth(), dst.getHeight());
    final float minDim = Math.min(src.getWidth(), src.getHeight());

    final Matrix matrix = new Matrix();

    // We only want the center square out of the original rectangle.
    final float translateX = -Math.max(0, (src.getWidth() - minDim) / 2);
    final float translateY = -Math.max(0, (src.getHeight() - minDim) / 2);
    matrix.preTranslate(translateX, translateY);

    final float scaleFactor = dst.getHeight() / minDim;
    matrix.postScale(scaleFactor, scaleFactor);

    // Rotate around the center if necessary.
    if (sensorOrientation != 0) {
        matrix.postTranslate(-dst.getWidth() / 2.0f, -dst.getHeight() / 2.0f);
        matrix.postRotate(sensorOrientation);
        matrix.postTranslate(dst.getWidth() / 2.0f, dst.getHeight() / 2.0f);
    }

    final Canvas canvas = new Canvas(dst);
    canvas.drawBitmap(src, matrix, null);
}
 
开发者ID:androidthings,项目名称:sample-tensorflow-imageclassifier,代码行数:25,代码来源:Helper.java

示例14: testBatchEventsWithoutMatTotalEvents

import junit.framework.Assert; //导入依赖的package包/类
@Test
public void testBatchEventsWithoutMatTotalEvents() throws InterruptedException,
    EventDeliveryException {
  StressSource source = new StressSource();
  source.setChannelProcessor(mockProcessor);
  Context context = new Context();
  context.put("batchSize", "10");
  source.configure(context);
  source.start();

  for (int i = 0; i < 10; i++) {
    Assert.assertFalse("StressSource with no maxTotalEvents should not return " +
        Status.BACKOFF, source.process() == Status.BACKOFF);
  }
  verify(mockProcessor,
      times(10)).processEventBatch(getLastProcessedEventList(source));

  long successfulEvents = getCounterGroup(source).get("events.successful");
  TestCase.assertTrue("Number of successful events should be 100 but was " +
      successfulEvents, successfulEvents == 100);

  long failedEvents = getCounterGroup(source).get("events.failed");
  TestCase.assertTrue("Number of failure events should be 0 but was " +
      failedEvents, failedEvents == 0);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:26,代码来源:TestStressSource.java

示例15: changeMap

import junit.framework.Assert; //导入依赖的package包/类
private void changeMap(IUT2004Server server, String map) {
   	if (awaitAgentUp((AbstractAgent)server)) {
   		System.out.println("Changing map to '" + map + "'...");
   		Future<Boolean> future = server.setGameMap(map);
   		try {
   			System.out.println("Waiting for the GB2004 to change the map (60sec timeout).");
   			Boolean result = future.get(60000, TimeUnit.MILLISECONDS);
       		if (result == null || !result) {
       			Assert.fail("Failed to change map to '" + map + "'.");
       		}
   		} catch (Exception e) {
   			Assert.fail("Failed to change map to '" + map + "'.");
   		}
   	} else {
   		Assert.fail("Failed to connect to GB2004...");
   	}
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:18,代码来源:UT2004Test08_UT2004Server_SetGameMap_AgentKeepAlive.java


注:本文中的junit.framework.Assert类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。