Skip to content

Commit

Permalink
Added new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Jul 18, 2024
1 parent 314c41c commit 54e27a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ public void answersShouldBeMaskedIfMaskedAppearanceIsUsed() {
assertThat(getSpyWidget().binding.widgetAnswerText.getBinding().editText.getTransformationMethod(), is(instanceOf(PasswordTransformationMethod.class)));
assertThat(getSpyWidget().binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), is(instanceOf(PasswordTransformationMethod.class)));
}

@Test
public void whenNumberOfRowsSpecifiedEditTextShouldHaveProperNumberOfMinLines() {
when(questionDef.getAdditionalAttribute(null, "rows")).thenReturn("5");
assertThat(getSpyWidget().binding.widgetAnswerText.getBinding().editText.getMinLines(), equalTo(5));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@ public void answersShouldBeMaskedIfMaskedAppearanceIsUsed() {
assertThat(getSpyWidget().widgetAnswerText.getBinding().editText.getTransformationMethod(), is(instanceOf(PasswordTransformationMethod.class)));
assertThat(getSpyWidget().widgetAnswerText.getBinding().textView.getTransformationMethod(), is(instanceOf(PasswordTransformationMethod.class)));
}

@Test
public void whenNumberOfRowsSpecifiedEditTextShouldHaveProperNumberOfMinLines() {
when(questionDef.getAdditionalAttribute(null, "rows")).thenReturn("5");
StringWidget widget = getWidget();
assertThat(widget.widgetAnswerText.getBinding().editText.getMinLines(), equalTo(5));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import android.view.View;

import org.javarosa.core.model.QuestionDef;
import org.javarosa.core.model.data.IAnswerData;
import org.junit.Test;
import org.mockito.Mock;
import org.odk.collect.android.R;
import org.odk.collect.android.support.WidgetTestActivity;
import org.odk.collect.android.widgets.StringWidget;
Expand All @@ -25,15 +23,6 @@
public abstract class GeneralStringWidgetTest<W extends StringWidget, A extends IAnswerData>
extends QuestionWidgetTest<W, A> {

@Mock
QuestionDef questionDef;

@Override
public void setUp() throws Exception {
super.setUp();
when(formEntryPrompt.getQuestion()).thenReturn(questionDef);
}

@Override
public void callingClearShouldRemoveTheExistingAnswer() {
super.callingClearShouldRemoveTheExistingAnswer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public abstract class WidgetTest {

protected final SettingsProvider settingsProvider = TestSettingsProvider.getSettingsProvider();

@Mock
protected QuestionDef questionDef;

@Before
@OverridingMethodsMustInvokeSuper
public void setUp() throws Exception {
Expand All @@ -48,7 +51,7 @@ public void setUp() throws Exception {
when(formEntryPrompt.getIndex()).thenReturn(mock(FormIndex.class));
when(formEntryPrompt.getIndex().toString()).thenReturn("0, 0");
when(formEntryPrompt.getFormElement()).thenReturn(formElement);
when(formEntryPrompt.getQuestion()).thenReturn(mock(QuestionDef.class));
when(formEntryPrompt.getQuestion()).thenReturn(questionDef);
}

@Test
Expand Down

0 comments on commit 54e27a0

Please sign in to comment.