CurrencyConverterViewModel extends ViewModel<Void, CurrencyConverterModel> { public void calculate() { String inputString = model.input.get(); float input = Float.parseFloat(inputString); DecimalFormat decimalFormat = new DecimalFormat("0.00", DecimalFormatSymbols.getInstance(Locale.US)); model.output.set(decimalFormat.format(input * rateLoader.loadRate())); } CurrencyConverterViewModel(RateLoader rateLoader); @NonNull @Override CurrencyConverterModel createModel(); void calculate();  }
@Test public void testConvertCurrency() { when(rateLoader.loadRate()).thenReturn(2f); CurrencyConverterModel model = viewModel.initAndResume(); model.input.set("123"); viewModel.calculate(); assertThat(model.output.get()).isEqualTo("246.00"); }