use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.
the class DecimalWidgetTest method decimalValueShouldNotAddPrecision.
@Test
public // that precision. For example, 9.00 becomes 9
void decimalValueShouldNotAddPrecision() {
Double twoDecimalDouble = 9.99;
String twoDecimalString = "9.99";
when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
when(answerData.getValue()).thenReturn(twoDecimalDouble);
DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
assertThat(decimalWidget.getAnswerText(), is(equalTo(twoDecimalString)));
decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
assertThat(decimalWidget.getAnswerText(), is(equalTo(twoDecimalString)));
}
use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.
the class DaylightSavingTest method prepareDateTimeWidget.
private DateTimeWidget prepareDateTimeWidget(int year, int month, int day, int hour, int minute) {
QuestionDef questionDefStub = mock(QuestionDef.class);
FormEntryPrompt formEntryPromptStub = new MockFormEntryPromptBuilder().withIndex("index").build();
IFormElement iformElementStub = formEntryPromptStub.getFormElement();
when(iformElementStub.getAdditionalAttribute(anyString(), anyString())).thenReturn(null);
when(formEntryPromptStub.getQuestion()).thenReturn(questionDefStub);
when(formEntryPromptStub.getFormElement()).thenReturn(iformElementStub);
when(formEntryPromptStub.getQuestion().getAppearanceAttr()).thenReturn("no-calendar");
DateTimeWidget dateTimeWidget = new DateTimeWidget(widgetActivity, new QuestionDetails(formEntryPromptStub), widgetUtils);
dateTimeWidget.setData(new LocalDateTime().withDate(year, month, day));
dateTimeWidget.setData(new DateTime().withTime(hour, minute, 0, 0));
return dateTimeWidget;
}
use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.
the class DaylightSavingTest method prepareDateWidget.
private DateWidget prepareDateWidget(int year, int month, int day) {
QuestionDef questionDefStub = mock(QuestionDef.class);
FormEntryPrompt formEntryPromptStub = new MockFormEntryPromptBuilder().withIndex("index").build();
IFormElement iformElementStub = formEntryPromptStub.getFormElement();
when(iformElementStub.getAdditionalAttribute(anyString(), anyString())).thenReturn(null);
when(formEntryPromptStub.getQuestion()).thenReturn(questionDefStub);
when(formEntryPromptStub.getFormElement()).thenReturn(iformElementStub);
when(formEntryPromptStub.getQuestion().getAppearanceAttr()).thenReturn("no-calendar");
DatePickerDialog datePickerDialog = mock(DatePickerDialog.class);
DatePicker datePicker = mock(DatePicker.class);
when(datePickerDialog.getDatePicker()).thenReturn(datePicker);
when(datePickerDialog.getDatePicker().getYear()).thenReturn(year);
when(datePickerDialog.getDatePicker().getMonth()).thenReturn(month);
when(datePickerDialog.getDatePicker().getDayOfMonth()).thenReturn(day);
return new DateWidget(widgetActivity, new QuestionDetails(formEntryPromptStub), widgetUtils);
}
use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.
the class DecimalWidgetTest method digitsAboveLimitOfFifteenShouldBeTruncatedFromRight.
@Test
public // This should never be possible because the EditText has a limit on it
void digitsAboveLimitOfFifteenShouldBeTruncatedFromRight() {
Double eighteenDigitDouble = 9999999999999994.;
String fifteenDigitString = "999999999999994";
assertSame(15, fifteenDigitString.length());
when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
when(answerData.getValue()).thenReturn(eighteenDigitDouble);
DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitString)));
decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitString)));
}
use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.
the class DecimalWidgetTest method integerValueShouldDisplayNoDecimalPoint.
@Test
public // Fails when double is turned to string with toString or String.format(Locale.US, "%f", d))
void integerValueShouldDisplayNoDecimalPoint() {
Double integerDouble = 0.;
String integerString = "0";
when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
when(answerData.getValue()).thenReturn(integerDouble);
DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
assertThat(decimalWidget.getAnswerText(), is(equalTo(integerString)));
decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
assertThat(decimalWidget.getAnswerText(), is(equalTo(integerString)));
}
Aggregations