コード例 #1
0
 @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);
 }
コード例 #2
0
 @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);
 }
コード例 #3
0
 @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) {
   }
 }
コード例 #4
0
 @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'.");
   }
 }