How to use isNull method of org.mockito.ArgumentMatchers class

Best Mockito code snippet using org.mockito.ArgumentMatchers.isNull

Source:CommonRepositoryTest.java Github

copy

Full Screen

...68 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);69 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);70 commonRepository.updateMasterRepository(repository);71 commonRepository.add(new CommonPersonObject("", "", new HashMap<String, String>(), ""));72 Mockito.verify(sqliteDatabase, Mockito.times(1)).insert(Mockito.anyString(), Mockito.isNull(String.class), Mockito.any(ContentValues.class));73 }74 @Test75 public void findByCaseIDCallsDatabaseQuery1times() throws Exception {76 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};77 MatrixCursor matrixCursor = new MatrixCursor(columns);78 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});79 String tablename = "";80 String[] tableColumns = new String[]{};81 commonRepository = new CommonRepository(tablename, tableColumns);82 repository = Mockito.mock(Repository.class);83 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);84 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);85 commonRepository.updateMasterRepository(repository);86 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);87 Assert.assertNotNull(commonRepository.findByCaseID(""));88 Mockito.verify(sqliteDatabase, Mockito.times(1)).query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class));89 }90 @Test91 public void findByBaseEntityIdCallsDatabaseQuery1times() throws Exception {92 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};93 MatrixCursor matrixCursor = new MatrixCursor(columns);94 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});95 String tablename = "";96 String[] tableColumns = new String[]{};97 commonRepository = new CommonRepository(tablename, tableColumns);98 repository = Mockito.mock(Repository.class);99 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);100 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);101 commonRepository.updateMasterRepository(repository);102 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);103 Assert.assertNotNull(commonRepository.findByBaseEntityId(""));104 Mockito.verify(sqliteDatabase, Mockito.times(1)).query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class));105 }106 @Test107 public void findByGOBHHIDCallsDatabaseQuery1times() throws Exception {108 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};109 MatrixCursor matrixCursor = new MatrixCursor(columns);110 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});111 String tablename = "";112 String[] tableColumns = new String[]{};113 commonRepository = new CommonRepository(tablename, tableColumns);114 repository = Mockito.mock(Repository.class);115 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);116 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);117 commonRepository.updateMasterRepository(repository);118 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);119 Assert.assertNotNull(commonRepository.findHHByGOBHHID(""));120 Mockito.verify(sqliteDatabase, Mockito.times(1)).query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class));121 }122 @Test123 public void allcommonCallsDatabaseQuery1times() throws Exception {124 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};125 MatrixCursor matrixCursor = new MatrixCursor(columns);126 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});127 String tablename = "";128 String[] tableColumns = new String[]{};129 commonRepository = new CommonRepository(tablename, tableColumns);130 repository = Mockito.mock(Repository.class);131 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);132 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);133 commonRepository.updateMasterRepository(repository);134 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);135 Assert.assertNotNull(commonRepository.allcommon());136 Mockito.verify(sqliteDatabase, Mockito.times(1)).query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class));137 }138 @Test139 public void findByCaseIDsCallsDatabaseQuery1times() throws Exception {140 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};141 MatrixCursor matrixCursor = new MatrixCursor(columns);142 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});143 matrixCursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});144 String tablename = "";145 String[] tableColumns = new String[]{};146 commonRepository = new CommonRepository(tablename, tableColumns);147 repository = Mockito.mock(Repository.class);148 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);149 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);150 commonRepository.updateMasterRepository(repository);151 Mockito.when(sqliteDatabase.rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class))).thenReturn(matrixCursor);152 Assert.assertNotNull(commonRepository.findByCaseIDs("caseID1", "caseID2"));153 Mockito.verify(sqliteDatabase, Mockito.times(1)).rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));154 }155 @Test156 public void findByRelationalIDsCallsDatabaseQuery1times() throws Exception {157 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};158 MatrixCursor matrixCursor = new MatrixCursor(columns);159 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});160 matrixCursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});161 String tablename = "";162 String[] tableColumns = new String[]{};163 commonRepository = new CommonRepository(tablename, tableColumns);164 repository = Mockito.mock(Repository.class);165 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);166 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);167 commonRepository.updateMasterRepository(repository);168 Mockito.when(sqliteDatabase.rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class))).thenReturn(matrixCursor);169 Assert.assertNotNull(commonRepository.findByRelationalIDs("relationalID", "relationalID2"));170 Mockito.verify(sqliteDatabase, Mockito.times(1)).rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));171 }172 @Test173 public void findByRelational_IDsCallsDatabaseQuery1times() throws Exception {174 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};175 MatrixCursor matrixCursor = new MatrixCursor(columns);176 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});177 matrixCursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});178 String tablename = "";179 String[] tableColumns = new String[]{};180 commonRepository = new CommonRepository(tablename, tableColumns);181 repository = Mockito.mock(Repository.class);182 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);183 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);184 commonRepository.updateMasterRepository(repository);185 Mockito.when(sqliteDatabase.rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class))).thenReturn(matrixCursor);186 Assert.assertNotNull(commonRepository.findByRelational_IDs("relationalID", "relationalID2"));187 Mockito.verify(sqliteDatabase, Mockito.times(1)).rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));188 }189 @Test190 public void customQueryReturnsNotNUll() throws Exception {191 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};192 MatrixCursor matrixCursor = new MatrixCursor(columns);193 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});194 matrixCursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});195 String tablename = "";196 String[] tableColumns = new String[]{};197 commonRepository = new CommonRepository(tablename, tableColumns);198 repository = Mockito.mock(Repository.class);199 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);200 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);201 commonRepository.updateMasterRepository(repository);202 Mockito.when(sqliteDatabase.rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class))).thenReturn(matrixCursor);203 Assert.assertNotNull(commonRepository.customQuery("", new String[]{}, ""));204 Mockito.verify(sqliteDatabase, Mockito.times(1)).rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));205 }206 @Test207 public void customQueryForCompleteRowReturnsNotNUll() throws Exception {208 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};209 MatrixCursor matrixCursor = new MatrixCursor(columns);210 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});211 matrixCursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});212 String tablename = "";213 String[] tableColumns = new String[]{};214 commonRepository = new CommonRepository(tablename, tableColumns);215 repository = Mockito.mock(Repository.class);216 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);217 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);218 commonRepository.updateMasterRepository(repository);219 Mockito.when(sqliteDatabase.rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class))).thenReturn(matrixCursor);220 Assert.assertNotNull(commonRepository.customQueryForCompleteRow("", new String[]{}, ""));221 Mockito.verify(sqliteDatabase, Mockito.times(1)).rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));222 }223 @Test224 public void rawCustomQueryForAdapterRowReturnsNotNUll() throws Exception {225 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};226 MatrixCursor matrixCursor = new MatrixCursor(columns);227 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});228 matrixCursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});229 String tablename = "";230 String[] tableColumns = new String[]{};231 commonRepository = new CommonRepository(tablename, tableColumns);232 repository = Mockito.mock(Repository.class);233 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);234 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);235 commonRepository.updateMasterRepository(repository);236 Mockito.when(sqliteDatabase.rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String[].class))).thenReturn(matrixCursor);237 Assert.assertNotNull(commonRepository.rawCustomQueryForAdapter(""));238 Mockito.verify(sqliteDatabase, Mockito.times(1)).rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String[].class));239 }240 @Test241 public void readAllcommonforCursorAdapterReturnsNotNUll() throws Exception {242 String[] columns = new String[]{"_id", "relationalid", "details", "is_closed"};243 MatrixCursor matrixCursor = new MatrixCursor(columns);244 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});245 matrixCursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});246 String tablename = "";247 String[] tableColumns = new String[]{};248 commonRepository = new CommonRepository(tablename, tableColumns);249 matrixCursor.moveToFirst();250 Assert.assertNotNull(commonRepository.readAllcommonforCursorAdapter(matrixCursor));251 }252 @Test253 public void readAllcommonforFieldReturnsNotNUll() throws Exception {254 String[] columns = new String[]{"_id", "relationalid", "details", "is_closed"};255 MatrixCursor matrixCursor = new MatrixCursor(columns);256 matrixCursor.addRow(new Object[]{0, 0, 0, 0});257 matrixCursor.addRow(new Object[]{1, 1, 1, 1});258 String tablename = "";259 String[] tableColumns = new String[]{};260 commonRepository = new CommonRepository(tablename, tableColumns);261 matrixCursor.moveToFirst();262 Assert.assertNotNull(commonRepository.readAllcommonForField(matrixCursor, ""));263 }264 @Test265 public void updateDetailsCallsDatabaseUpdate1Times() throws Exception {266 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};267 MatrixCursor matrixCursor = new MatrixCursor(columns);268 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});269 matrixCursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});270 String tablename = "";271 String[] tableColumns = new String[]{};272 commonRepository = new CommonRepository(tablename, tableColumns);273 repository = Mockito.mock(Repository.class);274 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);275 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);276 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);277 commonRepository.updateMasterRepository(repository);278 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);279 commonRepository.updateDetails("caseID", new HashMap<String, String>());280 Mockito.verify(sqliteDatabase, Mockito.times(1)).update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));281 }282 @Test283 public void mergeDetailsCallsDatabaseUpdate1Times() throws Exception {284 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};285 MatrixCursor matrixCursor = new MatrixCursor(columns);286 matrixCursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});287 matrixCursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});288 String tablename = "";289 String[] tableColumns = new String[]{};290 commonRepository = new CommonRepository(tablename, tableColumns);291 repository = Mockito.mock(Repository.class);292 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);293 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);294 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);295 commonRepository.updateMasterRepository(repository);296 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);297 commonRepository.mergeDetails("caseID", new HashMap<String, String>());298 Mockito.verify(sqliteDatabase, Mockito.times(1)).update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));299 }300 @Test301 public void assertOnCreateCallsDatabaseExec() {302 String tablename = "";303 String[] tableColumns = new String[]{CommonRepository.Relational_Underscore_ID, CommonRepository.BASE_ENTITY_ID_COLUMN, ADDITIONALCOLUMN, CUSTOMRELATIONALID};304 commonFtsObject = Mockito.mock(CommonFtsObject.class);305 Mockito.when(commonFtsObject.getCustomRelationalId(Mockito.anyString())).thenReturn(CUSTOMRELATIONALID);306 CommonRepository commonRepository = new CommonRepository(commonFtsObject, tablename, tableColumns);307 Assert.assertNotNull(commonRepository);308 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);309 repository = Mockito.mock(Repository.class);310 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);311 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);312 commonRepository.onCreate(sqliteDatabase);313 Mockito.verify(sqliteDatabase, Mockito.times(6)).execSQL(Mockito.anyString());314 }315 @Test316 public void assertExecuteInsertStatementReturnsId() throws Exception {317 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};318 MatrixCursor cursor = new MatrixCursor(columns);319 cursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});320 cursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});321 String tablename = "table";322 String[] tableColumns = new String[]{CommonRepository.Relational_Underscore_ID, CommonRepository.BASE_ENTITY_ID_COLUMN, ADDITIONALCOLUMN, CUSTOMRELATIONALID};323 commonFtsObject = Mockito.mock(CommonFtsObject.class);324 Mockito.when(commonFtsObject.getCustomRelationalId(Mockito.anyString())).thenReturn(CUSTOMRELATIONALID);325 CommonRepository commonRepository = new CommonRepository(commonFtsObject, tablename, tableColumns);326 Assert.assertNotNull(commonRepository);327 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);328 repository = Mockito.mock(Repository.class);329 String baseEntityId = "1";330 String query =331 "SELECT * FROM " + tablename + " WHERE base_entity_id = ?";332 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);333 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);334 Mockito.when(sqliteDatabase.rawQuery(query, new String[]{baseEntityId})).thenReturn(cursor);335 ContentValues cv = new ContentValues();336 cv.put("base_entity_id", "1");337 commonRepository.updateMasterRepository(repository);338 Long id = 0l;339 Assert.assertEquals(commonRepository.executeInsertStatement(cv, tablename), id);340 Mockito.verify(sqliteDatabase, Mockito.times(1)).insertWithOnConflict(Mockito.anyString(), Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyInt());341 Mockito.verify(sqliteDatabase, Mockito.times(1)).rawQuery(query, new String[]{"1"});342 }343 @Test344 public void assertQueryTableReturnsCursor() throws Exception {345 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};346 MatrixCursor cursor = new MatrixCursor(columns);347 cursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});348 cursor.addRow(new Object[]{"caseID2", "relationalID2", new HashMap<String, String>(), 0});349 String tablename = "table";350 String[] tableColumns = new String[]{CommonRepository.Relational_Underscore_ID, CommonRepository.BASE_ENTITY_ID_COLUMN, ADDITIONALCOLUMN, CUSTOMRELATIONALID};351 commonFtsObject = Mockito.mock(CommonFtsObject.class);352 Mockito.when(commonFtsObject.getCustomRelationalId(Mockito.anyString())).thenReturn(CUSTOMRELATIONALID);353 CommonRepository commonRepository = new CommonRepository(commonFtsObject, tablename, tableColumns);354 Assert.assertNotNull(commonRepository);355 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);356 repository = Mockito.mock(Repository.class);357 String baseEntityId = "1";358 String query =359 "SELECT * FROM " + tablename + " WHERE base_entity_id = '" + baseEntityId + "'";360 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);361 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);362 Mockito.when(sqliteDatabase.rawQuery(query, null)).thenReturn(cursor);363 commonRepository.updateMasterRepository(repository);364 org.junit.Assert.assertEquals(commonRepository.queryTable(query), cursor);365 Mockito.verify(sqliteDatabase, Mockito.times(1)).rawQuery(query, null);366 }367 @Test368 public void assertCloseCaseCallsDatabaseExec() {369 String tablename = "table";370 String baseEntityId = "1";371 String[] tableColumns = new String[]{CommonRepository.Relational_Underscore_ID, CommonRepository.BASE_ENTITY_ID_COLUMN, ADDITIONALCOLUMN, CUSTOMRELATIONALID};372 commonFtsObject = Mockito.mock(CommonFtsObject.class);373 CommonRepository commonRepository = new CommonRepository(commonFtsObject, tablename, tableColumns);374 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);375 repository = Mockito.mock(Repository.class);376 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);377 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);378 commonRepository.closeCase(baseEntityId, tablename);379 commonRepository.updateMasterRepository(repository);380 commonRepository.closeCase(baseEntityId, tablename);381 Mockito.verify(sqliteDatabase,Mockito.times(1)).update(Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyString(),Mockito.any(String[].class));382 }383 @Test384 public void assertDeleteCaseCallsDatabaseExec() {385 String tablename = "table";386 String baseEntityId = "1";387 String[] tableColumns = new String[]{CommonRepository.Relational_Underscore_ID, CommonRepository.BASE_ENTITY_ID_COLUMN, ADDITIONALCOLUMN, CUSTOMRELATIONALID};388 commonFtsObject = Mockito.mock(CommonFtsObject.class);389 CommonRepository commonRepository = new CommonRepository(commonFtsObject, tablename, tableColumns);390 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);391 repository = Mockito.mock(Repository.class);392 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);393 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);394 Assert.assertEquals(commonRepository.deleteCase(baseEntityId, tablename), false);395 Mockito.when(sqliteDatabase.delete(Mockito.anyString(), Mockito.anyString(), Mockito.any(String[].class))).thenReturn(1);396 commonRepository.updateMasterRepository(repository);397 Assert.assertEquals(commonRepository.deleteCase(baseEntityId, tablename), true);398 }399 @Test400 public void assertRawQueryReturnsMap() {401 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};402 MatrixCursor cursor = new MatrixCursor(columns);403 cursor.addRow(new Object[]{"caseID", "relationalID", "dd1", "0"});404 cursor.addRow(new Object[]{"caseID2", "relationalID2", "dd2", "0"});405 String tablename = "table";406 String[] tableColumns = new String[]{CommonRepository.Relational_Underscore_ID, CommonRepository.BASE_ENTITY_ID_COLUMN, ADDITIONALCOLUMN, CUSTOMRELATIONALID};407 commonFtsObject = Mockito.mock(CommonFtsObject.class);408 Mockito.when(commonFtsObject.getCustomRelationalId(Mockito.anyString())).thenReturn(CUSTOMRELATIONALID);409 CommonRepository commonRepository = new CommonRepository(commonFtsObject, tablename, tableColumns);410 Assert.assertNotNull(commonRepository);411 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);412 repository = Mockito.mock(Repository.class);413 String baseEntityId = "1";414 String query =415 "SELECT * FROM " + tablename + " WHERE base_entity_id = ?";416 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);417 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);418 Mockito.when(sqliteDatabase.rawQuery(query, null)).thenReturn(cursor);419 commonRepository.updateMasterRepository(repository);420 Assert.assertNotNull(commonRepository.rawQuery(query, new String[]{baseEntityId}));421 }422 @Test423 public void assertPopulateSearchValuesByCaseIdReturnsContentValue() {424 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};425 MatrixCursor cursor = new MatrixCursor(columns);426 cursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});427 String tableName = "common";428 String[] tableColumns = new String[]{};429 String[] tables = {"common", "common2"};430 String[] mainConditions = {"details"};431 String[] shortFields = {"id", "alerts.relationalid", "alerts.details", "is_closed"};432 String[] columns2 = new String[]{"id", "name"};433 MatrixCursor cursor2 = new MatrixCursor(columns2);434 cursor2.addRow(new Object[]{"caseID", "details"});435 commonFtsObject = Mockito.mock(CommonFtsObject.class);436 CommonRepository commonRepository = new CommonRepository(commonFtsObject, tableName, tableColumns);437 repository = Mockito.mock(Repository.class);438 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);439 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);440 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);441 commonRepository.updateMasterRepository(repository);442 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);443 Mockito.when(commonFtsObject.getSearchFields(Mockito.anyString())).thenReturn(columns);444 Mockito.when(commonFtsObject.getTables()).thenReturn(tables);445 Mockito.when(commonFtsObject.getMainConditions(Mockito.anyString())).thenReturn(mainConditions);446 Mockito.when(commonFtsObject.getSortFields(Mockito.anyString())).thenReturn(shortFields);447 tableName = "common2";448 String query = "PRAGMA table_info(" + tableName + ")";449 Mockito.when(sqliteDatabase.rawQuery(query, null)).thenReturn(cursor2);450 Assert.assertNotNull(commonRepository.populateSearchValues("caseID"));451 }452 @Test453 public void assertPopulateSearchValuesReturnsContentBoolean() {454 String[] columns = new String[]{"id", "relationalid", "details", "is_closed"};455 MatrixCursor cursor = new MatrixCursor(columns);456 cursor.addRow(new Object[]{"caseID", "relationalID", new HashMap<String, String>(), 0});457 String tableName = "common";458 String[] tableColumns = new String[]{};459 String[] tables = {"common"};460 String[] mainConditions = {"details"};461 String[] shortFields = {"id", "alerts.relationalid", "alerts.details", "is_closed"};462 String[] columns2 = new String[]{"id", "name", CommonFtsObject.phraseColumn};463 MatrixCursor cursor2 = new MatrixCursor(columns2);464 cursor2.addRow(new Object[]{"caseID", "details", "| hello| world"});465 commonFtsObject = Mockito.mock(CommonFtsObject.class);466 CommonRepository commonRepository = new CommonRepository(commonFtsObject, tableName, tableColumns);467 repository = Mockito.mock(Repository.class);468 sqliteDatabase = Mockito.mock(SQLiteDatabase.class);469 Mockito.when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);470 Mockito.when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);471 commonRepository.updateMasterRepository(repository);472 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);473 Mockito.when(commonFtsObject.getSearchFields(Mockito.anyString())).thenReturn(columns);474 Mockito.when(commonFtsObject.getTables()).thenReturn(tables);475 Mockito.when(commonFtsObject.getMainConditions(Mockito.anyString())).thenReturn(mainConditions);476 Mockito.when(commonFtsObject.getSortFields(Mockito.anyString())).thenReturn(shortFields);477 String query = "SELECT object_id, field FROM common_search WHERE object_id = ?";478 Mockito.when(sqliteDatabase.rawQuery(query, new String[]{"caseID"})).thenReturn(cursor2);479 Assert.assertEquals(commonRepository.populateSearchValues("caseID", "field", "value", new String[]{"details"}), false);480 Mockito.when(sqliteDatabase.update(Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyString(), Mockito.any(String[].class))).thenReturn(1);481 query = "SELECT object_id, phrase FROM common_search WHERE object_id = ?";482 Mockito.when(sqliteDatabase.rawQuery(query, new String[]{"caseID"})).thenReturn(cursor2);483 Assert.assertEquals(commonRepository.populateSearchValues("caseID", CommonFtsObject.phraseColumn, "hello_world", new String[]{"hello"}), true);484 }485 @Test486 public void deleteSearchRecordShouldReturnTrueAndCommitTransaction() {...

Full Screen

Full Screen

Source:ArgumentMatchers.java Github

copy

Full Screen

...38 * </code></pre>39 *40 * <p>41 * Since Mockito <code>any(Class)</code> and <code>anyInt</code> family matchers perform a type check, thus they won't42 * match <code>null</code> arguments. Instead use the <code>isNull</code> matcher.43 *44 * <pre class="code"><code class="java">45 * // stubbing using anyBoolean() argument matcher46 * when(mock.dryRun(anyBoolean())).thenReturn("state");47 *48 * // below the stub won't match, and won't return "state"49 * mock.dryRun(null);50 *51 * // either change the stub52 * when(mock.dryRun(isNull())).thenReturn("state");53 * mock.dryRun(null); // ok54 *55 * // or fix the code ;)56 * when(mock.dryRun(anyBoolean())).thenReturn("state");57 * mock.dryRun(true); // ok58 *59 * </code></pre>60 *61 * The same apply for verification.62 * </p>63 *64 *65 * Scroll down to see all methods - full list of matchers.66 *67 * <p>68 * <b>Warning:</b><br/>69 *70 * If you are using argument matchers, <b>all arguments</b> have to be provided by matchers.71 *72 * E.g: (example shows verification but the same applies to stubbing):73 * </p>74 *75 * <pre class="code"><code class="java">76 * verify(mock).someMethod(anyInt(), anyString(), <b>eq("third argument")</b>);77 * //above is correct - eq() is also an argument matcher78 *79 * verify(mock).someMethod(anyInt(), anyString(), <b>"third argument"</b>);80 * //above is incorrect - exception will be thrown because third argument is given without argument matcher.81 * </code></pre>82 *83 * <p>84 * Matcher methods like <code>anyObject()</code>, <code>eq()</code> <b>do not</b> return matchers.85 * Internally, they record a matcher on a stack and return a dummy value (usually null).86 * This implementation is due static type safety imposed by java compiler.87 * The consequence is that you cannot use <code>anyObject()</code>, <code>eq()</code> methods outside of verified/stubbed method.88 * </p>89 *90 * <h1>Custom Argument ArgumentMatchers</h1>91 * <p>92 * It is important to understand the use cases and available options for dealing with non-trivial arguments93 * <b>before</b> implementing custom argument matchers. This way, you can select the best possible approach94 * for given scenario and produce highest quality test (clean and maintainable).95 * Please read on in the javadoc for {@link ArgumentMatcher} to learn about approaches and see the examples.96 * </p>97 */98@SuppressWarnings("unchecked")99public class ArgumentMatchers {100 /**101 * Matches <strong>anything</strong>, including nulls and varargs.102 *103 * <p>104 * See examples in javadoc for {@link ArgumentMatchers} class105 *106 * This is an alias of: {@link #anyObject()} and {@link #any(java.lang.Class)}107 * </p>108 *109 * <p>110 * <strong>Notes : </strong><br/>111 * <ul>112 * <li>For primitive types use {@link #anyChar()} family or {@link #isA(Class)} or {@link #any(Class)}.</li>113 * <li>Since mockito 2.0 {@link #any(Class)} is not anymore an alias of this method.</li>114 * </ul>115 * </p>116 *117 * @return <code>null</code>.118 *119 * @see #any(Class)120 * @see #anyObject()121 * @see #anyVararg()122 * @see #anyChar()123 * @see #anyInt()124 * @see #anyBoolean()125 * @see #anyCollectionOf(Class)126 */127 public static <T> T any() {128 return anyObject();129 }130 /**131 * Matches anything, including <code>null</code>.132 *133 * <p>134 * This is an alias of: {@link #any()} and {@link #any(java.lang.Class)}.135 * See examples in javadoc for {@link ArgumentMatchers} class.136 * </p>137 *138 * @return <code>null</code>.139 * @see #any()140 * @see #any(Class)141 * @see #notNull()142 * @see #notNull(Class)143 * @deprecated This will be removed in Mockito 3.0 (which will be java 8 only)144 */145 @Deprecated146 public static <T> T anyObject() {147 reportMatcher(Any.ANY);148 return null;149 }150 /**151 * Matches any object of given type, excluding nulls.152 *153 * <p>154 * This matcher will perform a type check with the given type, thus excluding values.155 * See examples in javadoc for {@link ArgumentMatchers} class.156 *157 * This is an alias of: {@link #isA(Class)}}158 * </p>159 *160 * <p>161 * Since Mockito 2.0, only allow non-null instance of <code></code>, thus <code>null</code> is not anymore a valid value.162 * As reference are nullable, the suggested API to <strong>match</strong> <code>null</code>163 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito164 * 1.x.165 * </p>166 *167 * <p><strong>Notes : </strong><br/>168 * <ul>169 * <li>For primitive types use {@link #anyChar()} family.</li>170 * <li>Since Mockito 2.0 this method will perform a type check thus <code>null</code> values are not authorized.</li>171 * <li>Since mockito 2.0 {@link #any()} and {@link #anyObject()} are not anymore aliases of this method.</li>172 * </ul>173 * </p>174 *175 * @param <T> The accepted type176 * @param type the class of the accepted type.177 * @return <code>null</code>.178 * @see #any()179 * @see #anyObject()180 * @see #anyVararg()181 * @see #isA(Class)182 * @see #notNull()183 * @see #notNull(Class)184 * @see #isNull()185 * @see #isNull(Class)186 */187 public static <T> T any(Class<T> type) {188 reportMatcher(new InstanceOf.VarArgAware(type, "<any " + type.getCanonicalName() + ">"));189 return defaultValue(type);190 }191 /**192 * <code>Object</code> argument that implements the given class.193 * <p>194 * See examples in javadoc for {@link ArgumentMatchers} class195 *196 * @param <T> the accepted type.197 * @param type the class of the accepted type.198 * @return <code>null</code>.199 * @see #any(Class)200 */201 public static <T> T isA(Class<T> type) {202 reportMatcher(new InstanceOf(type));203 return defaultValue(type);204 }205 /**206 * Any vararg, meaning any number and values of arguments.207 *208 * <p>209 * Example:210 * <pre class="code"><code class="java">211 * //verification:212 * mock.foo(1, 2);213 * mock.foo(1, 2, 3, 4);214 *215 * verify(mock, times(2)).foo(anyVararg());216 *217 * //stubbing:218 * when(mock.foo(anyVararg()).thenReturn(100);219 *220 * //prints 100221 * System.out.println(mock.foo(1, 2));222 * //also prints 100223 * System.out.println(mock.foo(1, 2, 3, 4));224 * </code></pre>225 * </p>226 *227 * <p>228 * See examples in javadoc for {@link ArgumentMatchers} class.229 * </p>230 *231 * @return <code>null</code>.232 * @see #any()233 * @see #any(Class)234 * @deprecated as of 2.0 use {@link #any()}235 */236 @Deprecated237 public static <T> T anyVararg() {238 any();239 return null;240 }241 /**242 * Any <code>boolean</code> or <strong>non-null</strong> <code>Boolean</code>243 *244 * <p>245 * Since Mockito 2.0, only allow valued <code>Boolean</code>, thus <code>null</code> is not anymore a valid value.246 * As primitive wrappers are nullable, the suggested API to <strong>match</strong> <code>null</code> wrapper247 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito248 * 1.x.249 * </p>250 *251 * <p>252 * See examples in javadoc for {@link ArgumentMatchers} class.253 * </p>254 *255 * @return <code>false</code>.256 * @see #isNull()257 * @see #isNull(Class)258 */259 public static boolean anyBoolean() {260 reportMatcher(new InstanceOf(Boolean.class, "<any boolean>"));261 return false;262 }263 /**264 * Any <code>byte</code> or <strong>non-null</strong> <code>Byte</code>.265 *266 * <p>267 * Since Mockito 2.0, only allow valued <code>Byte</code>, thus <code>null</code> is not anymore a valid value.268 * As primitive wrappers are nullable, the suggested API to <strong>match</strong> <code>null</code> wrapper269 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito270 * 1.x.271 * </p>272 *273 * <p>274 * See examples in javadoc for {@link ArgumentMatchers} class.275 * </p>276 *277 * @return <code>0</code>.278 * @see #isNull()279 * @see #isNull(Class)280 */281 public static byte anyByte() {282 reportMatcher(new InstanceOf(Byte.class, "<any byte>"));283 return 0;284 }285 /**286 * Any <code>char</code> or <strong>non-null</strong> <code>Character</code>.287 *288 * <p>289 * Since Mockito 2.0, only allow valued <code>Character</code>, thus <code>null</code> is not anymore a valid value.290 * As primitive wrappers are nullable, the suggested API to <strong>match</strong> <code>null</code> wrapper291 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito292 * 1.x.293 * </p>294 *295 * <p>296 * See examples in javadoc for {@link ArgumentMatchers} class.297 * </p>298 *299 * @return <code>0</code>.300 * @see #isNull()301 * @see #isNull(Class)302 */303 public static char anyChar() {304 reportMatcher(new InstanceOf(Character.class, "<any char>"));305 return 0;306 }307 /**308 * Any int or <strong>non-null</strong> <code>Integer</code>.309 *310 * <p>311 * Since Mockito 2.0, only allow valued <code>Integer</code>, thus <code>null</code> is not anymore a valid value.312 * As primitive wrappers are nullable, the suggested API to <strong>match</strong> <code>null</code> wrapper313 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito314 * 1.x.315 * </p>316 *317 * <p>318 * See examples in javadoc for {@link ArgumentMatchers} class.319 * </p>320 *321 * @return <code>0</code>.322 * @see #isNull()323 * @see #isNull(Class)324 */325 public static int anyInt() {326 reportMatcher(new InstanceOf(Integer.class, "<any integer>"));327 return 0;328 }329 /**330 * Any <code>long</code> or <strong>non-null</strong> <code>Long</code>.331 *332 * <p>333 * Since Mockito 2.0, only allow valued <code>Long</code>, thus <code>null</code> is not anymore a valid value.334 * As primitive wrappers are nullable, the suggested API to <strong>match</strong> <code>null</code> wrapper335 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito336 * 1.x.337 * </p>338 *339 * <p>340 * See examples in javadoc for {@link ArgumentMatchers} class.341 * </p>342 *343 * @return <code>0</code>.344 * @see #isNull()345 * @see #isNull(Class)346 */347 public static long anyLong() {348 reportMatcher(new InstanceOf(Long.class, "<any long>"));349 return 0;350 }351 /**352 * Any <code>float</code> or <strong>non-null</strong> <code>Float</code>.353 *354 * <p>355 * Since Mockito 2.0, only allow valued <code>Float</code>, thus <code>null</code> is not anymore a valid value.356 * As primitive wrappers are nullable, the suggested API to <strong>match</strong> <code>null</code> wrapper357 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito358 * 1.x.359 * </p>360 *361 * <p>362 * See examples in javadoc for {@link ArgumentMatchers} class.363 * </p>364 *365 * @return <code>0</code>.366 * @see #isNull()367 * @see #isNull(Class)368 */369 public static float anyFloat() {370 reportMatcher(new InstanceOf(Float.class, "<any float>"));371 return 0;372 }373 /**374 * Any <code>double</code> or <strong>non-null</strong> <code>Double</code>.375 *376 * <p>377 * Since Mockito 2.0, only allow valued <code>Double</code>, thus <code>null</code> is not anymore a valid value.378 * As primitive wrappers are nullable, the suggested API to <strong>match</strong> <code>null</code> wrapper379 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito380 * 1.x.381 * </p>382 *383 * <p>384 * See examples in javadoc for {@link ArgumentMatchers} class.385 * </p>386 *387 * @return <code>0</code>.388 * @see #isNull()389 * @see #isNull(Class)390 */391 public static double anyDouble() {392 reportMatcher(new InstanceOf(Double.class, "<any double>"));393 return 0;394 }395 /**396 * Any <code>short</code> or <strong>non-null</strong> <code>Short</code>.397 *398 * <p>399 * Since Mockito 2.0, only allow valued <code>Short</code>, thus <code>null</code> is not anymore a valid value.400 * As primitive wrappers are nullable, the suggested API to <strong>match</strong> <code>null</code> wrapper401 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito402 * 1.x.403 * </p>404 *405 * <p>406 * See examples in javadoc for {@link ArgumentMatchers} class.407 * </p>408 *409 * @return <code>0</code>.410 * @see #isNull()411 * @see #isNull(Class)412 */413 public static short anyShort() {414 reportMatcher(new InstanceOf(Short.class, "<any short>"));415 return 0;416 }417 /**418 * Any <strong>non-null</strong> <code>String</code>419 *420 * <p>421 * Since Mockito 2.0, only allow non-null <code>String</code>.422 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code> wrapper423 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito424 * 1.x.425 * </p>426 *427 * <p>428 * See examples in javadoc for {@link ArgumentMatchers} class.429 * </p>430 *431 * @return empty String ("")432 * @see #isNull()433 * @see #isNull(Class)434 */435 public static String anyString() {436 reportMatcher(new InstanceOf(String.class, "<any string>"));437 return "";438 }439 /**440 * Any <strong>non-null</strong> <code>List</code>.441 *442 * <p>443 * Since Mockito 2.0, only allow non-null <code>List</code>.444 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code> wrapper445 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito446 * 1.x.447 * </p>448 *449 * <p>450 * See examples in javadoc for {@link ArgumentMatchers} class.451 * </p>452 *453 * @return empty List.454 * @see #anyListOf(Class)455 * @see #isNull()456 * @see #isNull(Class)457 */458 public static <T> List<T> anyList() {459 reportMatcher(new InstanceOf(List.class, "<any List>"));460 return new ArrayList<T>(0);461 }462 /**463 * Any <strong>non-null</strong> <code>List</code>.464 *465 * Generic friendly alias to {@link ArgumentMatchers#anyList()}. It's an alternative to466 * <code>&#064;SuppressWarnings("unchecked")</code> to keep code clean of compiler warnings.467 *468 * <p>469 * This method doesn't do type checks of the list content with the given type parameter, it is only there470 * to avoid casting in the code.471 * </p>472 *473 * <p>474 * Since Mockito 2.0, only allow non-null <code>List</code>.475 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code> wrapper476 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito477 * 1.x.478 * </p>479 *480 * <p>481 * See examples in javadoc for {@link ArgumentMatchers} class.482 * </p>483 *484 * @param clazz Type owned by the list to avoid casting485 * @return empty List.486 * @see #anyList()487 * @see #isNull()488 * @see #isNull(Class)489 * @deprecated With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic490 * friendliness to avoid casting, this is not anymore needed in Java 8.491 */492 public static <T> List<T> anyListOf(Class<T> clazz) {493 return anyList();494 }495 /**496 * Any <strong>non-null</strong> <code>Set</code>.497 *498 * <p>499 * Since Mockito 2.0, only allow non-null <code>Set</code>.500 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code> wrapper501 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito502 * 1.x.503 * </p>504 *505 * <p>506 * See examples in javadoc for {@link ArgumentMatchers} class.507 * </p>508 *509 * @return empty Set510 * @see #anySetOf(Class)511 * @see #isNull()512 * @see #isNull(Class)513 */514 public static <T> Set<T> anySet() {515 reportMatcher(new InstanceOf(Set.class, "<any set>"));516 return new HashSet<T>(0);517 }518 /**519 * Any <strong>non-null</strong> <code>Set</code>.520 *521 * <p>522 * Generic friendly alias to {@link ArgumentMatchers#anySet()}.523 * It's an alternative to <code>&#064;SuppressWarnings("unchecked")</code> to keep code clean of compiler warnings.524 * </p>525 *526 * <p>527 * This method doesn't do type checks of the set content with the given type parameter, it is only there528 * to avoid casting in the code.529 * </p>530 *531 * <p>532 * Since Mockito 2.0, only allow non-null <code>Set</code>.533 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code> wrapper534 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito535 * 1.x.536 * </p>537 *538 * <p>539 * See examples in javadoc for {@link ArgumentMatchers} class.540 * </p>541 *542 * @param clazz Type owned by the Set to avoid casting543 * @return empty Set544 * @see #anySet()545 * @see #isNull()546 * @see #isNull(Class)547 * @deprecated With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic548 * friendliness to avoid casting, this is not anymore needed in Java 8.549 */550 public static <T> Set<T> anySetOf(Class<T> clazz) {551 return anySet();552 }553 /**554 * Any <strong>non-null</strong> <code>Map</code>.555 *556 * <p>557 * Since Mockito 2.0, only allow non-null <code>Map</code>.558 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code> wrapper559 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito560 * 1.x.561 * </p>562 *563 * <p>564 * See examples in javadoc for {@link ArgumentMatchers} class.565 * </p>566 *567 * @return empty Map.568 * @see #anyMapOf(Class, Class)569 * @see #isNull()570 * @see #isNull(Class)571 */572 public static <K, V> Map<K, V> anyMap() {573 reportMatcher(new InstanceOf(Map.class, "<any map>"));574 return new HashMap<K, V>(0);575 }576 /**577 * Any <strong>non-null</strong> <code>Map</code>.578 *579 * <p>580 * Generic friendly alias to {@link ArgumentMatchers#anyMap()}.581 * It's an alternative to <code>&#064;SuppressWarnings("unchecked")</code> to keep code clean of compiler warnings.582 * </p>583 *584 * <p>585 * This method doesn't do type checks of the map content with the given type parameter, it is only there586 * to avoid casting in the code.587 * </p>588 *589 * <p>590 * Since Mockito 2.0, only allow non-null <code>Map</code>.591 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code> wrapper592 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito593 * 1.x.594 * </p>595 *596 * <p>597 * See examples in javadoc for {@link ArgumentMatchers} class.598 * </p>599 *600 * @param keyClazz Type of the map key to avoid casting601 * @param valueClazz Type of the value to avoid casting602 * @return empty Map.603 * @see #anyMap()604 * @see #isNull()605 * @see #isNull(Class)606 * @deprecated With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic607 * friendliness to avoid casting, this is not anymore needed in Java 8.608 */609 public static <K, V> Map<K, V> anyMapOf(Class<K> keyClazz, Class<V> valueClazz) {610 return anyMap();611 }612 /**613 * Any <strong>non-null</strong> <code>Collection</code>.614 *615 * <p>616 * Since Mockito 2.0, only allow non-null <code>Collection</code>.617 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code>618 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito619 * 1.x.620 * </p>621 *622 * <p>623 * See examples in javadoc for {@link ArgumentMatchers} class.624 * </p>625 *626 * @return empty Collection.627 * @see #anyCollectionOf(Class)628 * @see #isNull()629 * @see #isNull(Class)630 */631 public static <T> Collection<T> anyCollection() {632 reportMatcher(new InstanceOf(Collection.class, "<any collection>"));633 return new ArrayList<T>(0);634 }635 /**636 * Any <strong>non-null</strong> <code>Collection</code>.637 *638 * <p>639 * Generic friendly alias to {@link ArgumentMatchers#anyCollection()}.640 * It's an alternative to <code>&#064;SuppressWarnings("unchecked")</code> to keep code clean of compiler warnings.641 * </p>642 *643 * <p>644 * This method doesn't do type checks of the collection content with the given type parameter, it is only there645 * to avoid casting in the code.646 * </p>647 *648 * <p>649 * Since Mockito 2.0, only allow non-null <code>Collection</code>.650 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code>651 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito652 * 1.x.653 * </p>654 *655 * <p>656 * See examples in javadoc for {@link ArgumentMatchers} class.657 * </p>658 *659 * @param clazz Type owned by the collection to avoid casting660 * @return empty Collection.661 * @see #anyCollection()662 * @see #isNull()663 * @see #isNull(Class)664 * @deprecated With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic665 * friendliness to avoid casting, this is not anymore needed in Java 8.666 */667 public static <T> Collection<T> anyCollectionOf(Class<T> clazz) {668 return anyCollection();669 }670 /**671 * Any <strong>non-null</strong> <code>Iterable</code>.672 *673 * <p>674 * Since Mockito 2.0, only allow non-null <code>Iterable</code>.675 * As this is a nullable reference, the suggested API to <strong>match</strong> <code>null</code>676 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito677 * 1.x.678 * </p>679 *680 * <p>681 * See examples in javadoc for {@link ArgumentMatchers} class.682 * </p>683 *684 * @return empty Iterable.685 * @see #anyIterableOf(Class)686 * @see #isNull()687 * @see #isNull(Class)688 * @since 2.0.0689 */690 public static <T> Iterable<T> anyIterable() {691 reportMatcher(new InstanceOf(Iterable.class, "<any iterable>"));692 return new ArrayList<T>(0);693 }694 /**695 * Any <strong>non-null</strong> <code>Iterable</code>.696 *697 * <p>698 * Generic friendly alias to {@link ArgumentMatchers#anyIterable()}.699 * It's an alternative to <code>&#064;SuppressWarnings("unchecked")</code> to keep code clean of compiler warnings.700 * </p>701 *702 * <p>703 * This method doesn't do type checks of the iterable content with the given type parameter, it is only there704 * to avoid casting in the code.705 * </p>706 *707 * <p>708 * Since Mockito 2.0, only allow non-null <code>String</code>.709 * As strings are nullable reference, the suggested API to <strong>match</strong> <code>null</code> wrapper710 * would be {@link #isNull()}. We felt this change would make tests harness much safer that it was with Mockito711 * 1.x.712 * </p>713 *714 * <p>715 * See examples in javadoc for {@link ArgumentMatchers} class.716 * </p>717 *718 * @param clazz Type owned by the collection to avoid casting719 * @return empty Iterable.720 * @see #anyIterable()721 * @see #isNull()722 * @see #isNull(Class)723 * @since 2.0.0724 * @deprecated With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic725 * friendliness to avoid casting, this is not anymore needed in Java 8.726 */727 public static <T> Iterable<T> anyIterableOf(Class<T> clazz) {728 return anyIterable();729 }730 /**731 * <code>boolean</code> argument that is equal to the given value.732 *733 * <p>734 * See examples in javadoc for {@link ArgumentMatchers} class735 * </p>736 *737 * @param value the given value.738 * @return <code>0</code>.739 */740 public static boolean eq(boolean value) {741 reportMatcher(new Equals(value));742 return false;743 }744 /**745 * <code>byte</code> argument that is equal to the given value.746 *747 * <p>748 * See examples in javadoc for {@link ArgumentMatchers} class749 * </p>750 *751 * @param value the given value.752 * @return <code>0</code>.753 */754 public static byte eq(byte value) {755 reportMatcher(new Equals(value));756 return 0;757 }758 /**759 * <code>char</code> argument that is equal to the given value.760 *761 * <p>762 * See examples in javadoc for {@link ArgumentMatchers} class763 * </p>764 *765 * @param value the given value.766 * @return <code>0</code>.767 */768 public static char eq(char value) {769 reportMatcher(new Equals(value));770 return 0;771 }772 /**773 * <code>double</code> argument that is equal to the given value.774 *775 * <p>776 * See examples in javadoc for {@link ArgumentMatchers} class777 * </p>778 *779 * @param value the given value.780 * @return <code>0</code>.781 */782 public static double eq(double value) {783 reportMatcher(new Equals(value));784 return 0;785 }786 /**787 * <code>float</code> argument that is equal to the given value.788 *789 * <p>790 * See examples in javadoc for {@link ArgumentMatchers} class791 * </p>792 *793 * @param value the given value.794 * @return <code>0</code>.795 */796 public static float eq(float value) {797 reportMatcher(new Equals(value));798 return 0;799 }800 /**801 * <code>int</code> argument that is equal to the given value.802 *803 * <p>804 * See examples in javadoc for {@link ArgumentMatchers} class805 * </p>806 *807 * @param value the given value.808 * @return <code>0</code>.809 */810 public static int eq(int value) {811 reportMatcher(new Equals(value));812 return 0;813 }814 /**815 * <code>long</code> argument that is equal to the given value.816 *817 * <p>818 * See examples in javadoc for {@link ArgumentMatchers} class819 * </p>820 *821 * @param value the given value.822 * @return <code>0</code>.823 */824 public static long eq(long value) {825 reportMatcher(new Equals(value));826 return 0;827 }828 /**829 * <code>short</code> argument that is equal to the given value.830 * <p>831 * See examples in javadoc for {@link ArgumentMatchers} class832 *833 * @param value the given value.834 * @return <code>0</code>.835 */836 public static short eq(short value) {837 reportMatcher(new Equals(value));838 return 0;839 }840 /**841 * Object argument that is equal to the given value.842 *843 * <p>844 * See examples in javadoc for {@link ArgumentMatchers} class845 * </p>846 *847 * @param value the given value.848 * @return <code>null</code>.849 */850 public static <T> T eq(T value) {851 reportMatcher(new Equals(value));852 if (value == null)853 return null;854 return (T) Primitives.defaultValue(value.getClass());855 }856 /**857 * Object argument that is reflection-equal to the given value with support for excluding858 * selected fields from a class.859 *860 * <p>861 * This matcher can be used when equals() is not implemented on compared objects.862 * Matcher uses java reflection API to compare fields of wanted and actual object.863 * </p>864 *865 * <p>866 * Works similarly to <code>EqualsBuilder.reflectionEquals(this, other, exlucdeFields)</code> from867 * apache commons library.868 * <p>869 * <b>Warning</b> The equality check is shallow!870 * </p>871 *872 * <p>873 * See examples in javadoc for {@link ArgumentMatchers} class874 * </p>875 *876 * @param value the given value.877 * @param excludeFields fields to exclude, if field does not exist it is ignored.878 * @return <code>null</code>.879 */880 public static <T> T refEq(T value, String... excludeFields) {881 reportMatcher(new ReflectionEquals(value, excludeFields));882 return null;883 }884 /**885 * Object argument that is the same as the given value.886 *887 * <p>888 * See examples in javadoc for {@link ArgumentMatchers} class889 * </p>890 *891 * @param <T> the type of the object, it is passed through to prevent casts.892 * @param value the given value.893 * @return <code>null</code>.894 */895 public static <T> T same(T value) {896 reportMatcher(new Same(value));897 if (value == null)898 return null;899 return (T) Primitives.defaultValue(value.getClass());900 }901 /**902 * <code>null</code> argument.903 *904 * <p>905 * See examples in javadoc for {@link ArgumentMatchers} class906 * </p>907 *908 * @return <code>null</code>.909 * @see #isNull(Class)910 * @see #isNotNull()911 * @see #isNotNull(Class)912 */913 public static <T> T isNull() {914 reportMatcher(Null.NULL);915 return null;916 }917 /**918 * <code>null</code> argument.919 *920 * <p>921 * The class argument is provided to avoid casting.922 * </p>923 *924 * <p>925 * See examples in javadoc for {@link ArgumentMatchers} class926 * </p>927 *928 * @param clazz Type to avoid casting929 * @return <code>null</code>.930 * @see #isNull()931 * @see #isNotNull()932 * @see #isNotNull(Class)933 * @deprecated With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic934 * friendliness to avoid casting, this is not anymore needed in Java 8.935 */936 public static <T> T isNull(Class<T> clazz) {937 return isNull();938 }939 /**940 * Not <code>null</code> argument.941 *942 * <p>943 * Alias to {@link ArgumentMatchers#isNotNull()}944 * </p>945 *946 * <p>947 * See examples in javadoc for {@link ArgumentMatchers} class948 * </p>949 *950 * @return <code>null</code>.951 */952 public static <T> T notNull() {953 reportMatcher(NotNull.NOT_NULL);954 return null;955 }956 /**957 * Not <code>null</code> argument, not necessary of the given class.958 *959 * <p>960 * The class argument is provided to avoid casting.961 *962 * Alias to {@link ArgumentMatchers#isNotNull(Class)}963 * <p>964 *965 * <p>966 * See examples in javadoc for {@link ArgumentMatchers} class967 * </p>968 *969 * @param clazz Type to avoid casting970 * @return <code>null</code>.971 * @see #isNotNull()972 * @see #isNull()973 * @see #isNull(Class)974 * @deprecated With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic975 * friendliness to avoid casting, this is not anymore needed in Java 8.976 */977 public static <T> T notNull(Class<T> clazz) {978 return notNull();979 }980 /**981 * Not <code>null</code> argument.982 *983 * <p>984 * Alias to {@link ArgumentMatchers#notNull()}985 * </p>986 *987 * <p>988 * See examples in javadoc for {@link ArgumentMatchers} class989 * </p>990 *991 * @return <code>null</code>.992 * @see #isNotNull(Class)993 * @see #isNull()994 * @see #isNull(Class)995 */996 public static <T> T isNotNull() {997 return notNull();998 }999 /**1000 * Not <code>null</code> argument, not necessary of the given class.1001 *1002 * <p>1003 * The class argument is provided to avoid casting.1004 * Alias to {@link ArgumentMatchers#notNull(Class)}1005 * </p>1006 *1007 * <p>1008 * See examples in javadoc for {@link ArgumentMatchers} class...

Full Screen

Full Screen

Source:RecurringServiceTypeRepositoryTest.java Github

copy

Full Screen

...50 ServiceType serviceType = PowerMockito.mock(ServiceType.class);51 Mockito.when(serviceType.getId()).thenReturn(null);52 recurringServiceTypeRepository.add(serviceType, sqliteDatabase);53 Mockito.verify(sqliteDatabase, times(1))54 .insert(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class),55 org.mockito.ArgumentMatchers.any(ContentValues.class));56 }57 @Test58 public void assertAndVerifySearchByNamecallsDatabaseQueryMethod1Times() {59 String[] columns = new String[]{RecurringServiceTypeRepository.ID_COLUMN, RecurringServiceTypeRepository.NAME, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY_ID, RecurringServiceTypeRepository.DATE_ENTITY, RecurringServiceTypeRepository.DATE_ENTITY_ID, RecurringServiceTypeRepository.UNITS, RecurringServiceTypeRepository.SERVICE_LOGIC, RecurringServiceTypeRepository.PREREQUISITE, RecurringServiceTypeRepository.PRE_OFFSET, RecurringServiceTypeRepository.EXPIRY_OFFSET, RecurringServiceTypeRepository.MILESTONE_OFFSET, RecurringServiceTypeRepository.UPDATED_AT_COLUMN};60 MatrixCursor cursor = new MatrixCursor(columns);61 cursor.addRow(new Object[]{1l, "", "", "", "", "", "", "", "", "", "", "", "", 1l});62 Mockito.when(sqliteDatabase63 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),64 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),65 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),66 org.mockito.ArgumentMatchers.isNull(String.class),67 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);68 Mockito.when(recurringServiceTypeRepository.getReadableDatabase()).thenReturn(sqliteDatabase);69 recurringServiceTypeRepository.searchByName("Name");70 Mockito.verify(sqliteDatabase, times(1))71 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),72 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),73 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),74 org.mockito.ArgumentMatchers.isNull(String.class),75 org.mockito.ArgumentMatchers.isNull(String.class));76 Assert.assertNotNull(recurringServiceTypeRepository.searchByName(""));77 }78 @Test79 public void assertAndVerifyGetByNameCallsDatabaseQueryMethod1Times() {80 String[] columns = new String[]{RecurringServiceTypeRepository.ID_COLUMN, RecurringServiceTypeRepository.NAME, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY_ID, RecurringServiceTypeRepository.DATE_ENTITY, RecurringServiceTypeRepository.DATE_ENTITY_ID, RecurringServiceTypeRepository.UNITS, RecurringServiceTypeRepository.SERVICE_LOGIC, RecurringServiceTypeRepository.PREREQUISITE, RecurringServiceTypeRepository.PRE_OFFSET, RecurringServiceTypeRepository.EXPIRY_OFFSET, RecurringServiceTypeRepository.MILESTONE_OFFSET, RecurringServiceTypeRepository.UPDATED_AT_COLUMN};81 MatrixCursor cursor = new MatrixCursor(columns);82 cursor.addRow(new Object[]{1l, "", "Name", "", "", "", "", "", "", "", "", "", "", 1l});83 Mockito.when(sqliteDatabase84 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),85 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),86 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),87 org.mockito.ArgumentMatchers.isNull(String.class),88 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);89 Mockito.when(recurringServiceTypeRepository.getReadableDatabase()).thenReturn(sqliteDatabase);90 recurringServiceTypeRepository.getByName("Vitamin A1");91 Mockito.verify(sqliteDatabase, times(1))92 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),93 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),94 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),95 org.mockito.ArgumentMatchers.isNull(String.class),96 org.mockito.ArgumentMatchers.isNull(String.class));97 }98 @Test99 public void assertAndVerifySearchByTypecallsDatabaseQueryMethod1Times() {100 String[] columns = new String[]{RecurringServiceTypeRepository.ID_COLUMN, RecurringServiceTypeRepository.NAME, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY_ID, RecurringServiceTypeRepository.DATE_ENTITY, RecurringServiceTypeRepository.DATE_ENTITY_ID, RecurringServiceTypeRepository.UNITS, RecurringServiceTypeRepository.SERVICE_LOGIC, RecurringServiceTypeRepository.PREREQUISITE, RecurringServiceTypeRepository.PRE_OFFSET, RecurringServiceTypeRepository.EXPIRY_OFFSET, RecurringServiceTypeRepository.MILESTONE_OFFSET, RecurringServiceTypeRepository.UPDATED_AT_COLUMN};101 MatrixCursor cursor = new MatrixCursor(columns);102 cursor.addRow(new Object[]{1l, "", "", "", "", "", "", "", "", "", "", "", "", 1l});103 Mockito.when(sqliteDatabase104 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),105 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),106 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),107 org.mockito.ArgumentMatchers.isNull(String.class),108 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);109 Mockito.when(recurringServiceTypeRepository.getReadableDatabase()).thenReturn(sqliteDatabase);110 recurringServiceTypeRepository.findByType("Type");111 Mockito.verify(sqliteDatabase, times(1))112 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),113 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),114 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),115 org.mockito.ArgumentMatchers.isNull(String.class),116 org.mockito.ArgumentMatchers.isNull(String.class));117 Assert.assertNotNull(recurringServiceTypeRepository.findByType(""));118 }119 @Test120 public void verifyFindcallsDatabaseQueryMethod1Times() {121 String[] columns = new String[]{RecurringServiceTypeRepository.ID_COLUMN, RecurringServiceTypeRepository.NAME, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY_ID, RecurringServiceTypeRepository.DATE_ENTITY, RecurringServiceTypeRepository.DATE_ENTITY_ID, RecurringServiceTypeRepository.UNITS, RecurringServiceTypeRepository.SERVICE_LOGIC, RecurringServiceTypeRepository.PREREQUISITE, RecurringServiceTypeRepository.PRE_OFFSET, RecurringServiceTypeRepository.EXPIRY_OFFSET, RecurringServiceTypeRepository.MILESTONE_OFFSET, RecurringServiceTypeRepository.UPDATED_AT_COLUMN};122 MatrixCursor cursor = new MatrixCursor(columns);123 cursor.addRow(new Object[]{1l, "", "", "", "", "", "", "", "", "", "", "", "", 1l});124 Mockito.when(sqliteDatabase125 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),126 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),127 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),128 org.mockito.ArgumentMatchers.isNull(String.class),129 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);130 Mockito.when(recurringServiceTypeRepository.getReadableDatabase()).thenReturn(sqliteDatabase);131 recurringServiceTypeRepository.find(1l, sqliteDatabase);132 Mockito.verify(sqliteDatabase, times(1))133 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),134 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),135 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),136 org.mockito.ArgumentMatchers.isNull(String.class),137 org.mockito.ArgumentMatchers.isNull(String.class));138 }139 @Test140 public void assertAndVerifyAddCallsDatabaseDatabaseMethod0TimesInCaseOfNullVaccine() {141 recurringServiceTypeRepository.add(null, sqliteDatabase);142 Mockito.verify(sqliteDatabase, times(0))143 .insert(org.mockito.ArgumentMatchers.anyString(), (String) org.mockito.ArgumentMatchers.isNull(),144 org.mockito.ArgumentMatchers.any(ContentValues.class));145 Mockito.verify(sqliteDatabase, times(0))146 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),147 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));148 ServiceType serviceType = new ServiceType();149 serviceType.setId(1l);150 RecurringServiceTypeRepository spy = Mockito.spy(recurringServiceTypeRepository);151 Mockito.doReturn(serviceType).when(spy)152 .find(org.mockito.ArgumentMatchers.anyLong(), org.mockito.ArgumentMatchers.any(SQLiteDatabase.class));153 spy.add(serviceType);154 Mockito.verify(sqliteDatabase, times(0))155 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),156 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));157 Assert.assertNull(recurringServiceTypeRepository.find(0l));158 }159 @Test160 public void verifyFetchAllTypecallsDatabaseQueryMethod1Times() {161 String[] columns = new String[]{RecurringServiceTypeRepository.ID_COLUMN, RecurringServiceTypeRepository.NAME, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY_ID, RecurringServiceTypeRepository.DATE_ENTITY, RecurringServiceTypeRepository.DATE_ENTITY_ID, RecurringServiceTypeRepository.UNITS, RecurringServiceTypeRepository.SERVICE_LOGIC, RecurringServiceTypeRepository.PREREQUISITE, RecurringServiceTypeRepository.PRE_OFFSET, RecurringServiceTypeRepository.EXPIRY_OFFSET, RecurringServiceTypeRepository.MILESTONE_OFFSET, RecurringServiceTypeRepository.UPDATED_AT_COLUMN};162 MatrixCursor cursor = new MatrixCursor(columns);163 cursor.addRow(new Object[]{1l, "", "", "", "", "", "", "", "", "", "", "", "", 1l});164 cursor.addRow(new Object[]{1l, "", "a_b", "", "", "", "", "", "", "", "", "", "", 1l});165 Mockito.when(sqliteDatabase166 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),167 org.mockito.ArgumentMatchers.isNull(String.class),168 org.mockito.ArgumentMatchers.isNull(String[].class),169 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),170 org.mockito.ArgumentMatchers.anyString())).thenReturn(cursor);171 Mockito.when(recurringServiceTypeRepository.getReadableDatabase()).thenReturn(sqliteDatabase);172 recurringServiceTypeRepository.fetchAll();173 Mockito.verify(sqliteDatabase, times(1))174 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),175 org.mockito.ArgumentMatchers.isNull(String.class),176 org.mockito.ArgumentMatchers.isNull(String[].class),177 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),178 org.mockito.ArgumentMatchers.anyString());179 }180 @Test181 public void verifyFetchTypescallsDatabaseQueryMethod1Times() {182 String[] columns = new String[]{RecurringServiceTypeRepository.ID_COLUMN, RecurringServiceTypeRepository.NAME, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY_ID, RecurringServiceTypeRepository.DATE_ENTITY, RecurringServiceTypeRepository.DATE_ENTITY_ID, RecurringServiceTypeRepository.UNITS, RecurringServiceTypeRepository.SERVICE_LOGIC, RecurringServiceTypeRepository.PREREQUISITE, RecurringServiceTypeRepository.PRE_OFFSET, RecurringServiceTypeRepository.EXPIRY_OFFSET, RecurringServiceTypeRepository.MILESTONE_OFFSET, RecurringServiceTypeRepository.UPDATED_AT_COLUMN};183 MatrixCursor cursor = new MatrixCursor(columns);184 cursor.addRow(new Object[]{1l, "", "", "", "", "", "", "", "", "", "", "", "", 1l});185 Mockito.when(sqliteDatabase186 .rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String[].class)))187 .thenReturn(cursor);188 Mockito.when(recurringServiceTypeRepository.getReadableDatabase()).thenReturn(sqliteDatabase);189 recurringServiceTypeRepository.fetchTypes();190 Mockito.verify(sqliteDatabase, times(1))191 .rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String[].class));192 }193 @Test194 public void verifyDeletecallsDatabaseDeleteMethod1Times() {195 RecurringServiceTypeRepository recurringServiceTypeRepositoryspy = Mockito.spy(recurringServiceTypeRepository);196 ServiceType serviceType = new ServiceType();197 Mockito.doReturn(serviceType).when(recurringServiceTypeRepositoryspy).find(0l, null);198 Mockito.when(recurringServiceTypeRepositoryspy.getWritableDatabase()).thenReturn(sqliteDatabase);199 recurringServiceTypeRepositoryspy.deleteServiceType(0l);200 Mockito.verify(sqliteDatabase, times(1))201 .delete(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(),202 org.mockito.ArgumentMatchers.any(String[].class));203 }204 @Test205 public void assertAddHyphenMethodWithBlankParamReturnsBlankString() {206 String testString = RecurringServiceTypeRepository.addHyphen("");207 org.junit.Assert.assertNotNull(testString);208 org.junit.Assert.assertTrue(testString.isEmpty());209 }210 @Test211 public void assertRemoveHyphenMethodWithBlankParamReturnsBlankString() {212 String testString = RecurringServiceTypeRepository.removeHyphen("");213 org.junit.Assert.assertNotNull(testString);214 org.junit.Assert.assertTrue(testString.isEmpty());215 }216 @Test217 public void verifyFetchTypesOverrideCallTheSameMethod() throws Exception {218 RecurringServiceTypeRepository recurringServiceTypeRepositoryspy = Mockito.spy(recurringServiceTypeRepository);219 Mockito.when(recurringServiceTypeRepository.getReadableDatabase()).thenReturn(sqliteDatabase);220 String[] columns = new String[]{RecurringServiceTypeRepository.ID_COLUMN, RecurringServiceTypeRepository.NAME, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY, RecurringServiceTypeRepository.SERVICE_NAME_ENTITY_ID, RecurringServiceTypeRepository.DATE_ENTITY, RecurringServiceTypeRepository.DATE_ENTITY_ID, RecurringServiceTypeRepository.UNITS, RecurringServiceTypeRepository.SERVICE_LOGIC, RecurringServiceTypeRepository.PREREQUISITE, RecurringServiceTypeRepository.PRE_OFFSET, RecurringServiceTypeRepository.EXPIRY_OFFSET, RecurringServiceTypeRepository.MILESTONE_OFFSET, RecurringServiceTypeRepository.UPDATED_AT_COLUMN};221 MatrixCursor cursor = new MatrixCursor(columns);222 cursor.addRow(new Object[]{1l, "", "", "", "", "", "", "", "", "", "", "", "", 1l});223 Mockito.when(sqliteDatabase224 .rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String[].class)))225 .thenReturn(cursor);226 recurringServiceTypeRepositoryspy.fetchTypes();227 Mockito.verify(recurringServiceTypeRepositoryspy, times(1)).extractCursorTypes(cursor);228 recurringServiceTypeRepositoryspy.fetchTypes("group");229 Mockito.verify(recurringServiceTypeRepositoryspy, times(1)).extractCursorTypes(null);230 }231}...

Full Screen

Full Screen

Source:VaccineRepositoryTest.java Github

copy

Full Screen

...78 Mockito.when(vaccineRepository.getReadableDatabase()).thenReturn(sqliteDatabase);79 Mockito.when(sqliteDatabase80 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),81 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),82 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),83 org.mockito.ArgumentMatchers.isNull(String.class),84 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);85 org.junit.Assert.assertNotNull(vaccineRepository.findUnSyncedBeforeTime(magic10));86 }87 @Test88 public void assertConstructorTest() {89 VaccineRepository vaccineRepository = new VaccineRepository(commonFtsObject, alertService);90 org.junit.Assert.assertNotNull(vaccineRepository);91 }92 @Test93 public void verifyUpdateHia2StatusTest() {94 Mockito.when(vaccineRepository.getWritableDatabase()).thenReturn(sqliteDatabase);95 vaccineRepository.add(new Vaccine());96 Vaccine vaccine = new Vaccine();97 vaccine.setId(1l);98 vaccineRepository.updateHia2Status(vaccine, magicTS);99 vaccineRepository.updateHia2Status(null, magicTS);100 }101 @Test102 public void verifyCreateTableTest() {103 VaccineRepository.createTable(sqliteDatabase);104 Mockito.verify(sqliteDatabase, Mockito.times(3)).execSQL(org.mockito.ArgumentMatchers.anyString());105 }106 @Test107 public void verifyaddTestShouldCallInsertAndUpdate1Time() {108 //null database, throws exception109 Mockito.when(vaccineRepository.getWritableDatabase()).thenReturn(null);110 Vaccine vaccine1 = new Vaccine();111 vaccine1.setId(1l);112 vaccineRepository.add(vaccine1);113 //null vaccine114 vaccineRepository.add(null);115 Mockito.verify(sqliteDatabase, Mockito.times(0))116 .insert(org.mockito.ArgumentMatchers.anyString(), (String) org.mockito.ArgumentMatchers.isNull(),117 org.mockito.ArgumentMatchers.any(ContentValues.class));118 Mockito.verify(sqliteDatabase, Mockito.times(0))119 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),120 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));121 //notnull vaccine122 Mockito.when(vaccineRepository.getWritableDatabase()).thenReturn(sqliteDatabase);123 Vaccine vaccine = new Vaccine();124 vaccine.setId(0l);125 vaccineRepository.add(vaccine);126 Mockito.verify(sqliteDatabase, Mockito.times(1))127 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),128 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));129 //null id130 vaccineRepository.add(new Vaccine());131 Mockito.when(vaccineRepository.getWritableDatabase()).thenReturn(sqliteDatabase);132 vaccineRepository.add(new Vaccine());133 Mockito.verify(sqliteDatabase, Mockito.times(2))134 .insert(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class),135 org.mockito.ArgumentMatchers.any(ContentValues.class));136 Vaccine newVaccine = new Vaccine(0l, VaccineTest.BASEENTITYID, VaccineTest.PROGRAMCLIENTID, VaccineTest.NAME, 0,137 new Date(),138 VaccineTest.ANMID, VaccineTest.LOCATIONID, VaccineTest.SYNCSTATUS, VaccineTest.HIA2STATUS, 0l,139 VaccineTest.EVENTID, VaccineTest.FORMSUBMISSIONID, 0, new Date());140 VaccineRepository vaccineRepositoryspy = Mockito.spy(vaccineRepository);141 Vaccine vaccineToReturn = Mockito.mock(Vaccine.class);142 Mockito.when(vaccineRepositoryspy.findUnique(org.mockito.ArgumentMatchers.any(SQLiteDatabase.class),143 org.mockito.ArgumentMatchers.any(Vaccine.class))).thenReturn(vaccineToReturn);144 vaccineRepositoryspy.add(newVaccine);145 Mockito.verify(sqliteDatabase, Mockito.times(2))146 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),147 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));148 }149 @Test150 public void verifyUpdateTestCallsDatabaseUpdate1Time() {151 Vaccine vaccine = new Vaccine();152 vaccine.setId(0l);153 //exception test database null154 vaccineRepository.update(null, vaccine);155 Mockito.verify(sqliteDatabase, Mockito.times(0))156 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),157 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));158 //vaccine null test159 vaccineRepository.update(sqliteDatabase, null);160 //vaccine and database not null161 vaccineRepository.update(sqliteDatabase, vaccine);162 Mockito.verify(sqliteDatabase, Mockito.times(1))163 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),164 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));165 }166 @Test167 public void verifyFindbyEntityIdTestCallsDatabaseQuery1Time() {168 String[] columns = new String[]{VaccineRepository.ID_COLUMN, VaccineRepository.BASE_ENTITY_ID, VaccineRepository.PROGRAM_CLIENT_ID, VaccineRepository.NAME, VaccineRepository.CALCULATION, VaccineRepository.DATE, VaccineRepository.ANMID, VaccineRepository.LOCATION_ID, VaccineRepository.SYNC_STATUS, VaccineRepository.HIA2_STATUS, VaccineRepository.UPDATED_AT_COLUMN, VaccineRepository.EVENT_ID, VaccineRepository.FORMSUBMISSION_ID, VaccineRepository.OUT_OF_AREA};169 MatrixCursor cursor = new MatrixCursor(columns);170 cursor.addRow(new Object[]{1l, "", "", magicName, magic10, magicTime, "", "", "", "", 1l, "", "", 1});171 Mockito.when(sqliteDatabase172 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),173 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),174 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),175 org.mockito.ArgumentMatchers.isNull(String.class),176 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);177 Mockito.when(vaccineRepository.getReadableDatabase()).thenReturn(sqliteDatabase);178 vaccineRepository.findByEntityId(ENTITYID);179 Mockito.verify(sqliteDatabase, Mockito.times(1))180 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),181 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),182 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),183 org.mockito.ArgumentMatchers.isNull(String.class),184 org.mockito.ArgumentMatchers.isNull(String.class));185 }186 @Test187 public void verifyFindTwentyFourTestCallsDatabaseQuery1Time() {188 String[] columns = new String[]{VaccineRepository.ID_COLUMN, VaccineRepository.BASE_ENTITY_ID, VaccineRepository.PROGRAM_CLIENT_ID, VaccineRepository.NAME, VaccineRepository.CALCULATION, VaccineRepository.DATE, VaccineRepository.ANMID, VaccineRepository.LOCATION_ID, VaccineRepository.SYNC_STATUS, VaccineRepository.HIA2_STATUS, VaccineRepository.UPDATED_AT_COLUMN, VaccineRepository.EVENT_ID, VaccineRepository.FORMSUBMISSION_ID, VaccineRepository.OUT_OF_AREA};189 MatrixCursor cursor = new MatrixCursor(columns);190 cursor.addRow(new Object[]{1l, "", "", magicName, magic10, magicTime, "", "", "", "", 1l, "", "", 1});191 Mockito.when(sqliteDatabase192 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),193 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),194 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),195 org.mockito.ArgumentMatchers.isNull(String.class),196 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);197 Mockito.when(vaccineRepository.getReadableDatabase()).thenReturn(sqliteDatabase);198 vaccineRepository.findLatestTwentyFourHoursByEntityId(ENTITYID);199 Mockito.verify(sqliteDatabase, Mockito.times(1))200 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),201 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),202 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),203 org.mockito.ArgumentMatchers.isNull(String.class),204 org.mockito.ArgumentMatchers.isNull(String.class));205 }206 @Test207 public void verifyFindTestCallsDatabaseQuery1Time() {208 vaccineRepository.find(0l);209 String[] columns = new String[]{VaccineRepository.ID_COLUMN, VaccineRepository.BASE_ENTITY_ID, VaccineRepository.PROGRAM_CLIENT_ID, VaccineRepository.NAME, VaccineRepository.CALCULATION, VaccineRepository.DATE, VaccineRepository.ANMID, VaccineRepository.LOCATION_ID, VaccineRepository.SYNC_STATUS, VaccineRepository.HIA2_STATUS, VaccineRepository.UPDATED_AT_COLUMN, VaccineRepository.EVENT_ID, VaccineRepository.FORMSUBMISSION_ID, VaccineRepository.OUT_OF_AREA};210 MatrixCursor cursor = new MatrixCursor(columns);211 cursor.addRow(new Object[]{1l, "", "", magicName, magic10, magicTime, "", "", "", "", 1l, "", "", 1});212 Mockito.when(sqliteDatabase213 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),214 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),215 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),216 org.mockito.ArgumentMatchers.isNull(String.class),217 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);218 Mockito.when(vaccineRepository.getReadableDatabase()).thenReturn(sqliteDatabase);219 vaccineRepository.find(1l);220 Mockito.verify(sqliteDatabase, Mockito.times(1))221 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),222 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),223 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),224 org.mockito.ArgumentMatchers.isNull(String.class),225 org.mockito.ArgumentMatchers.isNull(String.class));226 }227 @Test228 public void findbyUniqueTest() {229 String[] columns = new String[]{VaccineRepository.ID_COLUMN, VaccineRepository.BASE_ENTITY_ID, VaccineRepository.PROGRAM_CLIENT_ID, VaccineRepository.NAME, VaccineRepository.CALCULATION, VaccineRepository.DATE, VaccineRepository.ANMID, VaccineRepository.LOCATION_ID, VaccineRepository.SYNC_STATUS, VaccineRepository.HIA2_STATUS, VaccineRepository.UPDATED_AT_COLUMN, VaccineRepository.EVENT_ID, VaccineRepository.FORMSUBMISSION_ID, VaccineRepository.OUT_OF_AREA};230 MatrixCursor cursor = new MatrixCursor(columns);231 cursor.addRow(new Object[]{1l, "", "", magicName, magic10, magicTime, "", "", "", "", 1l, "", "", 1});232 Vaccine vaccine = new Vaccine();233 vaccine.setFormSubmissionId(FORMSUBMISSIONID);234 vaccine.setEventId(EVENTID);235 Mockito.when(sqliteDatabase236 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),237 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),238 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),239 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class)))240 .thenReturn(cursor);241 Mockito.when(vaccineRepository.getReadableDatabase()).thenReturn(sqliteDatabase);242 vaccineRepository.findUnique(null, vaccine);243 vaccineRepository.findUnique(sqliteDatabase, null);244 vaccineRepository.findUnique(sqliteDatabase, vaccine);245 Mockito.verify(sqliteDatabase, Mockito.times(2))246 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),247 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),248 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),249 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class));250 }251 @Test252 public void deleteVaccineTest() {253 VaccineRepository vaccineRepositoryspy = Mockito.spy(vaccineRepository);254 Vaccine vaccine = new Vaccine();255 vaccine.setBaseEntityId("baseEntityID");256 vaccine.setName(magicName);257 vaccine.setFormSubmissionId(FORMSUBMISSIONID);258 vaccine.setEventId(EVENTID);259 Mockito.doReturn(vaccine).when(vaccineRepositoryspy).find(0l);260 Mockito.when(vaccineRepositoryspy.getWritableDatabase()).thenReturn(sqliteDatabase);261 vaccineRepositoryspy.deleteVaccine(0l);262 Mockito.verify(sqliteDatabase, Mockito.times(1))263 .delete(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(),...

Full Screen

Full Screen

Source:RecurringServiceRecordRepositoryTest.java Github

copy

Full Screen

...59 public void verifyAddCallsDatabaseDatabaseMethod1TimesInCaseOfNonNullVaccineNullID() {60 Mockito.when(recurringServiceRecordRepository.getWritableDatabase()).thenReturn(sqliteDatabase);61 recurringServiceRecordRepository.add(new ServiceRecord());62 Mockito.verify(sqliteDatabase, Mockito.times(1))63 .insert(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class),64 org.mockito.ArgumentMatchers.any(ContentValues.class));65 }66 @Test67 public void verifyAddCallsDatabaseDatabaseMethod1TimesInCaseOfNonNullVaccineNotNullID() {68 Mockito.when(recurringServiceRecordRepository.getWritableDatabase()).thenReturn(sqliteDatabase);69 ServiceRecord serviceRecord = new ServiceRecord();70 serviceRecord.setId(0l);71 recurringServiceRecordRepository.add(serviceRecord);72 Mockito.verify(sqliteDatabase, Mockito.times(1))73 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),74 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));75 }76 @Test77 public void verifyAddCallsDatabaseDatabaseMethod0TimesInCaseOfNullVaccine() {78 recurringServiceRecordRepository.add(null);79 Mockito.verify(sqliteDatabase, Mockito.times(0))80 .insert(org.mockito.ArgumentMatchers.anyString(), (String) org.mockito.ArgumentMatchers.isNull(),81 org.mockito.ArgumentMatchers.any(ContentValues.class));82 Mockito.verify(sqliteDatabase, Mockito.times(0))83 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),84 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));85 }86 @Test87 public void verifyFindbyEntityIDcallsDatabaseQueryMethod1Times() {88 RecurringServiceRecordRepository recurringServiceRecordRepositoryspy = PowerMockito89 .spy(recurringServiceRecordRepository);90 String[] columns = new String[]{RecurringServiceRecordRepository.ID_COLUMN, RecurringServiceRecordRepository.BASE_ENTITY_ID, RecurringServiceRecordRepository.PROGRAM_CLIENT_ID, RecurringServiceRecordRepository.RECURRING_SERVICE_ID, RecurringServiceRecordRepository.VALUE, RecurringServiceRecordRepository.DATE, RecurringServiceRecordRepository.ANMID, RecurringServiceRecordRepository.LOCATION_ID, RecurringServiceRecordRepository.SYNC_STATUS, RecurringServiceRecordRepository.EVENT_ID, RecurringServiceRecordRepository.FORMSUBMISSION_ID, RecurringServiceRecordRepository.UPDATED_AT_COLUMN, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.NAME};91 MatrixCursor cursor = new MatrixCursor(columns);92 cursor.addRow(new Object[]{1l, "", "", 1l, "", magicNumber, "", "", "", "", "", 1l, magicType, magicNAME});93 cursor.addRow(new Object[]{1l, "", "", 1l, "", magicNumber, "", "", "", "", "", 1l, "", ""});94 Mockito.when(sqliteDatabase95 .rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class)))96 .thenReturn(cursor);97 Mockito.when(recurringServiceRecordRepositoryspy.getReadableDatabase()).thenReturn(sqliteDatabase);98 recurringServiceRecordRepositoryspy.findByEntityId("entityID");99 Mockito.verify(sqliteDatabase, Mockito.times(1))100 .rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));101 }102 @Test103 public void verifyFindbyUniqueIDcallsDatabaseQueryMethod1Times() {104 String[] columns = new String[]{RecurringServiceRecordRepository.ID_COLUMN, RecurringServiceRecordRepository.BASE_ENTITY_ID, RecurringServiceRecordRepository.PROGRAM_CLIENT_ID, RecurringServiceRecordRepository.RECURRING_SERVICE_ID, RecurringServiceRecordRepository.VALUE, RecurringServiceRecordRepository.DATE, RecurringServiceRecordRepository.ANMID, RecurringServiceRecordRepository.LOCATION_ID, RecurringServiceRecordRepository.SYNC_STATUS, RecurringServiceRecordRepository.EVENT_ID, RecurringServiceRecordRepository.FORMSUBMISSION_ID, RecurringServiceRecordRepository.UPDATED_AT_COLUMN, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.NAME};105 MatrixCursor cursor = new MatrixCursor(columns);106 cursor.addRow(new Object[]{1l, "", "", 1l, "", magicNumber, "", "", "", "", "", 1l, magicType, magicNAME});107 ServiceRecord serviceRecord = new ServiceRecord();108 serviceRecord.setFormSubmissionId(FORMSUBMISSIONID);109 serviceRecord.setEventId(EVENTID);110 recurringServiceRecordRepository.findUnique(null, serviceRecord);111 Mockito.when(sqliteDatabase112 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),113 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),114 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),115 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class)))116 .thenReturn(cursor);117 Mockito.when(recurringServiceRecordRepository.getReadableDatabase()).thenReturn(sqliteDatabase);118 recurringServiceRecordRepository.findUnique(sqliteDatabase, serviceRecord);119 Mockito.verify(sqliteDatabase, Mockito.times(1))120 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),121 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),122 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),123 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class));124 recurringServiceRecordRepository.findUnique(sqliteDatabase, null);125 }126 @Test127 public void assertAndVerifyFindbyCaseIDcallsDatabaseQueryMethod1Times() {128 String[] columns = new String[]{RecurringServiceRecordRepository.ID_COLUMN, RecurringServiceRecordRepository.BASE_ENTITY_ID, RecurringServiceRecordRepository.PROGRAM_CLIENT_ID, RecurringServiceRecordRepository.RECURRING_SERVICE_ID, RecurringServiceRecordRepository.VALUE, RecurringServiceRecordRepository.DATE, RecurringServiceRecordRepository.ANMID, RecurringServiceRecordRepository.LOCATION_ID, RecurringServiceRecordRepository.SYNC_STATUS, RecurringServiceRecordRepository.EVENT_ID, RecurringServiceRecordRepository.FORMSUBMISSION_ID, RecurringServiceRecordRepository.UPDATED_AT_COLUMN, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.NAME};129 MatrixCursor cursor = new MatrixCursor(columns);130 cursor.addRow(new Object[]{1l, "", "", 1l, "", magicNumber, "", "", "", "", "", 1l, magicType, magicNAME});131 Assert.assertNull(recurringServiceRecordRepository.find(0l));132 Mockito.when(sqliteDatabase133 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),134 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),135 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),136 org.mockito.ArgumentMatchers.isNull(String.class),137 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);138 Mockito.when(recurringServiceRecordRepository.getReadableDatabase()).thenReturn(sqliteDatabase);139 recurringServiceRecordRepository.find(0l);140 Mockito.verify(sqliteDatabase, Mockito.times(1))141 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),142 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),143 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),144 org.mockito.ArgumentMatchers.isNull(String.class),145 org.mockito.ArgumentMatchers.isNull(String.class));146 }147 @Test148 public void verifyUpdateCallsDatabaseUpdateMethod1Times() {149 ServiceRecord serviceRecord = new ServiceRecord();150 serviceRecord.setId(0l);151 recurringServiceRecordRepository.update(null, serviceRecord);152 Mockito.when(recurringServiceRecordRepository.getReadableDatabase()).thenReturn(sqliteDatabase);153 recurringServiceRecordRepository.update(sqliteDatabase, null);154 recurringServiceRecordRepository.update(null, serviceRecord);155 recurringServiceRecordRepository.update(sqliteDatabase, serviceRecord);156 Mockito.verify(sqliteDatabase, Mockito.times(1))157 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),158 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));159 }160 @Test161 public void verifyDeletecallsDatabaseDeleteMethod1Times() {162 RecurringServiceRecordRepository recurringServiceRecordRepositoryspy = Mockito.spy(recurringServiceRecordRepository);163 ServiceRecord serviceRecord = new ServiceRecord();164 serviceRecord.setBaseEntityId("baseEntityID");165 serviceRecord.setName(magicNAME);166 serviceRecord.setFormSubmissionId(FORMSUBMISSIONID);167 serviceRecord.setEventId(EVENTID);168 Mockito.doReturn(serviceRecord).when(recurringServiceRecordRepositoryspy).find(0l);169 recurringServiceRecordRepository.deleteServiceRecord(0l);170 Mockito.when(recurringServiceRecordRepositoryspy.getWritableDatabase()).thenReturn(sqliteDatabase);171 recurringServiceRecordRepositoryspy.deleteServiceRecord(0l);172 Mockito.verify(sqliteDatabase, Mockito.times(1))173 .delete(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(),174 org.mockito.ArgumentMatchers.any(String[].class));175 }176 @Test177 public void verifycloseMethodCallsInternalMethodsWithCorrectParams() {178 Mockito.when(recurringServiceRecordRepository.getWritableDatabase()).thenReturn(sqliteDatabase);179 recurringServiceRecordRepository.close(5l);180 Mockito.verify(recurringServiceRecordRepository.getWritableDatabase(), Mockito.times(1))181 .update(org.mockito.ArgumentMatchers.eq(RecurringServiceRecordRepository.TABLE_NAME),182 (ContentValues) org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.anyString(),183 org.mockito.ArgumentMatchers.eq(new String[]{"5"}));184 }185 @Test186 public void verifyCloseMethodFailsSilentlyWithNullParams() {187 Mockito.when(recurringServiceRecordRepository.getWritableDatabase()).thenReturn(sqliteDatabase);188 recurringServiceRecordRepository.close(null);189 Mockito.verify(recurringServiceRecordRepository.getWritableDatabase(), Mockito.times(0))190 .update(org.mockito.ArgumentMatchers.anyString(), (ContentValues) org.mockito.ArgumentMatchers.any(),191 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.eq(new String[]{"5"}));192 }193 @Test194 public void assertRemoveHyphenMethodRemoveHyphenFromString() {195 String testString = RecurringServiceRecordRepository.removeHyphen("test_string");196 org.junit.Assert.assertNotNull(testString);197 junit.framework.Assert.assertFalse(testString.contains("-"));198 }199 @Test200 public void assertFindUnSyncedBeforeTimeTest() {201 String[] columns = new String[]{RecurringServiceRecordRepository.ID_COLUMN, RecurringServiceRecordRepository.BASE_ENTITY_ID, RecurringServiceRecordRepository.PROGRAM_CLIENT_ID, RecurringServiceRecordRepository.RECURRING_SERVICE_ID, RecurringServiceRecordRepository.VALUE, RecurringServiceRecordRepository.DATE, RecurringServiceRecordRepository.ANMID, RecurringServiceRecordRepository.LOCATION_ID, RecurringServiceRecordRepository.SYNC_STATUS, RecurringServiceRecordRepository.EVENT_ID, RecurringServiceRecordRepository.FORMSUBMISSION_ID, RecurringServiceRecordRepository.UPDATED_AT_COLUMN, RecurringServiceTypeRepository.TYPE, RecurringServiceTypeRepository.NAME};202 MatrixCursor cursor = new MatrixCursor(columns);203 cursor.addRow(new Object[]{1l, "", "", 1l, "", magicNumber, "", "", "", "", "", 1l, magicType, magicNAME});204 Mockito.when(recurringServiceRecordRepository.getReadableDatabase()).thenReturn(sqliteDatabase);205 Mockito.when(sqliteDatabase206 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),207 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),208 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),209 org.mockito.ArgumentMatchers.isNull(String.class),210 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);211 Assert.assertNotNull(recurringServiceRecordRepository.findUnSyncedBeforeTime(magicNumber10));212 }213}...

Full Screen

Full Screen

Source:AlertRepositoryTest.java Github

copy

Full Screen

...59 matrixCursor.addRow(alertRow);60 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);61 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);62 alertRepository.updateMasterRepository(repository);63 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);64 Assert.assertNotNull(alertRepository.allAlerts());65 }66 @Test67 public void createAlertsCallsInsert1TimeForNewALerts() throws Exception {68 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);69// matrixCursor.addRow(alertRow);70 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);71 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);72 alertRepository.updateMasterRepository(repository);73 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);74 Alert alert = new Alert("caseID", "scheduleName", "visitCode", AlertStatus.urgent, "startDate", "expiryDate", true);75 alertRepository.createAlert(alert);76 Mockito.verify(sqliteDatabase, Mockito.times(1)).insert(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.any(ContentValues.class));77 }78 @Test79 public void createAlertsCallsUpdate1TimeForOldALerts() throws Exception {80 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);81 matrixCursor.addRow(alertRow);82 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);83 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);84 alertRepository.updateMasterRepository(repository);85 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);86 Alert alert = new Alert("caseID", "scheduleName", "visitCode", AlertStatus.urgent, "startDate", "expiryDate", true);87 alertRepository.createAlert(alert);88 Mockito.verify(sqliteDatabase, Mockito.times(1)).update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));89 }90 @Test91 public void changeAlertStatusToInProcess1CallsUpdate1Time() throws Exception {92 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);93 matrixCursor.addRow(alertRow);94 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);95 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);96 alertRepository.updateMasterRepository(repository);97 alertRepository.changeAlertStatusToInProcess("caseID", "scheduleName");98 Mockito.verify(sqliteDatabase, Mockito.times(1)).update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));99 }100 @Test101 public void changeAlertStatusToCompleteCallsUpdate1Time() throws Exception {102 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);103 matrixCursor.addRow(alertRow);104 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);105 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);106 alertRepository.updateMasterRepository(repository);107 alertRepository.changeAlertStatusToComplete("caseID", "scheduleName");108 Mockito.verify(sqliteDatabase, Mockito.times(1)).update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));109 }110 @Test111 public void markAlertAsClosedCallsUpdate1Time() throws Exception {112 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);113 matrixCursor.addRow(alertRow);114 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);115 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);116 alertRepository.updateMasterRepository(repository);117 alertRepository.markAlertAsClosed("caseID", "scheduleName", "completionDate");118 Mockito.verify(sqliteDatabase, Mockito.times(1)).update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));119 }120 @Test121 public void filterActiveAlertsReturnsNotNull() throws Exception {122 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);123 LocalDate today = LocalDate.now();124 today = today.plusDays(5);125 Object[] alertRowForActiveALerts = {"caseID", "scheduleName", "visitCode", "urgent", "", today.toString(), "", 1};126 matrixCursor.addRow(alertRowForActiveALerts);127 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);128 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);129 alertRepository.updateMasterRepository(repository);130 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);131 Assert.assertNotNull(alertRepository.allActiveAlertsForCase("caseID"));132 }133 @Test134 public void deleteAllAlertsForEntityCallsDelete1Times() throws Exception {135 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);136 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);137 alertRepository.updateMasterRepository(repository);138 alertRepository.deleteAllAlertsForEntity("caseID");139 Mockito.verify(sqliteDatabase, Mockito.times(1)).delete(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));140 }141 @Test142 public void deleteAllOfflineAlertsForEntityCallsDelete1Times() throws Exception {143 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);144 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);145 alertRepository.updateMasterRepository(repository);146 alertRepository.deleteOfflineAlertsForEntity("caseID");147 Mockito.verify(sqliteDatabase, Mockito.times(1)).delete(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));148 }149 @Test150 public void deleteAllOfflineAlertsForEntityAndNameCallsDelete1Times() throws Exception {151 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);152 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);153 alertRepository.updateMasterRepository(repository);154 alertRepository.deleteOfflineAlertsForEntity("caseID", "name1", "name2");155 Mockito.verify(sqliteDatabase, Mockito.times(1)).delete(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));156 }157 @Test158 public void deleteAllAlertsCallsDelete1Times() throws Exception {159 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);160 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);161 alertRepository.updateMasterRepository(repository);162 alertRepository.deleteAllAlerts();163 Mockito.verify(sqliteDatabase, Mockito.times(1)).delete(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String[].class));164 }165 @Test166 public void findByEntityIDReturnNotNUll() throws Exception {167 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);168 matrixCursor.addRow(alertRow);169 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);170 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);171 alertRepository.updateMasterRepository(repository);172 Mockito.when(sqliteDatabase.rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class))).thenReturn(matrixCursor);173 Assert.assertNotNull(alertRepository.findByEntityId("caseID"));174 }175 @Test176 public void findByEntityIdAndAlertNamesReturnNotNUll() throws Exception {177 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);178 matrixCursor.addRow(alertRow);179 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);180 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);181 alertRepository.updateMasterRepository(repository);182 Mockito.when(sqliteDatabase.rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class))).thenReturn(matrixCursor);183 Assert.assertNotNull(alertRepository.findByEntityIdAndAlertNames("caseID", "names1", "names2"));184 }185 @Test186 public void findOfflineByEntityIdAndAlertNamesReturnNotNUll() throws Exception {187 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);188 matrixCursor.addRow(alertRow);189 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);190 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);191 alertRepository.updateMasterRepository(repository);192 Mockito.when(sqliteDatabase.rawQuery(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class))).thenReturn(matrixCursor);193 Assert.assertNotNull(alertRepository.findOfflineByEntityIdAndName("caseID", "names1", "names2"));194 }195 @Test196 public void findByEntityIdAndScheduleNameReturnNotNUll() throws Exception {197 MatrixCursor matrixCursor = new MatrixCursor(alertColumns);198 matrixCursor.addRow(alertRow);199 when(repository.getReadableDatabase()).thenReturn(sqliteDatabase);200 when(repository.getWritableDatabase()).thenReturn(sqliteDatabase);201 alertRepository.updateMasterRepository(repository);202 Mockito.when(sqliteDatabase.query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(matrixCursor);203 Assert.assertNotNull(alertRepository.findByEntityIdAndScheduleName("caseID", "Schedulenames"));204 }205}...

Full Screen

Full Screen

Source:VaccineTypeRepositoryTest.java Github

copy

Full Screen

...72 VaccineType vaccineType = PowerMockito.mock(VaccineType.class);73 Mockito.when(vaccineType.getId()).thenReturn(null);74 vaccineTypeRepository.add(vaccineType, sqliteDatabase);75 Mockito.verify(sqliteDatabase, Mockito.times(1))76 .insert(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.isNull(String.class),77 org.mockito.ArgumentMatchers.any(ContentValues.class));78 }79 @Test80 public void verifyAddCallsDatabaseDatabaseMethod1TimesInCaseOfNonNullVaccineNotNullID() {81 Mockito.when(vaccineTypeRepository.getWritableDatabase()).thenReturn(sqliteDatabase);82 VaccineType vaccineType = new VaccineType(0l, 0, "", "", "", "");83 vaccineTypeRepository.add(vaccineType, sqliteDatabase);84 Mockito.verify(sqliteDatabase, Mockito.times(1))85 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),86 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));87 }88 @Test89 public void verifyAddCallsDatabaseDatabaseMethod0TimesInCaseOfNullVaccine() {90 vaccineTypeRepository.add(null, sqliteDatabase);91 Mockito.verify(sqliteDatabase, Mockito.times(0))92 .insert(org.mockito.ArgumentMatchers.anyString(), (String) org.mockito.ArgumentMatchers.isNull(),93 org.mockito.ArgumentMatchers.any(ContentValues.class));94 Mockito.verify(sqliteDatabase, Mockito.times(0))95 .update(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(ContentValues.class),96 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class));97 }98 @Test99 public void verifyFindbyEntityIDcallsDatabaseQueryMethod1Times() {100 Cursor cursor = PowerMockito.mock(Cursor.class);101 Mockito.when(sqliteDatabase102 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),103 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),104 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),105 org.mockito.ArgumentMatchers.isNull(String.class),106 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);107 Mockito.when(vaccineTypeRepository.getReadableDatabase()).thenReturn(sqliteDatabase);108 vaccineTypeRepository.findIDByName("Name");109 Mockito.verify(sqliteDatabase, Mockito.times(1))110 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),111 org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),112 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),113 org.mockito.ArgumentMatchers.isNull(String.class),114 org.mockito.ArgumentMatchers.isNull(String.class));115 }116 @Test117 public void verifyFindallVaccineTypcallsDatabaseQueryMethod1Times() {118 // Cursor cursor = PowerMockito.mock(Cursor.class);119 String[] columns = new String[] {VaccineTypeRepository.ID_COLUMN, VaccineTypeRepository.DOSES, VaccineTypeRepository.NAME, VaccineTypeRepository.OPENMRS_PARENT_ENTITIY_ID, VaccineTypeRepository.OPENMRS_DATE_CONCEPT_ID, VaccineTypeRepository.OPENMRS_DOSE_CONCEPT_ID};120 MatrixCursor cursor = new MatrixCursor(columns);121 cursor.addRow(new Object[] {1l, 1, "", "", "", ""});122 Mockito.when(sqliteDatabase123 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),124 org.mockito.ArgumentMatchers.isNull(String.class),125 org.mockito.ArgumentMatchers.isNull(String[].class),126 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),127 org.mockito.ArgumentMatchers.isNull(String.class),128 org.mockito.ArgumentMatchers.isNull(String.class))).thenReturn(cursor);129 Mockito.when(vaccineTypeRepository.getReadableDatabase()).thenReturn(sqliteDatabase);130 vaccineTypeRepository.getAllVaccineTypes(sqliteDatabase);131 Mockito.verify(sqliteDatabase, Mockito.times(1))132 .query(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(String[].class),133 org.mockito.ArgumentMatchers.isNull(String.class),134 org.mockito.ArgumentMatchers.isNull(String[].class),135 org.mockito.ArgumentMatchers.isNull(String.class), org.mockito.ArgumentMatchers.isNull(String.class),136 org.mockito.ArgumentMatchers.isNull(String.class),137 org.mockito.ArgumentMatchers.isNull(String.class));138 }139}...

Full Screen

Full Screen

Source:Slf4jLoggerTest.java Github

copy

Full Screen

...20import org.slf4j.spi.LocationAwareLogger;21import static org.mockito.ArgumentMatchers.any;22import static org.mockito.ArgumentMatchers.anyInt;23import static org.mockito.ArgumentMatchers.anyString;24import static org.mockito.ArgumentMatchers.isNull;25import static org.mockito.Mockito.mock;26import static org.mockito.Mockito.verify;27import static org.mockito.internal.verification.VerificationModeFactory.times;28public class Slf4jLoggerTest {29 @Test30 public void testLocationAwareLogger() {31 LocationAwareLogger locationAwareLogger = mock(LocationAwareLogger.class);32 Slf4jLogger logger = new Slf4jLogger(locationAwareLogger);33 logger.error("error");34 logger.warn("warn");35 logger.info("info");36 logger.debug("debug");37 logger.trace("info");38 verify(locationAwareLogger, times(5)).log(isNull(Marker.class), anyString(),39 anyInt(), anyString(), isNull(Object[].class), isNull(Throwable.class));40 logger.error(new Exception("error"));41 logger.warn(new Exception("warn"));42 logger.info(new Exception("info"));43 logger.debug(new Exception("debug"));44 logger.trace(new Exception("trace"));45 logger.error("error", new Exception("error"));46 logger.warn("warn", new Exception("warn"));47 logger.info("info", new Exception("info"));48 logger.debug("debug", new Exception("debug"));49 logger.trace("trace", new Exception("trace"));50 verify(locationAwareLogger, times(10)).log(isNull(Marker.class), anyString(),51 anyInt(), anyString(), isNull(Object[].class), any(Throwable.class));52 }53}...

Full Screen

Full Screen

isNull

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.isNull;2import static org.mockito.Mockito.verify;3import static org.mockito.Mockito.when;4import org.junit.Test;5import org.junit.runner.RunWith;6import org.mockito.Mock;7import org.mockito.junit.MockitoJUnitRunner;8import java.util.List;9@RunWith(MockitoJUnitRunner.class)10public class MockitoDemo {11List<String> list;12public void test() {13when(list.get(0)).thenReturn("abc");14verify(list).get(isNull());15}16}17-> at org.mockito.Mockito.verify(Mockito.java:202)18verify(mock).someMethod(anyObject(), "raw String");19verify(mock).someMethod(anyObject(), eq("String by matcher"));20at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)21at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)22at org.junit.runner.JUnitCore.run(JUnitCore.java:137)23at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)24at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)25at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)26at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)27import static org.mockito.ArgumentMatchers.isNotNull;28import static org.mockito.Mockito.verify;29import static org.mockito.Mockito.when;30import org.junit.Test;31import org.junit.runner.RunWith;32import org.mockito.Mock;33import org.mockito.junit.MockitoJUnitRunner;34import java.util.List;35@RunWith(MockitoJUnitRunner.class)36public class MockitoDemo {37List<String> list;38public void test() {39when(list.get(0)).thenReturn("abc");

Full Screen

Full Screen

isNull

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.junit;2import static org.mockito.ArgumentMatchers.isNull;3import static org.mockito.Mockito.mock;4import static org.mockito.Mockito.when;5import org.junit.Test;6public class IsNullMethodTest {7 public void testIsNullMethod() {8 User user = mock(User.class);9 when(user.getName()).thenReturn("John");10 when(user.getAge()).thenReturn(25);11 when(user.getGender()).thenReturn(isNull());12 }13}14package com.automationrhapsody.junit;15import static org.mockito.Matchers.isNull;16import static org.mockito.Mockito.mock;17import static org.mockito.Mockito.when;18import org.junit.Test;19public class IsNullMethodTest {20 public void testIsNullMethod() {21 User user = mock(User.class);22 when(user.getName()).thenReturn("John");23 when(user.getAge()).thenReturn(25);24 when(user.getGender()).thenReturn(isNull());25 }26}

Full Screen

Full Screen

isNull

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.junit;2import static org.junit.Assert.*;3import static org.mockito.ArgumentMatchers.isNull;4import static org.mockito.Mockito.*;5import java.util.List;6import org.junit.Test;7public class NullArgumentTest {8 public void testNullArgument() {9 List<String> mockedList = mock(List.class);10 when(mockedList.get(isNull())).thenReturn("Hello Mockito!");11 assertEquals("Hello Mockito!", mockedList.get(null));12 }13}

Full Screen

Full Screen

isNull

Using AI Code Generation

copy

Full Screen

1package com.automationtestinghub;2import static org.mockito.ArgumentMatchers.isNull;3import static org.mockito.Mockito.mock;4import static org.mockito.Mockito.when;5import org.junit.Test;6public class MockitoIsNullMethod {7 public void testIsNullMethod() {8 Demo demo = mock(Demo.class);9 when(demo.isNull(isNull())).thenReturn("null");10 demo.isNull(null);11 demo.isNull(null);12 }13}14package com.automationtestinghub;15import static org.mockito.Matchers.isNull;16import static org.mockito.Mockito.mock;17import static org.mockito.Mockito.when;18import org.junit.Test;19public class MockitoIsNullMethod {20 public void testIsNullMethod() {21 Demo demo = mock(Demo.class);22 when(demo.isNull(isNull())).thenReturn("null");23 demo.isNull(null);24 demo.isNull(null);25 }26}27package com.automationtestinghub;28import static org.mockito.Mockito.isNull;29import static org.mockito.Mockito.mock;30import static org.mockito.Mockito.when;31import org.junit.Test;32public class MockitoIsNullMethod {33 public void testIsNullMethod() {34 Demo demo = mock(Demo.class);35 when(demo.isNull(isNull())).thenReturn("null");36 demo.isNull(null);37 demo.isNull(null);38 }39}40package com.automationtestinghub;41import static org.mockito.Matchers.isNull;42import static org.mockito.Mockito.mock;43import static org.mockito.Mockito.when;44import org.junit.Test;45public class MockitoIsNullMethod {46 public void testIsNullMethod() {47 Demo demo = mock(Demo.class);48 when(demo.isNull(isNull())).thenReturn("null");49 demo.isNull(null);50 demo.isNull(null);51 }52}

Full Screen

Full Screen

isNull

Using AI Code Generation

copy

Full Screen

1public class Test {2 public void test() {3 List<String> mockList = mock(List.class);4 when(mockList.get(0)).thenReturn("Hello");5 when(mockList.get(isNull())).thenReturn("Hello");6 assertEquals("Hello", mockList.get(0));7 assertEquals("Hello", mockList.get(null));8 }9}10public class Test {11 public void test() {12 List<String> mockList = mock(List.class);13 when(mockList.get(0)).thenReturn("Hello");14 when(mockList.get(isNull())).thenReturn("Hello");15 assertEquals("Hello", mockList.get(0));16 assertEquals("Hello", mockList.get(null));17 }18}19public class Test {20 public void test() {21 List<String> mockList = mock(List.class);22 when(mockList.get(0)).thenReturn("Hello");23 when(mockList.get(anyInt())).thenReturn("Hello");24 assertEquals("Hello", mockList.get(0));25 assertEquals("Hello", mockList.get(null));26 }27}28public class Test {29 public void test() {30 List<String> mockList = mock(List.class);31 when(mockList.get(0)).thenReturn("Hello");32 when(mockList.get(anyInt())).thenReturn("Hello");33 assertEquals("Hello", mockList.get(0));34 assertEquals("Hello", mockList.get(null));35 }36}37public class Test {38 public void test() {39 List<String> mockList = mock(List.class);40 when(mockList.get(0)).thenReturn("Hello");41 when(mockList.get(any(Integer.class))).thenReturn("Hello");42 assertEquals("Hello", mockList.get(0));43 assertEquals("Hello", mockList.get(null));44 }45}46public class Test {47 public void test() {48 List<String> mockList = mock(List.class);49 when(mockList.get

Full Screen

Full Screen

isNull

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3public class 1 {4 public static void main(String[] args) {5 String str = null;6 Mockito.when(str).thenReturn("Hello World");7 System.out.println(str);8 }9}10 at 1.main(1.java:10)11import org.mockito.ArgumentMatchers;12import org.mockito.Mockito;13public class 2 {14 public static void main(String[] args) {15 String str = null;16 Mockito.when(str).thenReturn("Hello World");17 System.out.println(str);18 }19}20 at 2.main(2.java:10)21import org.mockito.ArgumentMatchers;22import org.mockito.Mockito;23public class 3 {24 public static void main(String[] args) {25 String str = null;26 Mockito.when(str).thenReturn("Hello World");27 System.out.println(str);28 }29}30 at 3.main(3.java:10)31import org.mockito.ArgumentMatchers;32import org.mockito.Mockito;33public class 4 {34 public static void main(String[] args) {35 String str = null;36 Mockito.when(str).thenReturn("Hello World");37 System.out.println(str);38 }39}40 at 4.main(4.java:10)41import org.mockito.ArgumentMatchers;42import org.mockito.Mockito;43public class 5 {44 public static void main(String[] args) {45 String str = null;46 Mockito.when(str).thenReturn("Hello World");47 System.out.println(str);48 }49}50 at 5.main(5.java:10)51import org.mockito.ArgumentMatchers;52import org.mockito.Mockito;53public class 6 {54 public static void main(String[] args) {55 String str = null;56 Mockito.when(str).thenReturn("Hello World");57 System.out.println(str);58 }59}

Full Screen

Full Screen

isNull

Using AI Code Generation

copy

Full Screen

1public class Test {2 public void test(){3 List<String> list = mock(List.class);4 list.add(null);5 verify(list).add(isNull());6 }7}

Full Screen

Full Screen

isNull

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3public class IsNullExample {4 public static void main(String[] args) {5 MyService service = Mockito.mock(MyService.class);6 service.doSomething(ArgumentMatchers.isNull());7 Mockito.verify(service).doSomething(ArgumentMatchers.isNull());8 }9}10import org.mockito.Matchers;11import org.mockito.Mockito;12public class IsNullExample {13 public static void main(String[] args) {14 MyService service = Mockito.mock(MyService.class);15 service.doSomething(Matchers.isNull());16 Mockito.verify(service).doSomething(Matchers.isNull());17 }18}19import org.mockito.Matchers;20import org.mockito.Mockito;21public class IsNullExample {22 public static void main(String[] args) {23 MyService service = Mockito.mock(MyService.class);24 service.doSomething(Matchers.isNull());25 Mockito.verify(service).doSomething(Matchers.isNull());26 }27}28import org.mockito.ArgumentMatchers;29import org.mockito.Mockito;30public class IsNullExample {31 public static void main(String[] args) {32 MyService service = Mockito.mock(MyService.class);33 service.doSomething(ArgumentMatchers.isNull());34 Mockito.verify(service).doSomething(ArgumentMatchers.isNull());35 }36}37import org.mockito.Matchers;38import org.mockito.Mockito;39public class IsNullExample {40 public static void main(String[] args) {41 MyService service = Mockito.mock(MyService.class);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful