Ehcache article source code (#751)

* - created packages for each logical part of application
- created validator for WebsiteUser rest API
- created ValidatorEventRegister class which fixes known bug for not
detecting generated events
- created custom Exception Handler which creates better response
messages

* Code formatting

* formated pom.xml
replaced for loops with streams
fixed bug while getting all beans

* removed unnecessary code
changed repository type

* - added test for Spring Data REST APIs
- changed bad request return code
- formated code

* - added source code for ehcache article
- added ehcache dependency to pom.xml

* - added test for ehcache article
- removed main method which was only for testing purposes
This commit is contained in:
Ante Pocedulic 2016-10-16 11:12:51 +02:00 committed by Grzegorz Piwowarek
parent 67b3d62b91
commit db2b93a1b6
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
package org.baeldung.ehcache;
import static org.junit.Assert.*;
import org.baeldung.ehcache.calculator.SquaredCalculator;
import org.baeldung.ehcache.config.CacheHelper;
import org.junit.Before;
import org.junit.Test;
public class SquareCalculatorTest {
SquaredCalculator squaredCalculator = new SquaredCalculator();
CacheHelper cacheHelper = new CacheHelper();
@Before
public void setup() {
squaredCalculator.setCache(cacheHelper);
}
@Test
public void whenCalculatingSquareValueOnce_thenCacheDontHaveValues() {
for (int i = 10; i < 15; i++) {
assertFalse(cacheHelper.getSquareNumberCache().containsKey(i));
System.out.println("Square value of " + i + " is: "
+ squaredCalculator.getSquareValueOfNumber(i) + "\n");
}
}
@Test
public void whenCalculatingSquareValueAgain_thenCacheHasAllValues() {
for (int i = 10; i < 15; i++) {
assertFalse(cacheHelper.getSquareNumberCache().containsKey(i));
System.out.println("Square value of " + i + " is: "
+ squaredCalculator.getSquareValueOfNumber(i) + "\n");
}
for (int i = 10; i < 15; i++) {
assertTrue(cacheHelper.getSquareNumberCache().containsKey(i));
System.out.println("Square value of " + i + " is: "
+ squaredCalculator.getSquareValueOfNumber(i) + "\n");
}
}
}