Bonjour à tous,
J'ai écris une méthode avec un catch :
Mais cobertura (lancé depuis maven 3) me dit que le catch n'est pas couvert. Comment je peux le tester ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 protected final String doEncrypt(final String message, final String algo) { // REGLE RG024.2 if (message == null || message.length() == 0) { throw new IllegalArgumentException("Le param 'message' ne peut pas etre vide."); } // REGLE RG024.1, RG024.3 try { final byte[] uniqueKey = message.getBytes(); final byte[] hash = MessageDigest.getInstance(algo).digest(uniqueKey); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < hash.length; i++) { String hex = Integer.toHexString(hash[i]); if (hex.length() == 1) { sb.append('0'); sb.append(hex.charAt(hex.length() - 1)); } else { sb.append(hex.substring(hex.length() - 2)); } } final String encrypt = sb.toString(); return encrypt; } catch (NoSuchAlgorithmException e) { return null; } }
Partager