View Javadoc

1   /*
2    * JCaptcha, the open source java framework for captcha definition and integration
3    * Copyright (c)  2007 jcaptcha.net. All Rights Reserved.
4    * See the LICENSE.txt file distributed with this package.
5    */
6   
7   /*
8    * jcaptcha, the open source java framework for captcha definition and integration
9    * copyright (c)  2007 jcaptcha.net. All Rights Reserved.
10   * See the LICENSE.txt file distributed with this package.
11   */
12  package com.octo.captcha.engine.bufferedengine;
13  
14  import com.octo.captcha.Captcha;
15  import junit.framework.TestCase;
16  
17  import java.util.Locale;
18  
19  /***
20   * @author Benoit
21   */
22  public abstract class BufferedEngineContainerTestAbstract extends TestCase {
23  
24  
25      /*
26      * Class under test for Captcha getNextCaptcha()
27      */
28      public void testGetNextCaptcha() {
29          BufferedEngineContainer engine = getEngine();
30          assertTrue(Captcha.class.isInstance(engine.getNextCaptcha()));
31          releaseEngine(engine);
32      }
33  
34      /*
35       * Class under test for Captcha getNextCaptcha(Locale)
36       */
37      public void testGetNextCaptchaLocale() {
38          BufferedEngineContainer engine = getEngine();
39          assertTrue(Captcha.class.isInstance(engine.getNextCaptcha(Locale.FRANCE)));
40          releaseEngine(engine);
41      }
42  
43      public void testSwapCaptchasFromPersistentToVolatileMemory() {
44          BufferedEngineContainer engine = getEngine();
45          int size = engine.getVolatileBuffer().size();
46  
47          engine.feedPersistentBuffer();
48  
49          engine.swapCaptchasFromPersistentToVolatileMemory();
50  
51          assertTrue(size < engine.getVolatileBuffer().size());
52  
53          releaseEngine(engine);
54      }
55  
56      public void testFeedPersistentBuffer() {
57          BufferedEngineContainer engine = getEngine();
58          int size = engine.getPersistentBuffer().size();
59  
60          engine.feedPersistentBuffer();
61  
62          assertTrue(size < engine.getPersistentBuffer().size());
63          releaseEngine(engine);
64      }
65  
66      public abstract BufferedEngineContainer getEngine();
67  
68      public abstract void releaseEngine(BufferedEngineContainer engine);
69  
70  }