@Before public void setupMocks() throws Exception { expressionFactory = new ExpressionFactoryImpl(); functionMapper = RuleEvaluator.FUNCTION_MAPPER; testName = "testName"; final List<TestBucket> buckets = ImmutableList.of( new TestBucket("inactive", -1, "zoot", null), new TestBucket("control", 0, "zoot", null), new TestBucket("test", 1, "zoot", null)); testDefinition = new ConsumableTestDefinition(); testDefinition.setConstants(Collections.<String, Object>emptyMap()); testDefinition.setTestType(TestType.AUTHENTICATED_USER); // most tests just set the salt to be the same as the test name testDefinition.setSalt(testName); testDefinition.setBuckets(buckets); updateAllocations(RANGES_50_50); final int effBuckets = buckets.size() - 1; counts = new int[effBuckets]; hashes = new int[effBuckets]; }
@Test public void testExceptionsDealtWith() { final String testName = "test"; final ConsumableTestDefinition testDefinition = new ConsumableTestDefinition(); testDefinition.setConstants(Collections.<String, Object>emptyMap()); testDefinition.setRule("${lang == 'en'}"); testDefinition.setTestType(TestType.ANONYMOUS_USER); // most tests just set the salt to be the same as the test name testDefinition.setSalt(testName); testDefinition.setBuckets(Collections.<TestBucket>emptyList()); final RuleEvaluator ruleEvaluator = EasyMock.createMock(RuleEvaluator.class); EasyMock.expect( ruleEvaluator.evaluateBooleanRule( EasyMock.<String>anyObject(), EasyMock.<Map<String, Object>>anyObject())) // throw an unexpected type of runtime exception .andThrow(new RuntimeException() {}) // Must be evaluated, or this was not a valid test .once(); EasyMock.replay(ruleEvaluator); final TestRangeSelector selector = new TestRangeSelector(ruleEvaluator, testName, testDefinition); // Ensure no exceptions thrown. final TestBucket bucket = new StandardTestChooser(selector) .choose("identifier", Collections.<String, Object>emptyMap()); assertEquals("Expected no bucket to be found ", null, bucket); EasyMock.verify(ruleEvaluator); }