@Test public void getOrCreateShouldCreateIfAny() { Category category = Category.USER; int number = 0; statisticRefDaoService.create(StatisticRefEnum.CREATED_ISSUE_COUNT); assertNull(daoService.get(category, number)); Level level = daoService.getOrCreate(category, number, StatisticRefEnum.CREATED_ISSUE_COUNT, 0, 10); assertNotNull(level); entityManager.flushAll(); assertNotNull(daoService.get(category, number)); }
@Test public void findMatchingLevelShouldReturnLevelForGivenValue() { Category category = Category.USER; statisticRefDaoService.create(StatisticRefEnum.CREATED_ISSUE_COUNT); daoService.getOrCreate(category, 0, StatisticRefEnum.CREATED_ISSUE_COUNT, 0, 10); daoService.getOrCreate(category, 1, StatisticRefEnum.CREATED_ISSUE_COUNT, 10, 50); daoService.getOrCreate(category, 2, StatisticRefEnum.CREATED_ISSUE_COUNT, 50, 150); daoService.getOrCreate(category, 3, StatisticRefEnum.CREATED_ISSUE_COUNT, 150, 500); daoService.getOrCreate(category, 4, StatisticRefEnum.CREATED_ISSUE_COUNT, 500, 2000); daoService.getOrCreate(category, 5, StatisticRefEnum.CREATED_ISSUE_COUNT, 2000, 5000); int value = 150; Level level = daoService.findMatchingLevel(category, value); assertNotNull(level); assertTrue(level.getMinThreshold() <= value); assertTrue(level.getMaxThreshold() > value); }