| 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 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
package net.sourceforge.pebble.confirmation; |
| 33 |
|
|
| 34 |
|
import javax.servlet.http.HttpServletRequest; |
| 35 |
|
import java.util.Random; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@author |
| 42 |
|
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 6 |
Complexity Density: 0,26 |
|
| 43 |
|
public class SimpleMathsConfirmationStrategy extends AbstractConfirmationStrategy { |
| 44 |
|
|
| 45 |
|
private static final String ARGUMENT1 = "SimpleMathsConfirmationStrategyArg1"; |
| 46 |
|
private static final String ARGUMENT2 = "SimpleMathsConfirmationStrategyArg2"; |
| 47 |
|
private static final String OPERATOR = "SimpleMathsConfirmationStrategyOperator"; |
| 48 |
|
private static final String ANSWER = "SimpleMathsConfirmationStrategyAnswer"; |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
@param |
| 54 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0,21 |
|
| 55 |
0
|
public void setupConfirmation(HttpServletRequest request) {... |
| 56 |
0
|
Random r = new Random(); |
| 57 |
0
|
int arg1 = r.nextInt(10) + 1; |
| 58 |
0
|
int arg2 = r.nextInt(10) + 1; |
| 59 |
0
|
int op = r.nextInt(3); |
| 60 |
0
|
request.getSession().setAttribute(ARGUMENT1, arg1); |
| 61 |
0
|
request.getSession().setAttribute(ARGUMENT2, arg2); |
| 62 |
|
|
| 63 |
0
|
switch (op) { |
| 64 |
0
|
case 0 : |
| 65 |
0
|
request.getSession().setAttribute(OPERATOR, "+"); |
| 66 |
0
|
request.getSession().setAttribute(ANSWER, arg1 + arg2); |
| 67 |
0
|
break; |
| 68 |
0
|
case 1 : |
| 69 |
0
|
request.getSession().setAttribute(OPERATOR, "-"); |
| 70 |
0
|
request.getSession().setAttribute(ANSWER, arg1 - arg2); |
| 71 |
0
|
break; |
| 72 |
0
|
case 2 : |
| 73 |
0
|
request.getSession().setAttribute(OPERATOR, "*"); |
| 74 |
0
|
request.getSession().setAttribute(ANSWER, arg1 * arg2); |
| 75 |
0
|
break; |
| 76 |
|
} |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
@return |
| 83 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 84 |
0
|
public String getUri() {... |
| 85 |
0
|
return "/WEB-INF/jsp/confirmation/maths.jsp"; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
@param |
| 92 |
|
@return |
| 93 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 94 |
0
|
public boolean isConfirmed(HttpServletRequest request) {... |
| 95 |
0
|
Integer answer = (Integer)request.getSession().getAttribute(ANSWER); |
| 96 |
0
|
String userAnswer = request.getParameter("answer"); |
| 97 |
|
|
| 98 |
0
|
return answer.toString().equals(userAnswer); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
} |