Package com.bazaarvoice.snitch

Examples of com.bazaarvoice.snitch.Variable


        assertEquals("{}", _output.toString());
    }

    @Test
    public void testIntegerVariable() throws IOException, ServletException {
        Variable v = defineVariable("integer", 1);

        _servlet.doGet(_request, _response);
        assertVariablesInJson(_output.toString(), v);
    }
View Full Code Here


        assertVariablesInJson(_output.toString(), v);
    }

    @Test
    public void testStringVariable() throws IOException, ServletException {
        Variable v = defineVariable("string", "bar");

        _servlet.doGet(_request, _response);
        assertVariablesInJson(_output.toString(), v);
    }
View Full Code Here

        assertVariablesInJson(_output.toString(), v);
    }

    @Test
    public void testBooleanVariable() throws IOException, ServletException {
        Variable v = defineVariable("boolean", true);

        _servlet.doGet(_request, _response);
        assertVariablesInJson(_output.toString(), v);
    }
View Full Code Here

        assertVariablesInJson(_output.toString(), v);
    }

    @Test
    public void testNullVariable() throws IOException, ServletException {
        Variable v = defineVariable("string", null, String.class);

        _servlet.doGet(_request, _response);
        assertVariablesInJson(_output.toString(), v);
    }
View Full Code Here

        assertVariablesInJson(_output.toString(), v);
    }

    @Test
    public void testMultipleVariables() throws IOException, ServletException {
        Variable a = defineVariable("a", 1);
        Variable b = defineVariable("b", 10.);
        Variable c = defineVariable("c", "str");
        Variable d = defineVariable("d", false);
        Variable e = defineVariable("e", true);
        Variable f = defineVariable("f", null, Integer.class);

        _servlet.doGet(_request, _response);
        assertVariablesInJson(_output.toString(), a, b, c, d, e, f);
    }
View Full Code Here

    }

    @Test
    public void testDuplicateVariables() throws IOException, ServletException {
        String name = "a";
        Variable a1 = defineVariable(name, 1.0);
        Variable a2 = defineVariable(name, "second a");

        _servlet.doGet(_request, _response);

        Map<String, Object> jsonVarMap = parseJson(_output.toString());
        assertEquals(1, jsonVarMap.size());
        assertTrue(jsonVarMap.get(name) instanceof List);
       
        List jsonVars = (List) jsonVarMap.get(name);
        assertEquals(2, jsonVars.size());
        assertTrue(jsonVars.contains(a1.getValue()));
        assertTrue(jsonVars.contains(a2.getValue()));
    }
View Full Code Here

    private <T> Variable defineVariable(String name, final T value) {
        return defineVariable(name, value, (Class<T>) value.getClass());
    }

    private <T> Variable defineVariable(String name, T value, final Class<T> type) {
        Variable v = mock(Variable.class);
        when(v.getName()).thenReturn(name);
        when(v.getValue()).thenReturn(value);

        // For some reason the type inference doesn't work properly if we call thenReturn, so we use thenAnswer
        // instead and always return the class value (e.g. T).
        when(v.getType()).thenAnswer(new Answer<Class<T>>() {
            @Override
            public Class<T> answer(InvocationOnMock invocation) throws Throwable {
                return type;
            }
        });
View Full Code Here

TOP

Related Classes of com.bazaarvoice.snitch.Variable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.