-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdf0859
commit 7907d40
Showing
8 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...sts/src/androidTest/java/com/mobsandgeeks/saripaar/tests/QuickRuleOnlyControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2015 Mobs & Geeks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.mobsandgeeks.saripaar.tests; | ||
|
||
import android.test.ActivityInstrumentationTestCase2; | ||
import android.widget.TextView; | ||
|
||
import com.mobsandgeeks.saripaar.tests.ui.QuickRuleOnlyControllerActivity; | ||
|
||
public class QuickRuleOnlyControllerTest | ||
extends ActivityInstrumentationTestCase2<QuickRuleOnlyControllerActivity> { | ||
|
||
private TextView mResultTextView; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
mResultTextView = (TextView) getActivity().findViewById(R.id.resultTextView); | ||
} | ||
|
||
public void testInputNot1_failure() { | ||
EspressoHelper.type(R.id.oneOnlyEditText, "100"); | ||
EspressoHelper.clickView(R.id.saripaarButton); | ||
EspressoHelper.checkForText(Constants.STATE_FAILURE, mResultTextView); | ||
} | ||
|
||
public void testInput1_success() { | ||
EspressoHelper.type(R.id.oneOnlyEditText, "1"); | ||
EspressoHelper.clickView(R.id.saripaarButton); | ||
EspressoHelper.checkForText(Constants.STATE_SUCCESS, mResultTextView); | ||
} | ||
|
||
public QuickRuleOnlyControllerTest() { | ||
super(QuickRuleOnlyControllerActivity.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...sts/src/main/java/com/mobsandgeeks/saripaar/tests/ui/QuickRuleOnlyControllerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (C) 2015 Mobs & Geeks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.mobsandgeeks.saripaar.tests.ui; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
|
||
import com.mobsandgeeks.saripaar.QuickRule; | ||
import com.mobsandgeeks.saripaar.ValidationError; | ||
import com.mobsandgeeks.saripaar.Validator; | ||
import com.mobsandgeeks.saripaar.tests.R; | ||
|
||
import java.util.List; | ||
|
||
|
||
public class QuickRuleOnlyControllerActivity extends Activity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
// Set content view | ||
LayoutInflater layoutInflater = LayoutInflater.from(this); | ||
View view = layoutInflater.inflate(R.layout.activity_quick_rule_only, null); | ||
setContentView(view); | ||
|
||
// Controller | ||
new Controller(view); | ||
} | ||
|
||
static class Controller implements View.OnClickListener, Validator.ValidationListener { | ||
// UI | ||
private EditText mOneOnlyEditText; | ||
private TextView mResultTextView; | ||
private Button mSaripaarButton; | ||
|
||
// Attributes | ||
private Validator mValidator; | ||
|
||
Controller(final View rootView) { | ||
// UI | ||
mOneOnlyEditText = (EditText) rootView.findViewById(R.id.oneOnlyEditText); | ||
mResultTextView = (TextView) rootView.findViewById(R.id.resultTextView); | ||
mSaripaarButton = (Button) rootView.findViewById(R.id.saripaarButton); | ||
|
||
// Validation | ||
mValidator = new Validator(this); | ||
mValidator.setValidationListener(this); | ||
|
||
// Add a quick rule | ||
mValidator.put(mOneOnlyEditText, new QuickRule<TextView>() { | ||
|
||
@Override | ||
public boolean isValid(TextView textView) { | ||
return "1".equals(textView.getText().toString()); | ||
} | ||
|
||
@Override | ||
public String getMessage(Context context) { | ||
return "Enter 1, nothing else."; | ||
} | ||
}); | ||
|
||
// Event listeners | ||
mSaripaarButton.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
try { | ||
mValidator.validate(); | ||
} catch (IllegalStateException e) { | ||
mResultTextView.setText(R.string.crash); | ||
} | ||
} | ||
|
||
@Override | ||
public void onValidationSucceeded() { | ||
mResultTextView.setText(R.string.success); | ||
} | ||
|
||
@Override | ||
public void onValidationFailed(List<ValidationError> errors) { | ||
mResultTextView.setText(R.string.failure); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
saripaar-tests/src/main/res/layout/activity_quick_rule_only_controller.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:id="@+id/root"> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Saripaar!" | ||
android:id="@+id/saripaarButton" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentEnd="true"/> | ||
|
||
<EditText | ||
android:id="@+id/oneOnlyEditText" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:inputType="textPassword" | ||
android:hint="1 Only" | ||
android:ems="10" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentEnd="true"/> | ||
|
||
<TextView | ||
android:id="@+id/resultTextView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:layout_below="@+id/oneOnlyEditText" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_above="@+id/saripaarButton" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentEnd="true" | ||
android:gravity="center"/> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/RadioGroupBooleanAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters