Verify email in Java

Here is what I have around. To check that the address is a valid format, here is a regex that verifies that it’s nearly rfc2822 (it doesn’t catch some weird corner cases). I found it on the ‘net last year. private static final Pattern rfc2822 = Pattern.compile( “^[a-z0-9!#$%&’*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&’*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$” ); if (!rfc2822.matcher(email).matches()) { throw new Exception(“Invalid … Read more

Is there a way of having something like jUnit Assert message argument in Mockito’s verify method?

This question is ancient, but Mockito v2.1.0+ now has a built-in feature for this. verify(mock, description(“This will print on failure”)).someMethod(“some arg”); More examples included from @Lambart’s comment below: verify(mock, times(10).description(“This will print if the method isn’t called 10 times”)).someMethod(“some arg”); verify(mock, never().description(“This will print if someMethod is ever called”)).someMethod(“some arg”); verify(mock, atLeastOnce().description(“This will print if … Read more

Openssl : error “self signed certificate in certificate chain”

You have a certificate which is self-signed, so it’s non-trusted by default, that’s why OpenSSL complains. This warning is actually a good thing, because this scenario might also rise due to a man-in-the-middle attack. To solve this, you’ll need to install it as a trusted server. If it’s signed by a non-trusted CA, you’ll have … Read more

openssl verify – error 20 at 0 depth lookup:unable to get local issuer certificate

OpenSSL> verify -CAfile C:\mycert.pem C:\mycert.pem Close. You need to add the CA’s root certificate with -CAfile; and not your end entity certificate. Something like: openssl verify -CAfile C:\ca-cert.pem C:\mycert.pem Also, if there is an intermediate certificate, then it needs to be added to mycert.pem. So mycert.pem will actually have two (or more) certificates (rather than … Read more

Moq – Is it possible to specify in a Setup the Verify criteria (e.g. Times called)?

I have this problem all the time. I use strict mocks, and I want to specify strictly (i.e. I used It.Is<>() instead of It.IsAny()) as well as verify strictly (i.e. specifying Times). You cannot use verifiable for this sadly, because Moq is missing a Verifiable(Times) overload. The full expression of the call, including It.Is<>() is … Read more

How to verify downloaded file with .sig file?

You need to import public key: C3C45C06 Can be done in three steps. find public key ID: $ gpg gcc-4.7.2.tar.gz.sig gpg: Signature made Čt 20. září 2012, 12:30:44 CEST using DSA key ID C3C45C06 gpg: Can’t check signature: No public key import the public key from key server. It’s usually not needed to choose key server, but it can be … Read more

Java verify void method calls n times with Mockito

The necessary method is Mockito#verify: public static <T> T verify(T mock, VerificationMode mode) mock is your mocked object and mode is the VerificationMode that describes how the mock should be verified. Possible modes are: verify(mock, times(5)).someMethod(“was called five times”); verify(mock, never()).someMethod(“was never called”); verify(mock, atLeastOnce()).someMethod(“was called at least once”); verify(mock, atLeast(2)).someMethod(“was called at least twice”); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)