@Test public void testStringEvaluatorLookupAttributeAndConvertFromIntToLong() { Attribute amd = when(mock(Attribute.class).getName()).thenReturn("#POS").getMock(); when(amd.getDataType()).thenReturn(LONG); when(amd.getExpression()).thenReturn("Int"); assertEquals(new StringExpressionEvaluator(amd, entityType).evaluate(entity), 1L); }
@Test( expectedExceptions = ConversionFailedException.class, expectedExceptionsMessageRegExp = "Failed to convert from type \\[java.lang.String\\] to type \\[java.lang.Long\\] for value 'Hello World!'; nested exception is java.lang.NumberFormatException: For input string: \"HelloWorld!\"") public void testStringEvaluatorLookupAttributeAndConvertFromNonNumericStringToLongFails() { Attribute amd = when(mock(Attribute.class).getName()).thenReturn("#POS").getMock(); when(amd.getDataType()).thenReturn(LONG); when(amd.getExpression()).thenReturn("NonNumericString"); new StringExpressionEvaluator(amd, entityType).evaluate(entity); }
@Test public void testStringEvaluatorConstructorChecksIfExpressionIsMap() { Attribute amd = when(mock(Attribute.class).getName()).thenReturn("#CHROM").getMock(); when(amd.getDataType()).thenReturn(STRING); when(amd.getExpression()).thenReturn("{}"); try { new StringExpressionEvaluator(amd, entityType); fail("expected illegal state exception"); } catch (JsonSyntaxException expected) { } }
@Test public void testStringEvaluatorConstructorChecksIfAttributeMentionsExistingAttribute() { Attribute amd = when(mock(Attribute.class).getName()).thenReturn("#CHROM").getMock(); when(amd.getDataType()).thenReturn(STRING); when(amd.getExpression()).thenReturn("bogus"); try { new StringExpressionEvaluator(amd, entityType); fail("expected illegal argument exception"); } catch (IllegalArgumentException expected) { assertEquals( expected.getMessage(), "Expression for attribute '#CHROM' references non-existant attribute 'bogus'."); } }