New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assertion on expected exception when adding a try/catch #419

Closed
vmassol opened this Issue May 9, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@vmassol
Contributor

vmassol commented May 9, 2018

For example the following test was added:

    @Test(timeout = 10000)
    public void testRSAEncryptionDecryptionProgressive_failAssert2() throws Exception {
        try {
            Cipher cipher = factory.getInstance(true, AmplBcRsaOaepCipherFactoryTest.publicKey);
            cipher.update(AmplBcRsaOaepCipherFactoryTest.input, 0, 17);
            cipher.update(AmplBcRsaOaepCipherFactoryTest.input, 17, 1);
            cipher.update(AmplBcRsaOaepCipherFactoryTest.input, 18, ((AmplBcRsaOaepCipherFactoryTest.input.length) - 18));
            byte[] encrypted = cipher.doFinal();
            cipher = factory.getInstance(false, AmplBcRsaOaepCipherFactoryTest.privateKey);
            cipher.update(encrypted, 0, 65);
            cipher.update(encrypted, 65, 1);
            cipher.update(encrypted, 66, ((encrypted.length) - 66));
            cipher.doFinal();
            CoreMatchers.equalTo(AmplBcRsaOaepCipherFactoryTest.input);
            cipher = factory.getInstance(true, AmplBcRsaOaepCipherFactoryTest.privateKey);
            cipher.update(AmplBcRsaOaepCipherFactoryTest.input, 0, 15);
            cipher.update(AmplBcRsaOaepCipherFactoryTest.input, 15, 1);
            encrypted = cipher.doFinal(AmplBcRsaOaepCipherFactoryTest.input, 16, ((AmplBcRsaOaepCipherFactoryTest.input.length) - 16));
            cipher = factory.getInstance(false, AmplBcRsaOaepCipherFactoryTest.publicKey);
            cipher.update(encrypted);
            cipher.doFinal();
            CoreMatchers.equalTo(AmplBcRsaOaepCipherFactoryTest.input);
            cipher.doFinal();
            CoreMatchers.equalTo(AmplBcRsaOaepCipherFactoryTest.input);
            org.junit.Assert.fail("testRSAEncryptionDecryptionProgressive should have thrown GeneralSecurityException");
        } catch (GeneralSecurityException eee) {
        }
    }

It would be nice to improve this on 2 aspects:

  • name the exception "expected" instead of "eee". This a JUnit best practice
  • assert the exception message

danglotb added a commit to danglotb/dspot that referenced this issue May 13, 2018

danglotb added a commit to danglotb/dspot that referenced this issue May 14, 2018

danglotb added a commit to danglotb/dspot that referenced this issue May 14, 2018

@danglotb danglotb closed this in c859d7f May 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment