Skip to content

Commit

Permalink
Validate number of columns, it should be between 1 and 10
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed May 21, 2019
1 parent 1e419ca commit 210fa04
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public static int getNumberOfColumns(FormEntryPrompt formEntryPrompt, Context co
numColumns = Integer.parseInt(substringFromNumColumns.substring(0, substringFromNumColumns.contains(" ")
? substringFromNumColumns.indexOf(' ')
: substringFromNumColumns.length()));

if (numColumns < 1) {
numColumns = 1;
} else if (numColumns > 10) {
numColumns = 10;
}
}
} catch (Exception e) {
Timber.e(EXCEPTION_PARSING_COLUMNS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,23 @@ public void getNumberOfColumnsTest() {

when(formEntryPrompt.getAppearanceHint()).thenReturn("compact-5");
assertEquals(5, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("compact-9");
assertEquals(9, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-9");
assertEquals(9, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("compact-11");
assertEquals(10, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-11");
assertEquals(10, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("columns--1");
assertEquals(1, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));

when(formEntryPrompt.getAppearanceHint()).thenReturn("columns--10");
assertEquals(1, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null));
}
}

0 comments on commit 210fa04

Please sign in to comment.