1
2
3
4
5
6
7
8
9
10
11
12 package com.octo.captcha;
13
14 import java.util.Locale;
15
16 /***
17 * <p><ul><li></li></ul></p>
18 *
19 * @author <a href="mailto:mag@jcaptcha.net">Marc-Antoine Garrigue</a>
20 * @version 1.0
21 */
22 public class MockCaptcha implements Captcha {
23 private boolean isDisposed = false;
24 private boolean asBeenCalled = false;
25 private Locale locale = null;
26
27 public static final String QUESTION = "mockQuestion";
28 public static final String CHALLENGE = "mockChallenge";
29
30 public MockCaptcha(Locale locale) {
31 this.locale = locale;
32 }
33
34 /***
35 * Accessor captcha question.
36 *
37 * @return the question
38 */
39 public String getQuestion() {
40 return QUESTION + locale;
41 }
42
43 /***
44 * Accerssor for the questionned challenge.
45 *
46 * @return the challenge (may be an image for image captcha...
47 */
48 public Object getChallenge() {
49 asBeenCalled = true;
50 return !isDisposed ? CHALLENGE : null;
51 }
52
53 /***
54 * Validation routine for the response.
55 *
56 * @param response to the question concerning the chalenge
57 *
58 * @return true if the answer is correct, false otherwise.
59 */
60 public Boolean validateResponse(Object response) {
61 return new Boolean(response.toString());
62 }
63
64 /***
65 * Dispose the challenge, once this method is call the getChallenge method will return null.<br> It has been added
66 * for technical reasons : a captcha is always used in a two step fashion<br> First submit the challenge, and then
67 * wait until the response arrives.<br> It had been asked to have a method to dispose the challenge that is no
68 * longer used after being dipslayed. So here it is!
69 */
70 public void disposeChallenge() {
71 isDisposed = true;
72 }
73
74 /***
75 * This method should return true if the getChalenge method has been called (has been added in order to properly
76 * manage the captcha state.
77 *
78 * @return true if getChallenge has been called false otherwise.
79 */
80 public Boolean hasGetChalengeBeenCalled() {
81 return new Boolean(asBeenCalled);
82 }
83
84 }