本文整理汇总了Java中com.google.common.base.VerifyException类的典型用法代码示例。如果您正苦于以下问题:Java VerifyException类的具体用法?Java VerifyException怎么用?Java VerifyException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VerifyException类属于com.google.common.base包,在下文中一共展示了VerifyException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJavaObject
import com.google.common.base.VerifyException; //导入依赖的package包/类
/**
* Converts a {@link JsonValue} to its corresponding Java object. Values of type {@link
* JsonObject} or {@link JsonArray} are converted as specified by {@link #toJavaMap} and {@link
* #toJavaList}, respectively.
*/
@Nullable
public static Object toJavaObject(JsonValue value) {
switch (value.getValueType()) {
case ARRAY:
return toJavaList((JsonArray) value);
case FALSE:
return Boolean.FALSE;
case NULL:
return null;
case NUMBER:
JsonNumber number = (JsonNumber) value;
return number.isIntegral() ? number.intValue() : number.doubleValue();
case OBJECT:
return toJavaMap((JsonObject) value);
case STRING:
return ((JsonString) value).getString();
case TRUE:
return Boolean.TRUE;
default:
throw new VerifyException("Json value with unknown type: " + value);
}
}
示例2: getSuperMethodSpecs
import com.google.common.base.VerifyException; //导入依赖的package包/类
private List<MethodSpec> getSuperMethodSpecs() {
List<MethodSpec> methodSpecs = new ArrayList<>();
this.annotatedClazz.annotatedElement.getEnclosedElements().stream()
.filter(element -> element instanceof ExecutableElement)
.map(element -> (ExecutableElement) element)
.forEach(method -> {
ClassName preferenceRoom = ClassName.get(PreferenceRoom.class);
MethodSpec.Builder builder = MethodSpec.overriding(method);
MethodSpec methodSpec = builder.addStatement("$T.inject($N)", preferenceRoom, method.getParameters().get(0).getSimpleName()).build();
if(methodSpec.returnType != TypeName.get(Void.TYPE)) {
throw new VerifyException(String.format("Returned '%s'. only return type can be void.", methodSpec.returnType.toString()));
}
methodSpecs.add(methodSpec);
});
return methodSpecs;
}
示例3: processInjector
import com.google.common.base.VerifyException; //导入依赖的package包/类
private void processInjector(PreferenceComponentAnnotatedClass annotatedClass) throws VerifyException {
try {
annotatedClass.annotatedElement.getEnclosedElements().stream()
.filter(element -> element instanceof ExecutableElement)
.map(element -> (ExecutableElement) element)
.forEach(method -> {
MethodSpec methodSpec = MethodSpec.overriding(method).build();
ParameterSpec parameterSpec = methodSpec.parameters.get(0);
TypeElement injectedElement = processingEnv.getElementUtils().getTypeElement(parameterSpec.type.toString());
generateProcessInjector(annotatedClass, injectedElement);
});
} catch (VerifyException e) {
showErrorLog(e.getMessage(), annotatedClass.annotatedElement);
e.printStackTrace();
}
}
示例4: KickbackElementClass
import com.google.common.base.VerifyException; //导入依赖的package包/类
public KickbackElementClass(VariableElement variableElement, Elements elementUtils) throws VerifyException {
KickbackElement kickbackElement = variableElement.getAnnotation(KickbackElement.class);
Weak weak = variableElement.getAnnotation(Weak.class);
Soft soft = variableElement.getAnnotation(Soft.class);
PackageElement packageElement = elementUtils.getPackageOf(variableElement);
this.variableElement = variableElement;
this.packageName = packageElement.isUnnamed() ? null : packageElement.getQualifiedName().toString();
this.typeName = TypeName.get(variableElement.asType());
this.clazzName = variableElement.getSimpleName().toString();
this.value = variableElement.getConstantValue();
if(weak != null) this.isWeak = true;
else this.isWeak = false;
if(soft != null) this.isSoft = true;
else this.isSoft = false;
if(kickbackElement != null) {
this.elementName = StringUtils.toUpperCamel(Strings.isNullOrEmpty(kickbackElement.name()) ? this.clazzName : kickbackElement.name());
} else {
this.elementName = StringUtils.toUpperCamel(this.clazzName);
}
checkPrimitiveType();
checkModifierValidate();
checkAnnotationValidate();
}
示例5: provideJsonPayload
import com.google.common.base.VerifyException; //导入依赖的package包/类
@Provides
@JsonPayload
@SuppressWarnings("unchecked")
static Map<String, Object> provideJsonPayload(
@Header("Content-Type") MediaType contentType,
@Payload String payload) {
if (!JSON_UTF_8.is(contentType.withCharset(UTF_8))) {
throw new UnsupportedMediaTypeException(
String.format("Expected %s Content-Type", JSON_UTF_8.withoutParameters()));
}
try {
return (Map<String, Object>) JSONValue.parseWithException(payload);
} catch (ParseException e) {
throw new BadRequestException(
"Malformed JSON", new VerifyException("Malformed JSON:\n" + payload, e));
}
}
示例6: lookupPublicKey
import com.google.common.base.VerifyException; //导入依赖的package包/类
/**
* Search for public key on keyring based on a substring (like an email address).
*
* @throws VerifyException if the key couldn't be found.
* @see #lookupKeyPair
*/
public static PGPPublicKey lookupPublicKey(
PGPPublicKeyRingCollection keyring, String query, KeyRequirement want) {
try {
// Safe by specification.
@SuppressWarnings("unchecked")
Iterator<PGPPublicKeyRing> results =
keyring.getKeyRings(checkNotNull(query, "query"), true, true);
verify(results.hasNext(), "No public key found matching substring: %s", query);
while (results.hasNext()) {
Optional<PGPPublicKey> result = lookupPublicSubkey(results.next(), want);
if (result.isPresent()) {
return result.get();
}
}
throw new VerifyException(String.format(
"No public key (%s) found matching substring: %s", want, query));
} catch (PGPException e) {
throw new VerifyException(String.format(
"Public key lookup with query %s failed: %s", query, e.getMessage()));
}
}
示例7: lookupKeyPair
import com.google.common.base.VerifyException; //导入依赖的package包/类
/**
* Same as {@link #lookupPublicKey} but also retrieves the associated private key.
*
* @throws VerifyException if either keys couldn't be found.
* @see #lookupPublicKey
*/
@SuppressWarnings("deprecation")
public static PGPKeyPair lookupKeyPair(
PGPPublicKeyRingCollection publics,
PGPSecretKeyRingCollection privates,
String query,
KeyRequirement want) {
PGPPublicKey publicKey = lookupPublicKey(publics, query, want);
PGPPrivateKey privateKey;
try {
PGPSecretKey secret = verifyNotNull(privates.getSecretKey(publicKey.getKeyID()),
"Keyring missing private key associated with public key id: %x (query '%s')",
publicKey.getKeyID(), query);
// We do not support putting a password on the private key so we're just going to
// put char[0] here.
privateKey = secret.extractPrivateKey(
new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider())
.build(new char[0]));
} catch (PGPException e) {
throw new VerifyException(e.getMessage());
}
return new PGPKeyPair(publicKey, privateKey);
}
示例8: testSaveRevision_objectDoesntExist_newRevisionIsOne_throwsVe
import com.google.common.base.VerifyException; //导入依赖的package包/类
@Test
public void testSaveRevision_objectDoesntExist_newRevisionIsOne_throwsVe() throws Exception {
VerifyException thrown =
expectThrows(
VerifyException.class,
() ->
ofy()
.transact(
new VoidWork() {
@Override
public void vrun() {
saveRevision("despondency", DateTime.parse("1984-12-18TZ"), FULL, 1);
}
}));
assertThat(thrown).hasMessageThat().contains("object missing");
}
示例9: testSaveRevision_objectExistsAtZero_newRevisionIsZero_throwsVe
import com.google.common.base.VerifyException; //导入依赖的package包/类
@Test
public void testSaveRevision_objectExistsAtZero_newRevisionIsZero_throwsVe() throws Exception {
save("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0);
VerifyException thrown =
expectThrows(
VerifyException.class,
() ->
ofy()
.transact(
new VoidWork() {
@Override
public void vrun() {
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0);
}
}));
assertThat(thrown).hasMessageThat().contains("object already created");
}
示例10: testSaveRevision_objectExistsAtZero_newRevisionIsTwo_throwsVe
import com.google.common.base.VerifyException; //导入依赖的package包/类
@Test
public void testSaveRevision_objectExistsAtZero_newRevisionIsTwo_throwsVe() throws Exception {
save("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 0);
VerifyException thrown =
expectThrows(
VerifyException.class,
() ->
ofy()
.transact(
new VoidWork() {
@Override
public void vrun() {
saveRevision("melancholy", DateTime.parse("1984-12-18TZ"), FULL, 2);
}
}));
assertThat(thrown).hasMessageThat().contains("should be at 1 ");
}
示例11: testPublishDomainFails_whenDnsUpdateReturnsError
import com.google.common.base.VerifyException; //导入依赖的package包/类
@Test
public void testPublishDomainFails_whenDnsUpdateReturnsError() throws Exception {
DomainResource domain =
persistActiveDomain("example.tld")
.asBuilder()
.setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.tld"))))
.build();
persistResource(domain);
when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL));
VerifyException thrown =
expectThrows(
VerifyException.class,
() -> {
writer.publishDomain("example.tld");
writer.commit();
});
assertThat(thrown).hasMessageThat().contains("SERVFAIL");
}
示例12: testPublishHostFails_whenDnsUpdateReturnsError
import com.google.common.base.VerifyException; //导入依赖的package包/类
@Test
public void testPublishHostFails_whenDnsUpdateReturnsError() throws Exception {
HostResource host =
persistActiveSubordinateHost("ns1.example.tld", persistActiveDomain("example.tld"))
.asBuilder()
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("10.0.0.1")))
.build();
persistResource(host);
when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL));
VerifyException thrown =
expectThrows(
VerifyException.class,
() -> {
writer.publishHost("ns1.example.tld");
writer.commit();
});
assertThat(thrown).hasMessageThat().contains("SERVFAIL");
}
示例13: testRun_errorResponse
import com.google.common.base.VerifyException; //导入依赖的package包/类
@Test
public void testRun_errorResponse() throws Exception {
reset(connection);
command.setConnection(connection);
when(connection.send(
eq(CreatePremiumListAction.PATH),
anyMapOf(String.class, String.class),
any(MediaType.class),
any(byte[].class)))
.thenReturn(
JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}");
VerifyException thrown =
expectThrows(
VerifyException.class, () -> runCommandForced("-i=" + premiumTermsPath, "-n=foo"));
assertThat(thrown).hasMessageThat().contains("Server error:");
}
示例14: testOnDataCaseLeafFail
import com.google.common.base.VerifyException; //导入依赖的package包/类
@Test(expected = VerifyException.class)
public void testOnDataCaseLeafFail() throws DataValidationFailedException {
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
TestModel.TEST_QNAME, "choice1"));
final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id);
final ChoiceNode choice1 = Builders.choiceBuilder().withNodeIdentifier(choice1Id)
.withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case1-leaf1"), "leaf-value")).build();
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(ii, choice1);
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
}
示例15: testYangFunctionContext
import com.google.common.base.VerifyException; //导入依赖的package包/类
@Test(expected = UnresolvableException.class)
public void testYangFunctionContext() throws UnresolvableException, FunctionCallException {
final YangFunctionContext yangFun = YangFunctionContext.getInstance();
assertNotNull(yangFun);
final Function function = yangFun.getFunction("urn:opendaylight.test2", null, "current");
assertNotNull(function);
try {
final Context context = mock(Context.class);
final ArrayList<Object> list = new ArrayList<>();
function.call(context, list);
fail();
} catch (VerifyException e) {
// Expected
}
yangFun.getFunction("urn:opendaylight.test2", "test2", "root");
}