### Question:
SelectorUtils { public static String getSelectorFieldName (Selector selector){ if (null == selector){return null;} if (selector instanceof FunctionSelector){ return getFunctionSelectorFieldName((FunctionSelector) selector); } if (selector instanceof AliasSelector){ return getSelectorFieldName(((AliasSelector)selector).getReferencedSelector()); } return selector.getColumnName().getName(); }  static String getSelectorFieldName(Selector selector); static boolean isFunction(Selector selector, String... functionName); static boolean hasFunction(Map<Selector, String> columnMetadata, String... functionName); static FunctionSelector getFunctionSelector(Map<Selector, String> columnMetadata, String functionName); static String calculateSubFieldName(Selector selector); static String calculateAlias(Selector selector);  }### Answer:
@Test public void testGetNullSelectorFieldName(){ assertNull(SelectorUtils.getSelectorFieldName(null)); }
@Test public void testGetSelectorFieldName(){ Selector selector = mock(Selector.class); ColumnName columnName = mock(ColumnName.class); when(selector.getColumnName()).thenReturn(columnName); when(columnName.getName()).thenReturn("fieldName"); assertEquals("fieldName", SelectorUtils.getSelectorFieldName(selector)); }
@Test public void testGetSelectorUnknownFunctionName(){ FunctionSelector functionSelector = mock(FunctionSelector.class); List<Selector> functionColumns = new ArrayList<Selector>(); Selector selector = mock(Selector.class); ColumnName columnName = mock(ColumnName.class); Selector analyzer = mock(Selector.class); functionColumns.add(selector); functionColumns.add(analyzer); SelectExpression se = mock(SelectExpression.class); when(functionSelector.getFunctionName()).thenReturn("unknown"); when(functionSelector.getFunctionColumns()).thenReturn(se); when(se.getSelectorList()).thenReturn(functionColumns); when(selector.getColumnName()).thenReturn(columnName); when(columnName.getName()).thenReturn("fieldName"); when(analyzer.getStringValue()).thenReturn("analyzer"); assertEquals("unknown", SelectorUtils.getSelectorFieldName(functionSelector)); }
@Test public void testGetSelectorFunctionSubFieldName(){ FunctionSelector functionSelector = mock(FunctionSelector.class); List<Selector> functionColumns = new ArrayList<Selector>(); Selector selector = mock(Selector.class); ColumnName columnName = mock(ColumnName.class); Selector analyzer = mock(Selector.class); functionColumns.add(selector); functionColumns.add(analyzer); SelectExpression se = mock(SelectExpression.class); when(functionSelector.getFunctionName()).thenReturn("sub_field"); when(functionSelector.getFunctionColumns()).thenReturn(se); when(functionSelector.getFunctionColumns().getSelectorList()).thenReturn(functionColumns); when(selector.getColumnName()).thenReturn(columnName); when(columnName.getName()).thenReturn("fieldName"); when(analyzer.getStringValue()).thenReturn("analyzer"); assertEquals("fieldName.analyzer", SelectorUtils.getSelectorFieldName(functionSelector)); }