本文整理汇总了Java中org.testng.Assert类的典型用法代码示例。如果您正苦于以下问题:Java Assert类的具体用法?Java Assert怎么用?Java Assert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Assert类属于org.testng包,在下文中一共展示了Assert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: system_size
import org.testng.Assert; //导入依赖的package包/类
@Test
public void system_size() throws IOException, CompressorException, ArchiveException
{
ProcessingManager mgr = new ProcessingManager();
long size = mgr.system_size(sample);
Assert.assertEquals(size, 494928);
File folder=sample.getParentFile();
File extaction_folder=new File(folder, "unzip");
extaction_folder.mkdirs();
UnZip.unCompress(sample.getAbsolutePath(),
extaction_folder.getAbsolutePath());
File tocheck = extaction_folder.listFiles()[0];
size = mgr.system_size(tocheck);
Assert.assertEquals(size, SIZE, tocheck.getAbsolutePath());
}
示例2: testOAuthWithTokenLogin
import org.testng.Assert; //导入依赖的package包/类
@Test(enabled = false)
public void testOAuthWithTokenLogin() throws Exception
{
HttpResponse response = defaultClientTokenRequest("token",
TokenSecurity.createSecureToken("AutoTest", "token", "token", null));
String string = EntityUtils.toString(response.getEntity());
Assert.assertTrue(string.contains("oal_allowButton"), "Should be logged in");
response = defaultClientTokenRequestPost("event__", "oal.allowAccess");
Assert.assertTrue(hasAccessToken(response));
// we should be able to make REST calls with this token as the AutoTest
// user
}
示例3: testToFromByteArray
import org.testng.Assert; //导入依赖的package包/类
@Test
public void testToFromByteArray(){
boolean one = true;
boolean two = false;
boolean three = false;
List<Boolean> booleans = new ArrayList<>();
booleans.add(one);
booleans.add(null);
booleans.add(null);
booleans.add(two);
booleans.add(three);
byte[] booleanBytes = getBooleanByteArray(booleans);
List<Boolean> result = fromBooleanByteArray(booleanBytes, 0);
Assert.assertEquals(result, booleans);
}
示例4: successAllTest
import org.testng.Assert; //导入依赖的package包/类
@Test
public void successAllTest() throws IOException {
ReplaceText replaceText = new ReplaceText("foo").setReplacement("zoo").relative("/src/main/resources/application.properties").setFirstOnly(false);
TOExecutionResult executionResult = replaceText.execution(transformedAppFolder, transformationContext);
Assert.assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);
assertChangedFile("/src/main/resources/application.properties");
assertSameLineCount("/src/main/resources/application.properties");
Properties properties = getProperties("/src/main/resources/application.properties");
Assert.assertEquals(properties.size(), 3);
Assert.assertEquals(properties.getProperty("bar"), "barv");
Assert.assertEquals(properties.getProperty("zoo"), "zoov");
Assert.assertEquals(properties.getProperty("zoozoo"), "zoozoov");
}
示例5: testAddElementToGlobalNs
import org.testng.Assert; //导入依赖的package包/类
@Test
public void testAddElementToGlobalNs() throws Exception {
// Create empty SOAP message
SOAPMessage msg = createSoapMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
// Add elements
SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
childGlobalNS.addNamespaceDeclaration("", "");
SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
// Check namespace URIs
Assert.assertNull(childGlobalNS.getNamespaceURI());
Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
示例6: testFactoryFind
import org.testng.Assert; //导入依赖的package包/类
@Test
public void testFactoryFind() throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
Assert.assertTrue(factory.getClass().getClassLoader() == null);
runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(null));
factory = TransformerFactory.newInstance();
Assert.assertTrue(factory.getClass().getClassLoader() == null);
runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(new MyClassLoader()));
factory = TransformerFactory.newInstance();
if (System.getSecurityManager() == null)
Assert.assertTrue(myClassLoaderUsed);
else
Assert.assertFalse(myClassLoaderUsed);
}
示例7: checkLastHandler
import org.testng.Assert; //导入依赖的package包/类
@Test()
static void checkLastHandler() {
if (RUNNING_WITH_Xrs) {
return;
}
Signal signal = new Signal("TERM");
Handler h1 = new Handler();
Handler h2 = new Handler();
SignalHandler orig = Signal.handle(signal, h1);
if (orig == SignalHandler.SIG_IGN) {
// SIG_IGN for TERM means it cannot be handled
return;
}
try {
SignalHandler prev = Signal.handle(signal, h2);
Assert.assertSame(prev, h1, "prev handler mismatch");
prev = Signal.handle(signal, h1);
Assert.assertSame(prev, h2, "prev handler mismatch");
} finally {
if (orig != null && signal != null) {
Signal.handle(signal, orig);
}
}
}
示例8: testSAX
import org.testng.Assert; //导入依赖的package包/类
public void testSAX(boolean setUseCatalog, boolean useCatalog, String catalog,
String xml, MyHandler handler, String expected) throws Exception {
SAXParser parser = getSAXParser(setUseCatalog, useCatalog, catalog);
parser.parse(xml, handler);
Assert.assertEquals(handler.getResult().trim(), expected);
}
示例9: nonStemmedAnalyzeTest
import org.testng.Assert; //导入依赖的package包/类
@Test
public void nonStemmedAnalyzeTest() {
ModelMetadata metadata = ModelMetadata.createDefault().applyStemmer(0);
IndraAnalyzer analyzer = new IndraAnalyzer(LANG, metadata);
String loveString = "love";
List<String> res = analyzer.analyze(loveString);
Assert.assertEquals(res.size(), 1);
Assert.assertEquals(res.get(0), loveString);
loveString = "LOVE";
res = analyzer.analyze(loveString);
Assert.assertEquals(res.size(), 1);
Assert.assertEquals(res.get(0), loveString.toLowerCase());
}
示例10: assertEqualTrees
import org.testng.Assert; //导入依赖的package包/类
/**
* This wrapper method allows for potential post-processing, such as
* removing tags that we don't care to compare in {@code returnedTree}.
*
* @param returnedTree The returned tree from the web service.
* @param expectedTree The simulated tree that we expect.
*/
private void assertEqualTrees(ConsumableTree<TestSpan> returnedTree,
ConsumableTree<TestSpan> expectedTree) {
// It's okay if the returnedTree has tags other than the ones we
// want to compare, so just remove those
returnedTree.visitTree(span -> span.getTags().keySet()
.removeIf(key -> !key.equals(Tags.SPAN_KIND.getKey())
&& !key.equals(Tags.HTTP_METHOD.getKey())
&& !key.equals(Tags.HTTP_URL.getKey())
&& !key.equals(Tags.HTTP_STATUS.getKey())
&& !key.equals(TestServerWebServices.LOCAL_SPAN_TAG_KEY)));
// It's okay if the returnedTree has log entries other than the ones we
// want to compare, so just remove those
returnedTree.visitTree(span -> span.getLogEntries()
.removeIf(logEntry -> true));
Assert.assertEquals(returnedTree, expectedTree);
}
示例11: testBoolean
import org.testng.Assert; //导入依赖的package包/类
@Test
public void testBoolean(){
ManyFieldBean bean = new ManyFieldBean();
//test true value
bean.setBooleanField(true);
mapNode.put(bean, null);
ManyFieldBean roundTripped = mapNode.get(bean.getKey(), null);
Assert.assertNotSame(roundTripped, bean);
Assert.assertEquals(roundTripped.getBooleanField(), bean.getBooleanField());
//test false value
bean.setBooleanField(false);
mapNode.put(bean, null);
ManyFieldBean roundTrippedFalse = mapNode.get(bean.getKey(), null);
Assert.assertNotSame(roundTrippedFalse, bean);
Assert.assertEquals(roundTrippedFalse.getBooleanField(), bean.getBooleanField());
}
示例12: testCreateByIterable4
import org.testng.Assert; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test(dataProvider = "arrays")
public <T> void testCreateByIterable4(Array<T> array) {
final List<T> list = array.stream().values().collect(Collectors.toList());
final Index<T> index1 = Index.of((Iterable)list);
final Index<T> index2 = Index.of((Collection)list);
Assert.assertEquals(index1.size(), list.size(), "Size matches array length");
Assert.assertEquals(index2.size(), list.size(), "Size matches array length");
for (int i=0; i<index1.size(); ++i) {
final T key = index1.getKey(i);
Assert.assertEquals(key, list.get(i), "Key matches array value at " + i);
Assert.assertEquals(index1.getIndexForKey(key), i, "Index matches for ordinal " + i);
Assert.assertEquals(index1.getOrdinalForKey(key), i, "Ordinals match");
Assert.assertEquals(index1.getIndexForOrdinal(i), i, "Ordinal and index match");
Assert.assertEquals(index2.getIndexForKey(key), index1.getIndexForKey(key), "Index matches for ordinal " + i);
Assert.assertEquals(index2.getOrdinalForKey(key), index1.getOrdinalForKey(key), "Ordinals match");
Assert.assertEquals(index2.getIndexForOrdinal(i), index1.getIndexForOrdinal(i), "Ordinal and index match");
}
}
示例13: testPOSTResourcesMissingIdentifier
import org.testng.Assert; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPOSTResourcesMissingIdentifier() throws Exception {
List<BaseResource> resources = JSON_UTILS
.deserializeFromFile("controller-test/missing-identifier-resources-collection.json", List.class);
Assert.assertNotNull(resources);
// Append a list of resources
MockMvcContext postContext =
TEST_UTILS.createWACWithCustomPOSTRequestBuilder(this.wac, this.testZone.getSubdomain(), RESOURCE_BASE_URL);
postContext.getMockMvc()
.perform(postContext.getBuilder().contentType(MediaType.APPLICATION_JSON)
.content(OBJECT_MAPPER.writeValueAsString(resources)))
.andExpect(status().isUnprocessableEntity());
}
示例14: testRepairNotification
import org.testng.Assert; //导入依赖的package包/类
@Test
public void testRepairNotification(){
Notifications noti = new Notifications();
noti.setAntennaClient(antennaClientMock);
noti.setCmProcessor(cmProcessorMock);
noti.setEnvProcessor(envProcessorMock);
EventUtil eventUtil = new EventUtil();
eventUtil.setGson(new Gson());
noti.setEventUtil(eventUtil);
CiChangeStateEvent event = getCiChangeEvent(UNHEALTHY, NOTIFY, OPEN, NEW);
OpsBaseEvent opsEvent = eventUtil.getOpsEvent(event);
NotificationMessage message = noti.sendRepairNotification(event, null);
String subject = message.getSubject();
String text = message.getText();
Assert.assertEquals(subject, getSubjPrefix()+opsEvent.getName()+SUBJECT_SUFFIX_OPEN_EVENT);
Assert.assertEquals(text, CI_NAME +" is in "+event.getNewState()+" state"+TEXT_NOTE_SEPERATOR+Notifications.REPAIR_IN_PROGRESS);
Assert.assertEquals(message.getSource(),"ops");
Assert.assertEquals(message.getPayload().get(Notifications.CLASS_NAME),MOCK_CI_CLASS_NAME);
Assert.assertEquals(message.getPayload().get(Notifications.OLD_STATE),NOTIFY);
Assert.assertEquals(message.getPayload().get(Notifications.NEW_STATE),UNHEALTHY);
Assert.assertEquals(message.getPayload().get(Notifications.STATUS),NEW);
Assert.assertEquals(message.getPayload().get(Notifications.STATE),OPEN);
Assert.assertEquals(message.getSeverity(), NotificationSeverity.warning);
}
示例15: testLowerAndHigherValueOnSortedStringArray
import org.testng.Assert; //导入依赖的package包/类
@Test()
public void testLowerAndHigherValueOnSortedStringArray() {
final Array<String> array = Array.of("a", "c", "e", "g", "i", "k", "m", "o", "q", "s", "u", "w", "y");
Assert.assertEquals(array.previous("e").map(ArrayValue::getValue).get(), "c", "Lower value than e");
Assert.assertEquals(array.previous("g").map(ArrayValue::getValue).get(), "e", "Lower value than g");
Assert.assertEquals(array.previous("i").map(ArrayValue::getValue).get(), "g", "Lower value than i");
Assert.assertEquals(array.previous("q").map(ArrayValue::getValue).get(), "o", "Lower value than q");
Assert.assertEquals(array.previous("b").map(ArrayValue::getValue).get(), "a", "Lower value than e");
Assert.assertEquals(array.previous("f").map(ArrayValue::getValue).get(), "e", "Lower value than g");
Assert.assertEquals(array.previous("h").map(ArrayValue::getValue).get(), "g", "Lower value than i");
Assert.assertEquals(array.previous("p").map(ArrayValue::getValue).get(), "o", "Lower value than q");
Assert.assertEquals(array.next("e").map(ArrayValue::getValue).get(), "g", "Lower value than e");
Assert.assertEquals(array.next("g").map(ArrayValue::getValue).get(), "i", "Lower value than g");
Assert.assertEquals(array.next("i").map(ArrayValue::getValue).get(), "k", "Lower value than i");
Assert.assertEquals(array.next("q").map(ArrayValue::getValue).get(), "s", "Lower value than q");
Assert.assertEquals(array.next("b").map(ArrayValue::getValue).get(), "c", "Lower value than e");
Assert.assertEquals(array.next("f").map(ArrayValue::getValue).get(), "g", "Lower value than g");
Assert.assertEquals(array.next("h").map(ArrayValue::getValue).get(), "i", "Lower value than i");
Assert.assertEquals(array.next("p").map(ArrayValue::getValue).get(), "q", "Lower value than q");
}