-
Notifications
You must be signed in to change notification settings - Fork 29
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
cc88c47
commit e6768b4
Showing
3 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
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
81 changes: 81 additions & 0 deletions
81
checklistview/src/androidTest/java/ChecklistManagerTest.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,81 @@ | ||
import static androidx.test.InstrumentationRegistry.getInstrumentation; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
import android.content.Context; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
import androidx.test.runner.AndroidJUnit4; | ||
import it.feio.android.checklistview.exceptions.ViewNotSupportedException; | ||
import it.feio.android.checklistview.models.CheckListView; | ||
import it.feio.android.checklistview.models.CheckListViewItem; | ||
import it.feio.android.checklistview.models.ChecklistManager; | ||
import it.feio.android.checklistview.test.R; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class ChecklistManagerTest { | ||
|
||
private Context context; | ||
private ChecklistManager checklistManager; | ||
private EditText editText; | ||
|
||
@Before | ||
public void setUp () { | ||
context = getInstrumentation().getContext(); | ||
checklistManager = new ChecklistManager(context); | ||
editText = new EditText(context); | ||
editText.setText(R.string.template_phrase); | ||
} | ||
|
||
@Test | ||
public void convert_toList () throws ViewNotSupportedException { | ||
View view = checklistManager.convert(editText); | ||
|
||
assertEquals(CheckListView.class, view.getClass()); | ||
assertEquals( | ||
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", | ||
((CheckListView) view).getChildAt(1).getText()); | ||
} | ||
|
||
@Test | ||
public void convert_toText () throws ViewNotSupportedException { | ||
View view = checklistManager.convert(checklistManager.convert(editText)); | ||
|
||
assertEquals(EditText.class, view.getClass()); | ||
assertEquals(context.getResources().getString(R.string.template_phrase), ((EditText) view).getText().toString()); | ||
} | ||
|
||
@Test | ||
public void getCheckedCount () throws ViewNotSupportedException { | ||
CheckListView checkListView = (CheckListView) checklistManager.convert(editText); | ||
checkItem(checkListView, 0); | ||
checkItem(checkListView, 2); | ||
|
||
assertEquals(2, checklistManager.getCheckedCount()); | ||
} | ||
|
||
@Test | ||
public void moveCheckedToBottom () throws ViewNotSupportedException { | ||
CheckListView checkListView = (CheckListView) checklistManager.convert(editText); | ||
CheckListViewItem item = checkListView.getChildAt(0); | ||
checkItem(checkListView, 0); | ||
|
||
assertEquals(item, checkListView.getChildAt(0)); | ||
|
||
checklistManager.moveCheckedToBottom(); | ||
|
||
assertNotEquals(item, checkListView.getChildAt(0)); | ||
assertEquals(item, checkListView.getChildAt(checkListView.getChildCount() - 1)); | ||
} | ||
|
||
private void checkItem (CheckListView checkListView, int i) { | ||
CheckListViewItem item = checkListView.getChildAt(i); | ||
item.getCheckBox().setChecked(true); | ||
checkListView.onItemChecked(item, true); | ||
} | ||
|
||
} |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="template_phrase">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</string> | ||
|
||
</resources> |