TimeAmountEditor implements IsWidget { public void init(final TimeAmount ta, Command onChangeCommand) { this.onChangeCommand = onChangeCommand; this.timeAmount = ta != null ? ta : new TimeAmount(); view.setQuantity(timeAmount.getQuantity()); view.clearIntervalTypeSelector(); for (int i=0; i< INTERVAL_TYPES.size(); i++) { DateIntervalType type = INTERVAL_TYPES.get(i); view.addIntervalTypeItem(type); if (timeAmount != null && timeAmount.getType().equals(type)) { view.setSelectedTypeIndex(i); } } } @Inject  TimeAmountEditor(View view); @Override Widget asWidget(); TimeAmount getTimeAmount(); void init(final TimeAmount ta, Command onChangeCommand); long getQuantity(); void decreaseQuantity(); void increaseQuantity(); void changeQuantity(String value); void changeIntervalType(); static List<DateIntervalType> INTERVAL_TYPES; }
@Test public void testViewInitialization() { TimeAmount timeAmount = new TimeAmount(10, DateIntervalType.DAY); TimeAmountEditor editor = new TimeAmountEditor(timeAmountView); editor.init(timeAmount, changeCommand); verify(timeAmountView).clearIntervalTypeSelector(); verify(timeAmountView, times(TimeAmountEditor.INTERVAL_TYPES.size())).addIntervalTypeItem(any(DateIntervalType.class)); verify(timeAmountView).setSelectedTypeIndex(3); verify(timeAmountView).setQuantity(10); }
@Test public void testNullInitialization() { TimeAmountEditor editor = new TimeAmountEditor(timeAmountView); editor.init(null, changeCommand); verify(timeAmountView).clearIntervalTypeSelector(); verify(timeAmountView, times(TimeAmountEditor.INTERVAL_TYPES.size())).addIntervalTypeItem(any(DateIntervalType.class)); verify(timeAmountView).setSelectedTypeIndex(7); verify(timeAmountView).setQuantity(0); }