PasteTemplate { public void execute() { String text = event.getValue(); if (text != null) { String[] values = PasteUtils.split(text); if (values.length > 1) { clearSourceField(event); for (int i = 0; i < values.length; i++) { try { String temp = values[i]; temp = PasteUtils.translateSeparators(temp, locale); String s = temp.replaceAll("%", ""); process(i, s); } catch (Exception ex) { LOG.error(ex.getMessage(), ex); } } } } } PasteTemplate(Locale locale, Grid<T> grid, ValueChangeEvent<String> event); void execute(); Grid<T> getGrid();  }
@Test public void testIgnoreForSingleValue() { when(event.getValue()).thenReturn("3"); final List<String> values = new ArrayList<>(); template = new PasteTemplate<TestEntity>(locale, grid, event) { @Override protected void process(int index, String value) { values.add(value); } @Override protected void clearSourceField(ValueChangeEvent<String> event) { } }; template.execute(); assertEquals(0, values.size()); }
@Test public void testMultipleValues() { when(event.getValue()).thenReturn("3 4 5"); final List<String> values = new ArrayList<>(); template = new PasteTemplate<TestEntity>(locale, grid, event) { @Override protected void process(int index, String value) { values.add(value); } @Override protected void clearSourceField(ValueChangeEvent<String> event) { } }; template.execute(); assertEquals(3, values.size()); assertEquals("3", values.get(0)); assertEquals("4", values.get(1)); assertEquals("5", values.get(2)); }
@Test public void testMultipleValuesWithTabs() { when(event.getValue()).thenReturn("3\t4\t5"); final List<String> values = new ArrayList<>(); template = new PasteTemplate<TestEntity>(locale, grid, event) { @Override protected void process(int index, String value) { values.add(value); } @Override protected void clearSourceField(ValueChangeEvent<String> event) { } }; template.execute(); assertEquals(3, values.size()); assertEquals("3", values.get(0)); assertEquals("4", values.get(1)); assertEquals("5", values.get(2)); }
@Test public void testSeparatorReplace() { when(event.getValue()).thenReturn("4.2 5.2"); final List<String> values = new ArrayList<>(); template = new PasteTemplate<TestEntity>(locale, grid, event) { @Override protected void process(int index, String value) { values.add(value); } @Override protected void clearSourceField(ValueChangeEvent<String> event) { } }; template.execute(); assertEquals(2, values.size()); assertEquals("4,2", values.get(0)); assertEquals("5,2", values.get(1)); }