本文整理汇总了Java中jdk.testlibrary.Asserts类的典型用法代码示例。如果您正苦于以下问题:Java Asserts类的具体用法?Java Asserts怎么用?Java Asserts使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Asserts类属于jdk.testlibrary包,在下文中一共展示了Asserts类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: assertReturn
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public void assertReturn(Object returned, Object arg0, Object arg1,
int catchDrops, Object... args) {
int lag = 0;
if (throwMode == ThrowMode.CAUGHT) {
lag = 1;
}
Helper.assertCalled(lag, callName(), arg0, arg1);
if (throwMode == ThrowMode.NOTHING) {
assertEQ(cast.apply(arg0), returned);
} else if (throwMode == ThrowMode.CAUGHT) {
List<Object> catchArgs = new ArrayList<>(Arrays.asList(args));
// catcher receives an initial subsequence of target arguments:
catchArgs.subList(args.length - catchDrops, args.length).clear();
// catcher also receives the exception, prepended:
catchArgs.add(0, thrown);
Helper.assertCalled("catcher", catchArgs);
assertEQ(cast.apply(catchArgs), returned);
}
Asserts.assertEQ(0, fakeIdentityCount);
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:CatchExceptionTest.java
示例2: generateCombinations
import jdk.testlibrary.Asserts; //导入依赖的package包/类
/**
* Generate all possible combinations of {@link JpsArg}
* (31 argument combinations and no arguments case)
*/
public static List<List<JpsArg>> generateCombinations() {
final int argCount = JpsArg.values().length;
// If there are more than 30 args this algorithm will overflow.
Asserts.assertLessThan(argCount, 31, "Too many args");
List<List<JpsArg>> combinations = new ArrayList<>();
int combinationCount = (int) Math.pow(2, argCount);
for (int currCombo = 0; currCombo < combinationCount; ++currCombo) {
List<JpsArg> combination = new ArrayList<>();
for (int position = 0; position < argCount; ++position) {
int bit = 1 << position;
if ((bit & currCombo) != 0) {
combination.add(JpsArg.values()[position]);
}
}
combinations.add(combination);
}
return combinations;
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:JpsHelper.java
示例3: testGeneric
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void testGeneric() throws Exception {
Field f = GetAnnotatedOwnerType.class.getField("genericField");
// make sure inner is correctly annotated
AnnotatedType inner = f.getAnnotatedType();
Asserts.assertEquals(inner.getAnnotation(TB.class).value(), "generic");
Asserts.assertTrue(inner.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ inner.getAnnotations().length);
// make sure owner is correctly annotated, on the correct type
AnnotatedType outer = inner.getAnnotatedOwnerType();
Asserts.assertEquals(outer.getType(), ((ParameterizedType) f.getGenericType()).getOwnerType());
Asserts.assertEquals(outer.getAnnotation(TA.class).value(), "generic");
Asserts.assertTrue(outer.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ outer.getAnnotations().length);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:GetAnnotatedOwnerType.java
示例4: testRaw
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void testRaw() throws Exception {
Field f = GetAnnotatedOwnerType.class.getField("rawField");
// make sure inner is correctly annotated
AnnotatedType inner = f.getAnnotatedType();
Asserts.assertEquals(inner.getAnnotation(TB.class).value(), "raw");
Asserts.assertTrue(inner.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ inner.getAnnotations().length);
// make sure owner is correctly annotated, on the correct type
AnnotatedType outer = inner.getAnnotatedOwnerType();
Asserts.assertEquals(outer.getType(), ((Class<?>)f.getGenericType()).getEnclosingClass());
Asserts.assertEquals(outer.getAnnotation(TA.class).value(), "raw");
Asserts.assertTrue(outer.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ outer.getAnnotations().length);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:GetAnnotatedOwnerType.java
示例5: testNonGeneric
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void testNonGeneric() throws Exception {
Field f = GetAnnotatedOwnerType.class.getField("nonGeneric");
// make sure inner is correctly annotated
AnnotatedType inner = f.getAnnotatedType();
Asserts.assertEquals(inner.getAnnotation(TB.class).value(), "non-generic");
Asserts.assertTrue(inner.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ inner.getAnnotations().length);
// make sure owner is correctly annotated, on the correct type
AnnotatedType outer = inner.getAnnotatedOwnerType();
Asserts.assertEquals(outer.getType(), ((Class<?>)f.getGenericType()).getEnclosingClass());
Asserts.assertEquals(outer.getAnnotation(TA.class).value(), "non-generic");
Asserts.assertTrue(outer.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ outer.getAnnotations().length);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:GetAnnotatedOwnerType.java
示例6: testInnerGeneric
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void testInnerGeneric() throws Exception {
Field f = GetAnnotatedOwnerType.class.getField("innerGeneric");
// make sure inner is correctly annotated
AnnotatedType inner = f.getAnnotatedType();
Asserts.assertEquals(inner.getAnnotation(TB.class).value(), "generic");
Asserts.assertTrue(inner.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ inner.getAnnotations().length);
// make sure owner is correctly annotated, on the correct type
AnnotatedType outer = inner.getAnnotatedOwnerType();
Asserts.assertEquals(outer.getType(), ((ParameterizedType) f.getGenericType()).getOwnerType());
Asserts.assertEquals(outer.getAnnotation(TA.class).value(), "non-generic");
Asserts.assertTrue(outer.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ outer.getAnnotations().length);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:GetAnnotatedOwnerType.java
示例7: testInnerRaw
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void testInnerRaw() throws Exception {
Field f = GetAnnotatedOwnerType.class.getField("innerRaw");
// make sure inner is correctly annotated
AnnotatedType inner = f.getAnnotatedType();
Asserts.assertEquals(inner.getAnnotation(TB.class).value(), "raw");
Asserts.assertTrue(inner.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ inner.getAnnotations().length);
// make sure owner is correctly annotated, on the correct type
AnnotatedType outer = inner.getAnnotatedOwnerType();
Asserts.assertEquals(outer.getType(), ((Class<?>)f.getGenericType()).getEnclosingClass());
Asserts.assertEquals(outer.getAnnotation(TA.class).value(), "non-generic");
Asserts.assertTrue(outer.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ outer.getAnnotations().length);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:GetAnnotatedOwnerType.java
示例8: testTypeArgument
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void testTypeArgument() throws Exception {
AnnotatedType tt = GetAnnotatedOwnerType.class.getField("typeArgument").getAnnotatedType();
Asserts.assertEquals(tt.getAnnotation(TA.class).value(), "bad");
Asserts.assertTrue(tt.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ tt.getAnnotations().length);
// make sure inner is correctly annotated
AnnotatedType inner = ((AnnotatedParameterizedType)tt).getAnnotatedActualTypeArguments()[0];
Asserts.assertEquals(inner.getAnnotation(TB.class).value(), "tb");
Asserts.assertTrue(inner.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ inner.getAnnotations().length);
// make sure owner is correctly annotated
AnnotatedType outer = inner.getAnnotatedOwnerType();
Asserts.assertEquals(outer.getAnnotation(TA.class).value(), "good");
Asserts.assertTrue(outer.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ outer.getAnnotations().length);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:GetAnnotatedOwnerType.java
示例9: testIndex
import jdk.testlibrary.Asserts; //导入依赖的package包/类
@Override
void testIndex(int cpi, Object reference) {
String[] natInfo = CP.getNameAndTypeRefInfoAt(cpi);
String msg = String.format("Method getNameAndTypeRefInfoAt"
+ " works not as expected at CP entry #%d:"
+ " returned value should not be null", cpi);
Asserts.assertNotNull(natInfo, msg);
String[] castedReference = (String[]) reference;
int natInfoLength = natInfo.length;
msg = String.format("Method getNameAndTypeRefInfoAt"
+ " works not as expected at CP entry #%d:"
+ " length of the returned string array is %d, but should be 2",
cpi, natInfoLength);
Asserts.assertEquals(natInfoLength, 2, msg);
String[] nameOrType = new String[]{"name", "type"};
for (int i = 0; i < 2; i++) {
String infoToVerify = natInfo[i];
String infoToRefer = castedReference[i];
msg = String.format("Method getNameAndTypeRefInfoAt"
+ " works not as expected at CP entry #%d:"
+ " got %s info %s, but should be %s",
cpi, nameOrType[i], infoToVerify, infoToRefer);
Asserts.assertEquals(infoToVerify, infoToRefer, msg);
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ConstantPoolTest.java
示例10: main
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
MessageDigest md;
// Test vectors obtained from
// http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_224.pdf
md = MessageDigest.getInstance("SHA-512/224");
Asserts.assertTrue(Arrays.equals(md.digest("abc".getBytes()),
xeh("4634270F 707B6A54 DAAE7530 460842E2 0E37ED26 5CEEE9A4 3E8924AA")));
Asserts.assertTrue(Arrays.equals(md.digest((
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" +
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu").getBytes()),
xeh("23FEC5BB 94D60B23 30819264 0B0C4533 35D66473 4FE40E72 68674AF9")));
// Test vectors obtained from
// http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_256.pdf
md = MessageDigest.getInstance("SHA-512/256");
Asserts.assertTrue(Arrays.equals(md.digest("abc".getBytes()),
xeh("53048E26 81941EF9 9B2E29B7 6B4C7DAB E4C2D0C6 34FC6D46 E0E2F131 07E7AF23")));
Asserts.assertTrue(Arrays.equals(md.digest((
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" +
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu").getBytes()),
xeh("3928E184 FB8690F8 40DA3988 121D31BE 65CB9D3E F83EE614 6FEAC861 E19B563A")));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:SHA512.java
示例11: main
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void main(String[] args) throws IOException,
MonitorException, URISyntaxException {
LingeredApp app = null;
try {
List<String> vmArgs = new ArrayList<String>();
vmArgs.add("-XX:+UsePerfData");
vmArgs.addAll(Utils.getVmOptions());
app = LingeredApp.startApp(vmArgs);
MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");
String uriString = "//" + app.getPid() + "?mode=r"; // NOI18N
VmIdentifier vmId = new VmIdentifier(uriString);
MonitoredVm vm = localHost.getMonitoredVm(vmId);
System.out.println("Monitored vm command line: " + MonitoredVmUtil.commandLine(vm));
vm.setInterval(INTERVAL);
localHost.setInterval(INTERVAL);
Asserts.assertEquals(vm.getInterval(), INTERVAL, "Monitored vm interval should be equal the test value");
Asserts.assertEquals(localHost.getInterval(), INTERVAL, "Monitored host interval should be equal the test value");
} finally {
LingeredApp.stopApp(app);
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:TestPollingInterval.java
示例12: assertEQ
import jdk.testlibrary.Asserts; //导入依赖的package包/类
private void assertEQ(T t, Object returned) {
if (rtype.isArray()) {
Asserts.assertEQ(t.getClass(), returned.getClass());
int n = Array.getLength(t);
Asserts.assertEQ(n, Array.getLength(returned));
for (int i = 0; i < n; ++i) {
Asserts.assertEQ(Array.get(t, i), Array.get(returned, i));
}
} else {
Asserts.assertEQ(t, returned);
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:CatchExceptionTest.java
示例13: assertCatch
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public void assertCatch(Throwable ex) {
try {
Asserts.assertSame(thrown, ex,
"must get the out-of-band exception");
} catch (Throwable t) {
ex.printStackTrace();
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:CatchExceptionTest.java
示例14: testJpsUnknownHost
import jdk.testlibrary.Asserts; //导入依赖的package包/类
private static void testJpsUnknownHost() throws Exception {
String invalidHostName = "Oja781nh2ev7vcvbajdg-Sda1-C";
OutputAnalyzer output = JpsHelper.jps(invalidHostName);
Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
output.shouldContain("Unknown host: " + invalidHostName);
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TestJpsSanity.java
示例15: check
import jdk.testlibrary.Asserts; //导入依赖的package包/类
/**
* Verify the similarity of random numbers generated though both original
* as well as deserialized instance.
*/
private static void check(SecureRandom orig, SecureRandom copy,
boolean equal, String mech) {
int o = orig.nextInt();
int c = copy.nextInt();
System.out.printf("%nRandom number generated for mechanism: '%s' "
+ "from original instance as: '%s' and from serialized "
+ "instance as: '%s'", mech, o, c);
if (equal) {
Asserts.assertEquals(o, c, mech);
} else {
Asserts.assertNotEquals(o, c, mech);
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:SerializedSeedTest.java
示例16: checkAttributes
import jdk.testlibrary.Asserts; //导入依赖的package包/类
/**
* Check specific attributes of a SecureRandom instance.
*/
private static void checkAttributes(SecureRandom sr, String mech) {
if (sr == null) {
return;
}
Asserts.assertEquals(sr.getAlgorithm(), (isDRBG(mech) ? "DRBG" : mech));
Asserts.assertEquals(sr.getProvider().getName(), SUN_PROVIDER);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:GetInstanceTest.java
示例17: testWildcard
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void testWildcard() throws Exception {
AnnotatedType tt = GetAnnotatedOwnerType.class.getField("wildcard").getAnnotatedType();
AnnotatedType t = ((AnnotatedParameterizedType)tt).getAnnotatedActualTypeArguments()[0];
Asserts.assertTrue((t instanceof AnnotatedWildcardType),
"Was expecting an AnnotatedWildcardType " + t);
testNegative(t, "" + t + " should not have an annotated owner type");
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:GetAnnotatedOwnerType.java
示例18: testComplicated
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void testComplicated() throws Exception {
Field f = GetAnnotatedOwnerType.class.getField("complicated");
// Outermost level
AnnotatedType t = f.getAnnotatedType();
Asserts.assertTrue((t instanceof AnnotatedArrayType),
"Was expecting an AnnotatedArrayType " + t);
testNegative(t, "" + t + " should not have an annotated owner type");
Asserts.assertTrue(t.getAnnotations().length == 0, "expecting zero annotation, got: "
+ t.getAnnotations().length);
// Component type
t = ((AnnotatedArrayType)t).getAnnotatedGenericComponentType();
testNegative(t, "" + t + " should not have an annotated owner type");
Asserts.assertTrue(t.getAnnotations().length == 0, "expecting zero annotation, got: "
+ t.getAnnotations().length);
// Type arg GetAnnotatedOwnerType<String>...D<Number>
t = ((AnnotatedParameterizedType)t).getAnnotatedActualTypeArguments()[0];
Asserts.assertTrue(t.getAnnotations().length == 0, "expecting zero annotation, got: "
+ t.getAnnotations().length);
// C<Class<?>, ? extends ...>
t = t.getAnnotatedOwnerType();
Asserts.assertTrue(t.getAnnotations().length == 0, "expecting zero annotation, got: "
+ t.getAnnotations().length);
// ? extends
t = ((AnnotatedParameterizedType)t).getAnnotatedActualTypeArguments()[1];
testNegative(t, "" + t + " should not have an annotated owner type");
Asserts.assertTrue(t.getAnnotations().length == 0, "expecting zero annotation, got: "
+ t.getAnnotations().length);
// @TA("complicated") Exception
t = ((AnnotatedWildcardType)t).getAnnotatedUpperBounds()[0];
testNegative(t, "" + t + " should not have an annotated owner type");
Asserts.assertEquals(t.getAnnotation(TA.class).value(), "complicated");
Asserts.assertTrue(t.getAnnotations().length == 1, "expecting one (1) annotation, got: "
+ t.getAnnotations().length);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:GetAnnotatedOwnerType.java
示例19: main
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length == 1) {
SecurityManager sm = new SecurityManager();
System.setSecurityManager(sm);
}
Asserts.assertTrue(TwoAnnotations.class.getAnnotationsByType(MyAnnotation.class).length == 2,
"Array should contain 2 annotations: " +
Arrays.toString(TwoAnnotations.class.getAnnotationsByType(MyAnnotation.class)));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:RepeatingWithSecurityManager.java
示例20: main
import jdk.testlibrary.Asserts; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length == 1) {
SecurityManager sm = new SecurityManager();
System.setSecurityManager(sm);
}
Asserts.assertTrue(new CustomAnnotations().getAnnotationsByType(MyAnnotation.class).length == 2,
"Array should contain 2 annotations");
Asserts.assertEquals(new CustomAnnotations().getAnnotationsByType(MyAnnotation.class)[1].name(),
"Bar", "Should be 'Bar'");
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:CustomRepeatingWithSecurityManager.java
注:本文中的jdk.testlibrary.Asserts类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论