Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Apr 18, 2024
1 parent 02b453c commit 74c8e40
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import static org.odk.collect.android.utilities.Appearances.MASKED;
import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP;

import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;

public class DecimalWidgetTest extends GeneralStringWidgetTest<DecimalWidget, DecimalData> {

private final Random random = new Random();
Expand Down Expand Up @@ -205,4 +210,21 @@ public void separatorsShouldBeAddedWhenEnabled() {
assertEquals("123,456,789.54", getWidget().widgetAnswerText.getBinding().editText.getText().toString());
assertEquals("123,456,789.54", getWidget().widgetAnswerText.getBinding().textView.getText().toString());
}

@Override
@Test
public void verifyInputType() {
DecimalWidget widget = getWidget();
assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class));
}

@Override
@Test
public void verifyInputTypeWithMaskedAppearance() {
when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED);
DecimalWidget widget = getWidget();
assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_VARIATION_PASSWORD));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import static org.odk.collect.android.utilities.Appearances.MASKED;
import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP;

import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;

/**
* @author James Knight
*/
Expand Down Expand Up @@ -88,4 +93,23 @@ public void separatorsShouldBeAddedWhenEnabled() {
assertEquals("123,456,789.54", getWidget().binding.widgetAnswerText.getBinding().editText.getText().toString());
assertEquals("123,456,789.54", getWidget().binding.widgetAnswerText.getBinding().textView.getText().toString());
}

@Override
@Test
public void verifyInputType() {
ExDecimalWidget widget = getWidget();
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL));
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class));
assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null));
}

@Override
@Test
public void verifyInputTypeWithMaskedAppearance() {
when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED);
ExDecimalWidget widget = getWidget();
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_VARIATION_PASSWORD));
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
import org.odk.collect.android.widgets.utilities.StringRequester;

import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;
import static org.odk.collect.android.utilities.Appearances.MASKED;
import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP;

import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;

/**
* @author James Knight
*/
Expand Down Expand Up @@ -60,4 +67,23 @@ public void separatorsShouldBeAddedWhenEnabled() {
assertEquals("123,456,789", getWidget().binding.widgetAnswerText.getBinding().editText.getText().toString());
assertEquals("123,456,789", getWidget().binding.widgetAnswerText.getBinding().textView.getText().toString());
}

@Override
@Test
public void verifyInputType() {
ExIntegerWidget widget = getWidget();
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED));
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class));
assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null));
}

@Override
@Test
public void verifyInputTypeWithMaskedAppearance() {
when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED);
ExIntegerWidget widget = getWidget();
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_VARIATION_PASSWORD));
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@

import net.bytebuddy.utility.RandomString;

import org.hamcrest.CoreMatchers;
import org.javarosa.core.model.data.StringData;
import org.junit.Test;
import org.mockito.Mock;
import org.odk.collect.android.formentry.questions.QuestionDetails;
import org.odk.collect.android.widgets.base.GeneralExStringWidgetTest;
import org.odk.collect.android.widgets.support.FakeWaitingForDataRegistry;
import org.odk.collect.android.widgets.utilities.StringRequester;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.when;
import static org.odk.collect.android.utilities.Appearances.MASKED;

import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;

/**
* @author James Knight
Expand Down Expand Up @@ -39,4 +48,23 @@ public void setUp() throws Exception {
super.setUp();
when(formEntryPrompt.getAppearanceHint()).thenReturn("");
}

@Override
@Test
public void verifyInputType() {
ExStringWidget widget = getWidget();
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT));
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), CoreMatchers.equalTo(SingleLineTransformationMethod.class));
assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null));
}

@Override
@Test
public void verifyInputTypeWithMaskedAppearance() {
when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED);
ExStringWidget widget = getWidget();
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD));
assertThat(widget.binding.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
assertThat(widget.binding.widgetAnswerText.getBinding().textView.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
import org.odk.collect.android.widgets.base.GeneralStringWidgetTest;

import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;
import static org.odk.collect.android.utilities.Appearances.MASKED;
import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP;

import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;

/**
* @author James Knight
*/
Expand Down Expand Up @@ -47,4 +54,21 @@ public void separatorsShouldBeAddedWhenEnabled() {
assertEquals("123,456,789", getWidget().widgetAnswerText.getBinding().editText.getText().toString());
assertEquals("123,456,789", getWidget().widgetAnswerText.getBinding().textView.getText().toString());
}

@Override
@Test
public void verifyInputType() {
IntegerWidget widget = getWidget();
assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class));
}

@Override
@Test
public void verifyInputTypeWithMaskedAppearance() {
when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED);
IntegerWidget widget = getWidget();
assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_VARIATION_PASSWORD));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
import org.odk.collect.android.widgets.base.GeneralStringWidgetTest;

import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.when;
import static org.odk.collect.android.utilities.Appearances.MASKED;
import static org.odk.collect.android.utilities.Appearances.THOUSANDS_SEP;

import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;

/**
* @author James Knight
*/
Expand Down Expand Up @@ -45,4 +52,21 @@ public void separatorsShouldBeAddedWhenEnabled() {
assertEquals("123,456,789,123,456,789,123,456,789,123,456,789", getWidget().widgetAnswerText.getBinding().editText.getText().toString());
assertEquals("123,456,789,123,456,789,123,456,789,123,456,789", getWidget().widgetAnswerText.getBinding().textView.getText().toString());
}

@Override
@Test
public void verifyInputType() {
StringNumberWidget widget = getWidget();
assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class));
}

@Override
@Test
public void verifyInputTypeWithMaskedAppearance() {
when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED);
StringNumberWidget widget = getWidget();
assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package org.odk.collect.android.widgets;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.when;
import static org.odk.collect.android.utilities.Appearances.MASKED;

import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.text.method.SingleLineTransformationMethod;

import androidx.annotation.NonNull;

import net.bytebuddy.utility.RandomString;

import org.javarosa.core.model.data.StringData;
import org.junit.Test;
import org.odk.collect.android.formentry.questions.QuestionDetails;
import org.odk.collect.android.widgets.base.GeneralStringWidgetTest;

Expand All @@ -24,4 +34,22 @@ public StringWidget createWidget() {
public StringData getNextAnswer() {
return new StringData(RandomString.make());
}

@Override
@Test
public void verifyInputType() {
StringWidget widget = getWidget();
assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(SingleLineTransformationMethod.class));
assertThat(widget.widgetAnswerText.getBinding().textView.getTransformationMethod(), equalTo(null));
}

@Override
@Test
public void verifyInputTypeWithMaskedAppearance() {
when(formEntryPrompt.getAppearanceHint()).thenReturn(MASKED);
StringWidget widget = getWidget();
assertThat(widget.widgetAnswerText.getBinding().editText.getInputType(), equalTo(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD));
assertThat(widget.widgetAnswerText.getBinding().editText.getTransformationMethod().getClass(), equalTo(PasswordTransformationMethod.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,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 abstract void verifyInputType();

@Test
public abstract void verifyInputTypeWithMaskedAppearance();
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,10 @@ 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 abstract void verifyInputType();

@Test
public abstract void verifyInputTypeWithMaskedAppearance();
}

0 comments on commit 74c8e40

Please sign in to comment.