How to use long method of test.Open class

Best Mockito-kotlin code snippet using test.Open.long

EventBundleCreatorTest.kt

Source:EventBundleCreatorTest.kt Github

copy

Full Screen

...85 val bundle = Bundle()86 val typeName = eventBundleCreator.fillEventBundle(EventLog.getDefaultInstance(), bundle)87 assertThat(typeName).isEqualTo("unknown_activity_context")88 assertThat(bundle).hasSize(2)89 assertThat(bundle).longInt("timestamp").isEqualTo(0)90 assertThat(bundle).string("priority").isEqualTo("unspecified_priority")91 }92 @Test93 fun testFillEventBundle_eventWithDefaultedContext_fillsPriorityAndTimeAndRetsUnknownContext() {94 setUpTestApplicationComponent()95 val bundle = Bundle()96 val eventLog = createEventLog(timestamp = TEST_TIMESTAMP_1, priority = ESSENTIAL)97 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)98 assertThat(typeName).isEqualTo("unknown_activity_context")99 assertThat(bundle).hasSize(2)100 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)101 assertThat(bundle).string("priority").isEqualTo("essential")102 }103 @Test104 fun testFillEventBundle_eventWithDifferentTimestamp_savesDifferentTimestampInBundle() {105 setUpTestApplicationComponent()106 val bundle = Bundle()107 val eventLog = createEventLog(timestamp = TEST_TIMESTAMP_2)108 eventBundleCreator.fillEventBundle(eventLog, bundle)109 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_2)110 }111 @Test112 fun testFillEventBundle_eventWithDifferentPriority_savesDifferentPriorityInBundle() {113 setUpTestApplicationComponent()114 val bundle = Bundle()115 val eventLog = createEventLog(priority = OPTIONAL)116 eventBundleCreator.fillEventBundle(eventLog, bundle)117 assertThat(bundle).string("priority").isEqualTo("optional")118 }119 @Test120 fun testFillEventBundle_openExpActivityEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {121 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()122 val bundle = Bundle()123 val eventLog = createEventLog(context = createOpenExplorationActivity())124 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)125 assertThat(typeName).isEqualTo("open_exploration_activity")126 assertThat(bundle).hasSize(8)127 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)128 assertThat(bundle).string("priority").isEqualTo("essential")129 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)130 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)131 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)132 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)133 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)134 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)135 }136 @Test137 fun testFillEventBundle_openExpActivityEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {138 setUpTestApplicationComponentWithLearnerAnalyticsStudy()139 val bundle = Bundle()140 val eventLog = createEventLog(context = createOpenExplorationActivity())141 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)142 assertThat(typeName).isEqualTo("open_exploration_activity")143 assertThat(bundle).hasSize(10)144 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)145 assertThat(bundle).string("priority").isEqualTo("essential")146 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)147 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)148 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)149 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)150 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)151 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)152 assertThat(bundle).string("ld_learner_id").isEqualTo(TEST_LEARNER_ID)153 assertThat(bundle).string("ld_install_id").isEqualTo(TEST_INSTALLATION_ID)154 }155 @Test156 fun testFillEventBundle_openInfoTabContextEvent_fillsAllFieldsInBundleAndReturnsName() {157 setUpTestApplicationComponent()158 val bundle = Bundle()159 val eventLog = createEventLog(context = createOpenInfoTab())160 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)161 assertThat(typeName).isEqualTo("open_info_tab")162 assertThat(bundle).hasSize(3)163 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)164 assertThat(bundle).string("priority").isEqualTo("essential")165 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)166 }167 @Test168 fun testFillEventBundle_openLessonsTabContextEvent_fillsAllFieldsInBundleAndReturnsName() {169 setUpTestApplicationComponent()170 val bundle = Bundle()171 val eventLog = createEventLog(context = createOpenLessonsTab())172 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)173 assertThat(typeName).isEqualTo("open_lessons_tab")174 assertThat(bundle).hasSize(3)175 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)176 assertThat(bundle).string("priority").isEqualTo("essential")177 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)178 }179 @Test180 fun testFillEventBundle_openPracticeTabContextEvent_fillsAllFieldsInBundleAndReturnsName() {181 setUpTestApplicationComponent()182 val bundle = Bundle()183 val eventLog = createEventLog(context = createOpenPracticeTab())184 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)185 assertThat(typeName).isEqualTo("open_practice_tab")186 assertThat(bundle).hasSize(3)187 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)188 assertThat(bundle).string("priority").isEqualTo("essential")189 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)190 }191 @Test192 fun testFillEventBundle_openRevisionTabContextEvent_fillsAllFieldsInBundleAndReturnsName() {193 setUpTestApplicationComponent()194 val bundle = Bundle()195 val eventLog = createEventLog(context = createOpenRevisionTab())196 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)197 assertThat(typeName).isEqualTo("open_revision_tab")198 assertThat(bundle).hasSize(3)199 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)200 assertThat(bundle).string("priority").isEqualTo("essential")201 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)202 }203 @Test204 fun testFillEventBundle_openQuestionPlayerContextEvent_fillsAllFieldsInBundleAndReturnsName() {205 setUpTestApplicationComponent()206 val bundle = Bundle()207 val eventLog = createEventLog(context = createOpenQuestionPlayer())208 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)209 assertThat(typeName).isEqualTo("open_question_player")210 assertThat(bundle).hasSize(4)211 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)212 assertThat(bundle).string("priority").isEqualTo("essential")213 assertThat(bundle).string("question_id").isEqualTo(TEST_QUESTION_ID)214 assertThat(bundle).string("skill_ids").isEqualTo("$TEST_SKILL_ID_1,$TEST_SKILL_ID_2")215 }216 @Test217 fun testFillEventBundle_openStoryActivityContextEvent_fillsAllFieldsInBundleAndReturnsName() {218 setUpTestApplicationComponent()219 val bundle = Bundle()220 val eventLog = createEventLog(context = createOpenStoryActivity())221 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)222 assertThat(typeName).isEqualTo("open_story_activity")223 assertThat(bundle).hasSize(4)224 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)225 assertThat(bundle).string("priority").isEqualTo("essential")226 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)227 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)228 }229 @Test230 fun testFillEventBundle_openConceptCardContextEvent_fillsAllFieldsInBundleAndReturnsName() {231 setUpTestApplicationComponent()232 val bundle = Bundle()233 val eventLog = createEventLog(context = createOpenConceptCard())234 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)235 assertThat(typeName).isEqualTo("open_concept_card")236 assertThat(bundle).hasSize(3)237 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)238 assertThat(bundle).string("priority").isEqualTo("essential")239 assertThat(bundle).string("skill_id").isEqualTo(TEST_SKILL_ID_1)240 }241 @Test242 fun testFillEventBundle_openRevisionCardContextEvent_fillsAllFieldsInBundleAndReturnsName() {243 setUpTestApplicationComponent()244 val bundle = Bundle()245 val eventLog = createEventLog(context = createOpenRevisionCard())246 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)247 assertThat(typeName).isEqualTo("open_revision_card")248 assertThat(bundle).hasSize(4)249 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)250 assertThat(bundle).string("priority").isEqualTo("essential")251 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)252 assertThat(bundle).string("subtopic_index").isEqualTo(TEST_SUB_TOPIC_INDEX_STR)253 }254 @Test255 fun testFillEventBundle_startCardContextEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {256 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()257 val bundle = Bundle()258 val eventLog = createEventLog(context = createStartCardContext())259 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)260 assertThat(typeName).isEqualTo("start_card_context")261 assertThat(bundle).hasSize(9)262 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)263 assertThat(bundle).string("priority").isEqualTo("essential")264 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)265 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)266 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)267 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)268 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)269 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)270 assertThat(bundle).string("skill_id").isEqualTo(TEST_SKILL_ID_1)271 }272 @Test273 fun testFillEventBundle_startCardContextEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {274 setUpTestApplicationComponentWithLearnerAnalyticsStudy()275 val bundle = Bundle()276 val eventLog = createEventLog(context = createStartCardContext())277 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)278 assertThat(typeName).isEqualTo("start_card_context")279 assertThat(bundle).hasSize(11)280 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)281 assertThat(bundle).string("priority").isEqualTo("essential")282 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)283 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)284 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)285 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)286 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)287 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)288 assertThat(bundle).string("skill_id").isEqualTo(TEST_SKILL_ID_1)289 assertThat(bundle).string("ed_ld_learner_id").isEqualTo(TEST_LEARNER_ID)290 assertThat(bundle).string("ed_ld_install_id").isEqualTo(TEST_INSTALLATION_ID)291 }292 @Test293 fun testFillEventBundle_endCardContextEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {294 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()295 val bundle = Bundle()296 val eventLog = createEventLog(context = createEndCardContext())297 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)298 assertThat(typeName).isEqualTo("end_card_context")299 assertThat(bundle).hasSize(9)300 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)301 assertThat(bundle).string("priority").isEqualTo("essential")302 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)303 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)304 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)305 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)306 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)307 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)308 assertThat(bundle).string("skill_id").isEqualTo(TEST_SKILL_ID_1)309 }310 @Test311 fun testFillEventBundle_endCardContextEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {312 setUpTestApplicationComponentWithLearnerAnalyticsStudy()313 val bundle = Bundle()314 val eventLog = createEventLog(context = createEndCardContext())315 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)316 assertThat(typeName).isEqualTo("end_card_context")317 assertThat(bundle).hasSize(11)318 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)319 assertThat(bundle).string("priority").isEqualTo("essential")320 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)321 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)322 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)323 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)324 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)325 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)326 assertThat(bundle).string("skill_id").isEqualTo(TEST_SKILL_ID_1)327 assertThat(bundle).string("ed_ld_learner_id").isEqualTo(TEST_LEARNER_ID)328 assertThat(bundle).string("ed_ld_install_id").isEqualTo(TEST_INSTALLATION_ID)329 }330 @Test331 fun testFillEventBundle_hintOfferedEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {332 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()333 val bundle = Bundle()334 val eventLog = createEventLog(context = createHintOfferedContext())335 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)336 assertThat(typeName).isEqualTo("hint_offered_context")337 assertThat(bundle).hasSize(9)338 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)339 assertThat(bundle).string("priority").isEqualTo("essential")340 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)341 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)342 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)343 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)344 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)345 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)346 assertThat(bundle).string("hint_index").isEqualTo(TEST_HINT_INDEX_STR)347 }348 @Test349 fun testFillEventBundle_hintOfferedEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {350 setUpTestApplicationComponentWithLearnerAnalyticsStudy()351 val bundle = Bundle()352 val eventLog = createEventLog(context = createHintOfferedContext())353 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)354 assertThat(typeName).isEqualTo("hint_offered_context")355 assertThat(bundle).hasSize(11)356 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)357 assertThat(bundle).string("priority").isEqualTo("essential")358 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)359 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)360 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)361 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)362 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)363 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)364 assertThat(bundle).string("hint_index").isEqualTo(TEST_HINT_INDEX_STR)365 assertThat(bundle).string("ed_ld_learner_id").isEqualTo(TEST_LEARNER_ID)366 assertThat(bundle).string("ed_ld_install_id").isEqualTo(TEST_INSTALLATION_ID)367 }368 @Test369 fun testFillEventBundle_accessHintContextEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {370 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()371 val bundle = Bundle()372 val eventLog = createEventLog(context = createAccessHintContext())373 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)374 assertThat(typeName).isEqualTo("access_hint_context")375 assertThat(bundle).hasSize(9)376 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)377 assertThat(bundle).string("priority").isEqualTo("essential")378 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)379 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)380 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)381 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)382 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)383 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)384 assertThat(bundle).string("hint_index").isEqualTo(TEST_HINT_INDEX_STR)385 }386 @Test387 fun testFillEventBundle_accessHintContextEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {388 setUpTestApplicationComponentWithLearnerAnalyticsStudy()389 val bundle = Bundle()390 val eventLog = createEventLog(context = createAccessHintContext())391 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)392 assertThat(typeName).isEqualTo("access_hint_context")393 assertThat(bundle).hasSize(11)394 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)395 assertThat(bundle).string("priority").isEqualTo("essential")396 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)397 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)398 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)399 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)400 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)401 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)402 assertThat(bundle).string("hint_index").isEqualTo(TEST_HINT_INDEX_STR)403 assertThat(bundle).string("ed_ld_learner_id").isEqualTo(TEST_LEARNER_ID)404 assertThat(bundle).string("ed_ld_install_id").isEqualTo(TEST_INSTALLATION_ID)405 }406 @Test407 fun testFillEventBundle_solutionOfferedEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {408 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()409 val bundle = Bundle()410 val eventLog = createEventLog(context = createSolutionOfferedContext())411 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)412 assertThat(typeName).isEqualTo("solution_offered_context")413 assertThat(bundle).hasSize(8)414 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)415 assertThat(bundle).string("priority").isEqualTo("essential")416 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)417 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)418 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)419 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)420 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)421 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)422 }423 @Test424 fun testFillEventBundle_solutionOfferedEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {425 setUpTestApplicationComponentWithLearnerAnalyticsStudy()426 val bundle = Bundle()427 val eventLog = createEventLog(context = createSolutionOfferedContext())428 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)429 assertThat(typeName).isEqualTo("solution_offered_context")430 assertThat(bundle).hasSize(10)431 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)432 assertThat(bundle).string("priority").isEqualTo("essential")433 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)434 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)435 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)436 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)437 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)438 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)439 assertThat(bundle).string("ld_learner_id").isEqualTo(TEST_LEARNER_ID)440 assertThat(bundle).string("ld_install_id").isEqualTo(TEST_INSTALLATION_ID)441 }442 @Test443 fun testFillEventBundle_accessSolutionEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {444 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()445 val bundle = Bundle()446 val eventLog = createEventLog(context = createAccessSolutionContext())447 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)448 assertThat(typeName).isEqualTo("access_solution_context")449 assertThat(bundle).hasSize(8)450 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)451 assertThat(bundle).string("priority").isEqualTo("essential")452 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)453 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)454 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)455 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)456 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)457 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)458 }459 @Test460 fun testFillEventBundle_accessSolutionEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {461 setUpTestApplicationComponentWithLearnerAnalyticsStudy()462 val bundle = Bundle()463 val eventLog = createEventLog(context = createAccessSolutionContext())464 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)465 assertThat(typeName).isEqualTo("access_solution_context")466 assertThat(bundle).hasSize(10)467 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)468 assertThat(bundle).string("priority").isEqualTo("essential")469 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)470 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)471 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)472 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)473 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)474 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)475 assertThat(bundle).string("ld_learner_id").isEqualTo(TEST_LEARNER_ID)476 assertThat(bundle).string("ld_install_id").isEqualTo(TEST_INSTALLATION_ID)477 }478 @Test479 fun testFillEventBundle_submitAnswerEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {480 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()481 val bundle = Bundle()482 val eventLog = createEventLog(context = createSubmitAnswerContext())483 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)484 assertThat(typeName).isEqualTo("submit_answer_context")485 assertThat(bundle).hasSize(9)486 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)487 assertThat(bundle).string("priority").isEqualTo("essential")488 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)489 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)490 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)491 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)492 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)493 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)494 assertThat(bundle).string("is_answer_correct").isEqualTo(TEST_IS_ANSWER_CORRECT_STR)495 }496 @Test497 fun testFillEventBundle_submitAnswerEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {498 setUpTestApplicationComponentWithLearnerAnalyticsStudy()499 val bundle = Bundle()500 val eventLog = createEventLog(context = createSubmitAnswerContext())501 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)502 assertThat(typeName).isEqualTo("submit_answer_context")503 assertThat(bundle).hasSize(11)504 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)505 assertThat(bundle).string("priority").isEqualTo("essential")506 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)507 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)508 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)509 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)510 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)511 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)512 assertThat(bundle).string("is_answer_correct").isEqualTo(TEST_IS_ANSWER_CORRECT_STR)513 assertThat(bundle).string("ed_ld_learner_id").isEqualTo(TEST_LEARNER_ID)514 assertThat(bundle).string("ed_ld_install_id").isEqualTo(TEST_INSTALLATION_ID)515 }516 @Test517 fun testFillEventBundle_playVoiceOverEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {518 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()519 val bundle = Bundle()520 val eventLog = createEventLog(context = createPlayVoiceOverContext())521 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)522 assertThat(typeName).isEqualTo("play_voice_over_context")523 assertThat(bundle).hasSize(9)524 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)525 assertThat(bundle).string("priority").isEqualTo("essential")526 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)527 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)528 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)529 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)530 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)531 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)532 assertThat(bundle).string("content_id").isEqualTo(TEST_CONTENT_ID)533 }534 @Test535 fun testFillEventBundle_playVoiceOverEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {536 setUpTestApplicationComponentWithLearnerAnalyticsStudy()537 val bundle = Bundle()538 val eventLog = createEventLog(context = createPlayVoiceOverContext())539 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)540 assertThat(typeName).isEqualTo("play_voice_over_context")541 assertThat(bundle).hasSize(11)542 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)543 assertThat(bundle).string("priority").isEqualTo("essential")544 assertThat(bundle).string("ed_topic_id").isEqualTo(TEST_TOPIC_ID)545 assertThat(bundle).string("ed_story_id").isEqualTo(TEST_STORY_ID)546 assertThat(bundle).string("ed_exploration_id").isEqualTo(TEST_EXPLORATION_ID)547 assertThat(bundle).string("ed_session_id").isEqualTo(TEST_LEARNER_SESSION_ID)548 assertThat(bundle).string("ed_exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)549 assertThat(bundle).string("ed_state_name").isEqualTo(TEST_STATE_NAME)550 assertThat(bundle).string("content_id").isEqualTo(TEST_CONTENT_ID)551 assertThat(bundle).string("ed_ld_learner_id").isEqualTo(TEST_LEARNER_ID)552 assertThat(bundle).string("ed_ld_install_id").isEqualTo(TEST_INSTALLATION_ID)553 }554 @Test555 fun testFillEventBundle_appInBackgroundEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {556 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()557 val bundle = Bundle()558 val eventLog = createEventLog(context = createAppInBackgroundContext())559 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)560 assertThat(typeName).isEqualTo("app_in_background_context")561 assertThat(bundle).hasSize(2)562 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)563 assertThat(bundle).string("priority").isEqualTo("essential")564 }565 @Test566 fun testFillEventBundle_appInBackgroundEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {567 setUpTestApplicationComponentWithLearnerAnalyticsStudy()568 val bundle = Bundle()569 val eventLog = createEventLog(context = createAppInBackgroundContext())570 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)571 assertThat(typeName).isEqualTo("app_in_background_context")572 assertThat(bundle).hasSize(4)573 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)574 assertThat(bundle).string("priority").isEqualTo("essential")575 assertThat(bundle).string("learner_id").isEqualTo(TEST_LEARNER_ID)576 assertThat(bundle).string("install_id").isEqualTo(TEST_INSTALLATION_ID)577 }578 @Test579 fun testFillEventBundle_appInForegroundEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {580 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()581 val bundle = Bundle()582 val eventLog = createEventLog(context = createAppInForegroundContext())583 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)584 assertThat(typeName).isEqualTo("app_in_foreground_context")585 assertThat(bundle).hasSize(2)586 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)587 assertThat(bundle).string("priority").isEqualTo("essential")588 }589 @Test590 fun testFillEventBundle_appInForegroundEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {591 setUpTestApplicationComponentWithLearnerAnalyticsStudy()592 val bundle = Bundle()593 val eventLog = createEventLog(context = createAppInForegroundContext())594 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)595 assertThat(typeName).isEqualTo("app_in_foreground_context")596 assertThat(bundle).hasSize(4)597 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)598 assertThat(bundle).string("priority").isEqualTo("essential")599 assertThat(bundle).string("learner_id").isEqualTo(TEST_LEARNER_ID)600 assertThat(bundle).string("install_id").isEqualTo(TEST_INSTALLATION_ID)601 }602 @Test603 fun testFillEventBundle_exitExplorationEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {604 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()605 val bundle = Bundle()606 val eventLog = createEventLog(context = createExitExplorationContext())607 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)608 assertThat(typeName).isEqualTo("exit_exploration_context")609 assertThat(bundle).hasSize(8)610 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)611 assertThat(bundle).string("priority").isEqualTo("essential")612 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)613 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)614 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)615 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)616 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)617 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)618 }619 @Test620 fun testFillEventBundle_exitExplorationEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {621 setUpTestApplicationComponentWithLearnerAnalyticsStudy()622 val bundle = Bundle()623 val eventLog = createEventLog(context = createExitExplorationContext())624 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)625 assertThat(typeName).isEqualTo("exit_exploration_context")626 assertThat(bundle).hasSize(10)627 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)628 assertThat(bundle).string("priority").isEqualTo("essential")629 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)630 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)631 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)632 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)633 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)634 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)635 assertThat(bundle).string("ld_learner_id").isEqualTo(TEST_LEARNER_ID)636 assertThat(bundle).string("ld_install_id").isEqualTo(TEST_INSTALLATION_ID)637 }638 @Test639 fun testFillEventBundle_finishExplorationEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {640 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()641 val bundle = Bundle()642 val eventLog = createEventLog(context = createFinishExplorationContext())643 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)644 assertThat(typeName).isEqualTo("finish_exploration_context")645 assertThat(bundle).hasSize(8)646 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)647 assertThat(bundle).string("priority").isEqualTo("essential")648 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)649 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)650 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)651 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)652 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)653 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)654 }655 @Test656 fun testFillEventBundle_finishExplorationEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {657 setUpTestApplicationComponentWithLearnerAnalyticsStudy()658 val bundle = Bundle()659 val eventLog = createEventLog(context = createFinishExplorationContext())660 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)661 assertThat(typeName).isEqualTo("finish_exploration_context")662 assertThat(bundle).hasSize(10)663 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)664 assertThat(bundle).string("priority").isEqualTo("essential")665 assertThat(bundle).string("topic_id").isEqualTo(TEST_TOPIC_ID)666 assertThat(bundle).string("story_id").isEqualTo(TEST_STORY_ID)667 assertThat(bundle).string("exploration_id").isEqualTo(TEST_EXPLORATION_ID)668 assertThat(bundle).string("session_id").isEqualTo(TEST_LEARNER_SESSION_ID)669 assertThat(bundle).string("exploration_version").isEqualTo(TEST_EXPLORATION_VERSION_STR)670 assertThat(bundle).string("state_name").isEqualTo(TEST_STATE_NAME)671 assertThat(bundle).string("ld_learner_id").isEqualTo(TEST_LEARNER_ID)672 assertThat(bundle).string("ld_install_id").isEqualTo(TEST_INSTALLATION_ID)673 }674 @Test675 fun testFillEventBundle_resumeExplorationEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {676 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()677 val bundle = Bundle()678 val eventLog = createEventLog(context = createResumeExplorationContext())679 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)680 assertThat(typeName).isEqualTo("resume_exploration_context")681 assertThat(bundle).hasSize(2)682 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)683 assertThat(bundle).string("priority").isEqualTo("essential")684 }685 @Test686 fun testFillEventBundle_resumeExplorationEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {687 setUpTestApplicationComponentWithLearnerAnalyticsStudy()688 val bundle = Bundle()689 val eventLog = createEventLog(context = createResumeExplorationContext())690 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)691 assertThat(typeName).isEqualTo("resume_exploration_context")692 assertThat(bundle).hasSize(4)693 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)694 assertThat(bundle).string("priority").isEqualTo("essential")695 assertThat(bundle).string("learner_id").isEqualTo(TEST_LEARNER_ID)696 assertThat(bundle).string("install_id").isEqualTo(TEST_INSTALLATION_ID)697 }698 @Test699 fun testFillEventBundle_startOverExpEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {700 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()701 val bundle = Bundle()702 val eventLog = createEventLog(context = createStartOverExplorationContext())703 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)704 assertThat(typeName).isEqualTo("start_over_exploration_context")705 assertThat(bundle).hasSize(2)706 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)707 assertThat(bundle).string("priority").isEqualTo("essential")708 }709 @Test710 fun testFillEventBundle_startOverExpEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {711 setUpTestApplicationComponentWithLearnerAnalyticsStudy()712 val bundle = Bundle()713 val eventLog = createEventLog(context = createStartOverExplorationContext())714 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)715 assertThat(typeName).isEqualTo("start_over_exploration_context")716 assertThat(bundle).hasSize(4)717 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)718 assertThat(bundle).string("priority").isEqualTo("essential")719 assertThat(bundle).string("learner_id").isEqualTo(TEST_LEARNER_ID)720 assertThat(bundle).string("install_id").isEqualTo(TEST_INSTALLATION_ID)721 }722 @Test723 fun testFillEventBundle_deleteProfileEvent_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {724 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()725 val bundle = Bundle()726 val eventLog = createEventLog(context = createDeleteProfileContext())727 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)728 assertThat(typeName).isEqualTo("delete_profile_context")729 assertThat(bundle).hasSize(2)730 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)731 assertThat(bundle).string("priority").isEqualTo("essential")732 }733 @Test734 fun testFillEventBundle_deleteProfileEvent_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {735 setUpTestApplicationComponentWithLearnerAnalyticsStudy()736 val bundle = Bundle()737 val eventLog = createEventLog(context = createDeleteProfileContext())738 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)739 assertThat(typeName).isEqualTo("delete_profile_context")740 assertThat(bundle).hasSize(4)741 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)742 assertThat(bundle).string("priority").isEqualTo("essential")743 assertThat(bundle).string("learner_id").isEqualTo(TEST_LEARNER_ID)744 assertThat(bundle).string("install_id").isEqualTo(TEST_INSTALLATION_ID)745 }746 @Test747 fun testFillEventBundle_openHomeContextEvent_fillsAllFieldsInBundleAndReturnsName() {748 setUpTestApplicationComponent()749 val bundle = Bundle()750 val eventLog = createEventLog(context = createOpenHomeContext())751 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)752 assertThat(typeName).isEqualTo("open_home")753 assertThat(bundle).hasSize(2)754 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)755 assertThat(bundle).string("priority").isEqualTo("essential")756 }757 @Test758 fun testFillEventBundle_openProfileChooserContextEvent_fillsAllFieldsInBundleAndReturnsName() {759 setUpTestApplicationComponent()760 val bundle = Bundle()761 val eventLog = createEventLog(context = createOpenProfileChooserContext())762 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)763 assertThat(typeName).isEqualTo("open_profile_chooser")764 assertThat(bundle).hasSize(2)765 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)766 assertThat(bundle).string("priority").isEqualTo("essential")767 }768 @Test769 fun testFillEventBundle_failedEventInstallId_studyOff_fillsOnlyNonSensitiveFieldsAndRetsName() {770 setUpTestApplicationComponentWithoutLearnerAnalyticsStudy()771 val bundle = Bundle()772 val eventLog = createEventLog(context = createInstallationIdForFailedAnalyticsLogContext())773 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)774 assertThat(typeName).isEqualTo("failed_analytics_log")775 assertThat(bundle).hasSize(2)776 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)777 assertThat(bundle).string("priority").isEqualTo("essential")778 }779 @Test780 fun testFillEventBundle_failedEventInstallId_studyOn_fillsOnlyNonSensitiveFieldsAndRetsName() {781 setUpTestApplicationComponentWithLearnerAnalyticsStudy()782 val bundle = Bundle()783 val eventLog = createEventLog(context = createInstallationIdForFailedAnalyticsLogContext())784 val typeName = eventBundleCreator.fillEventBundle(eventLog, bundle)785 assertThat(typeName).isEqualTo("failed_analytics_log")786 assertThat(bundle).hasSize(3)787 assertThat(bundle).longInt("timestamp").isEqualTo(TEST_TIMESTAMP_1)788 assertThat(bundle).string("priority").isEqualTo("essential")789 assertThat(bundle).string("install_id").isEqualTo(TEST_INSTALLATION_ID)790 }791 private fun createEventLog(792 timestamp: Long = TEST_TIMESTAMP_1,793 priority: EventLog.Priority = ESSENTIAL,794 context: EventLog.Context = EventLog.Context.getDefaultInstance()795 ) = EventLog.newBuilder().apply {796 this.timestamp = timestamp797 this.priority = priority798 this.context = context799 }.build()800 private fun createOpenExplorationActivity(801 explorationContext: ExplorationContext = createExplorationContext()...

Full Screen

Full Screen

TestTradingBot.kt

Source:TestTradingBot.kt Github

copy

Full Screen

...74 // close short and complete trade orders75 every { tradeClient.placeNewOrder(any())} returns Mono.just(buyOrderResponseA) andThen Mono.just(buyOrderResponseB)76 // initial state77 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialClosedState)78 // open new long79 every { stateRepository.updateState(finalLongState)} returns Mono.just(finalLongState)80 val botSrc: Mono<State> = bot.longTrigger("SOLBTC")81 StepVerifier82 .create(botSrc)83 .expectNext(finalLongState)84 .expectComplete()85 .verify()86 // initial get state87 verify(exactly = 1) { stateRepository.getState("SOLBTC") }88 // closing shot and opening long - 2x long trades89 verify(exactly = 2) { tradeClient.placeNewOrder(any()) }90 // save short closing long trade91 // save new long trade92 // completed trade repository, close short position93 // finally, update state with new long position94 verify(exactly = 1) { stateRepository.updateState(finalLongState) }95 }96 @Test97 @Ignore98 fun testTradingBotLongTriggerWithOpenShortPosition(){99 val orderDocumentReference: DocumentReference = mockk()100 val orderDocumentReferenceA: DocumentReference = mockk()101 val orderDocumentReferenceB: DocumentReference = mockk()102 val openSellResponse: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.SELL, "shortA")103 val buyOrderResponseA: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.BUY, "orderA")104 val buyOrderResponseB: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.BUY, "orderB")105 val initialShortState = State (106 exchange = "binance",107 symbol = "SOLBTC",108 open_position = orderDocumentReference,109 position_size = 1.0,110 remaining_position = 1.0,111 direction = Direction.SHORT,112 timestamp = 0L113 )114 val finalLongState = State (115 exchange = "binance",116 symbol = "SOLBTC",117 open_position = orderDocumentReferenceB,118 position_size = 1.0,119 remaining_position = 1.0,120 direction = Direction.LONG,121 timestamp = 0L122 )123 val bot = TradingBot(124 binanceTradeClient = tradeClient,125 bybitTradeClient = bybitClient,126 stateRepository = stateRepository,127 openTradeRepository = openTradeRepository,128 openTradeService = openTradeService129 )130 // close short and complete trade orders131 every { tradeClient.placeNewOrder(any())} returns Mono.just(buyOrderResponseA) andThen Mono.just(buyOrderResponseB)132 // initial state133 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialShortState)134// every { stateRepository.getTrade(initialShortState) } returns Mono.just(openSellResponse)135 // open new long136 every { stateRepository.updateState(finalLongState)} returns Mono.just(finalLongState)137 val botSrc: Mono<State> = bot.longTrigger("SOLBTC")138 StepVerifier139 .create(botSrc)140 .expectNext(finalLongState)141 .expectComplete()142 .verify()143 // initial get state144 verify(exactly = 1) { stateRepository.getState("SOLBTC") }145 // closing shot and opening long - 2x long trades146 verify(exactly = 2) { tradeClient.placeNewOrder(any()) }147 // save short closing long trade148 // save new long trade149 // completed trade repository, close short position150 // finally, update state with new long position151 verify(exactly = 1) { stateRepository.updateState(finalLongState) }152 }153 /*154 @Test155 fun testTradingBotLongTriggerWithNoShortPosition(){156 val buyOrderResponseB: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.BUY, "orderB")157 val initialShortState = State (158 exchange = "binance",159 symbol = "SOLBTC",160 long_position = "",161 short_position = ""162 )163 val finalLongState = State (164 exchange = "binance",165 symbol = "SOLBTC",166 long_position = "new-position-doc-id",167 short_position = ""168 )169 val bot = TradingBot(170 tradeClient = tradeClient,171 positionRepository = positionRepository,172 stateRepository = stateRepository,173 tradeRepository = tradeRepository174 )175 val position = Position(176 exchange = "binance",177 symbol = "SOLBTC",178 )179 every { tradeClient.placeNewOrder(any())} returns Mono.just(buyOrderResponseB)180 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialShortState)181 every { tradeRepository.saveOrderResponse(buyOrderResponseB)} returns Mono.just("document-id")182 every { positionRepository.createPosition(Position(exchange = "binance", symbol = "SOLBTC")) } returns Mono.just("new-position-doc-id")183 every { positionRepository.addOpenOrder( documentId = "new-position-doc-id", orderResponse = buyOrderResponseB) } returns Mono.just(position)184 every { stateRepository.updateState(State(exchange = "binance", symbol="SOLBTC", long_position="new-position-doc-id", short_position="")) } returns Mono.just(finalLongState)185 val botSrc: Mono<State> = bot.longTrigger()186 StepVerifier187 .create(botSrc)188 .expectNext(finalLongState)189 .expectComplete()190 .verify()191 // initial get state192 verify(exactly = 1) { stateRepository.getState("SOLBTC") }193 // create the new long position194 verify(exactly = 1) { positionRepository.createPosition(any()) }195 // position repository, open long position196 verify(exactly = 1) { positionRepository.addOpenOrder("new-position-doc-id", buyOrderResponseB) }197 // finally, update state with new long position198 verify(exactly = 1) { stateRepository.updateState(finalLongState) }199 }200 @Test201 fun testTradingBotShortTriggerWithOpenLongPosition(){202 val buyOrderResponseA: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.SELL, "orderA")203 val buyOrderResponseB: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.SELL, "orderB")204 val initialLongState = State (205 exchange = "binance",206 symbol = "SOLBTC",207 long_position = "long_pos_123",208 short_position = ""209 )210 val intermediateIdleState = State (211 exchange = "binance",212 symbol = "SOLBTC",213 long_position = "",214 short_position = ""215 )216 val finalShortState = State (217 exchange = "binance",218 symbol = "SOLBTC",219 long_position = "",220 short_position = "new-short-position-doc"221 )222 val bot = TradingBot(223 tradeClient = tradeClient,224 positionRepository = positionRepository,225 stateRepository = stateRepository,226 tradeRepository = tradeRepository227 )228 val position = Position(229 exchange = "binance",230 symbol = "SOLBTC",231 )232 every { tradeClient.placeNewOrder(any())} returns Mono.just(buyOrderResponseA) andThen Mono.just(buyOrderResponseB)233 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialLongState)234 every { tradeRepository.saveOrderResponse(buyOrderResponseA)} returns Mono.just("document-id")235 every { positionRepository.addCloseOrder( documentId = "long_pos_123", orderResponse = buyOrderResponseA) } returns Mono.just(position)236 every { stateRepository.updateState(State(exchange = "binance", symbol="SOLBTC", long_position="", short_position="")) } returns Mono.just(intermediateIdleState)237 every { positionRepository.createPosition(Position(exchange = "binance", symbol = "SOLBTC")) } returns Mono.just("new-short-position-doc")238 every { tradeRepository.saveOrderResponse(buyOrderResponseB)} returns Mono.just("document-id")239 every { positionRepository.addOpenOrder( documentId = "new-short-position-doc", orderResponse = buyOrderResponseB) } returns Mono.just(position)240 every { stateRepository.updateState(State(exchange = "binance", symbol="SOLBTC", long_position="", short_position="new-short-position-doc")) } returns Mono.just(finalShortState)241 val botSrc: Mono<State> = bot.shortTrigger()242 StepVerifier243 .create(botSrc)244 .expectNext(finalShortState)245 .expectComplete()246 .verify()247 // initial get state248 verify(exactly = 1) { stateRepository.getState("SOLBTC") }249 // closing shot and opening long - 2x long trades250 verify(exactly = 2) { tradeClient.placeNewOrder(any()) }251 // save short closing long trade252 verify(exactly = 1) { tradeRepository.saveOrderResponse(buyOrderResponseA) }253 // save new long trade254 verify(exactly = 1) { tradeRepository.saveOrderResponse(buyOrderResponseB) }255 // position repository, close short position256 verify(exactly = 1) { positionRepository.addCloseOrder(any(), any()) }257 // create new empty position258 verify(exactly = 1) { positionRepository.createPosition(any()) }259 // position repository, open long position260 verify(exactly = 1) { positionRepository.addOpenOrder("new-short-position-doc", buyOrderResponseB) }261 // finally, update state with new long position262 verify(exactly = 1) { stateRepository.updateState(finalShortState) }263 }264 @Test265 fun testTradingBotShortTriggerWithNoLongPosition(){266 val buyOrderResponseB: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.SELL, "orderB")267 val initialLongState = State (268 exchange = "binance",269 symbol = "SOLBTC",270 long_position = "",271 short_position = ""272 )273 val finalShortState = State (274 exchange = "binance",275 symbol = "SOLBTC",276 long_position = "",277 short_position = "new-short-position-doc"278 )279 val bot = TradingBot(280 tradeClient = tradeClient,281 positionRepository = positionRepository,282 stateRepository = stateRepository,283 tradeRepository = tradeRepository284 )285 val position = Position(286 exchange = "binance",287 symbol = "SOLBTC",288 )289 every { tradeClient.placeNewOrder(any())} returns Mono.just(buyOrderResponseB)290 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialLongState)291 every { positionRepository.createPosition(Position(exchange = "binance", symbol = "SOLBTC")) } returns Mono.just("new-short-position-doc")292 every { tradeRepository.saveOrderResponse(buyOrderResponseB)} returns Mono.just("document-id")293 every { positionRepository.addOpenOrder( documentId = "new-short-position-doc", orderResponse = buyOrderResponseB) } returns Mono.just(position)294 every { stateRepository.updateState(State(exchange = "binance", symbol="SOLBTC", long_position="", short_position="new-short-position-doc")) } returns Mono.just(finalShortState)295 val botSrc: Mono<State> = bot.shortTrigger()296 StepVerifier297 .create(botSrc)298 .expectNext(finalShortState)299 .expectComplete()300 .verify()301 // initial get state302 verify(exactly = 1) { stateRepository.getState("SOLBTC") }303 // create new empty position304 verify(exactly = 1) { positionRepository.createPosition(any()) }305 // position repository, open long position306 verify(exactly = 1) { positionRepository.addOpenOrder("new-short-position-doc", buyOrderResponseB) }307 // finally, update state with new long position308 verify(exactly = 1) { stateRepository.updateState(finalShortState) }309 }310 @Test311 fun testTradingBotShortTP(){312 val buyOrderResponseA: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.BUY, "orderA")313 val initialShortState = State (314 exchange = "binance",315 symbol = "SOLBTC",316 long_position = "",317 short_position = "short_pos_123"318 )319 val finalState = State (320 exchange = "binance",321 symbol = "SOLBTC",322 long_position = "",323 short_position = ""324 )325 val bot = TradingBot(326 tradeClient = tradeClient,327 positionRepository = positionRepository,328 stateRepository = stateRepository,329 tradeRepository = tradeRepository330 )331 val position = Position(332 exchange = "binance",333 symbol = "SOLBTC",334 )335 every { tradeClient.placeNewOrder(any())} returns Mono.just(buyOrderResponseA)336 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialShortState)337 every { tradeRepository.saveOrderResponse(buyOrderResponseA)} returns Mono.just("document-id")338 every { positionRepository.addCloseOrder( documentId = "short_pos_123", orderResponse = buyOrderResponseA) } returns Mono.just(position)339 every { stateRepository.updateState(State(exchange = "binance", symbol="SOLBTC", long_position="", short_position="")) } returns Mono.just(finalState)340 val botSrc: Mono<State> = bot.shortTakeProfit()341 StepVerifier342 .create(botSrc)343 .expectNext(finalState)344 .expectComplete()345 .verify()346 // initial get state347 verify(exactly = 1) { stateRepository.getState("SOLBTC") }348 // closing shot and opening long - 2x long trades349 verify(exactly = 1) { tradeClient.placeNewOrder(any()) }350 // save short closing long trade351 verify(exactly = 1) { tradeRepository.saveOrderResponse(buyOrderResponseA) }352 // finally, update state with new long position353 verify(exactly = 1) { stateRepository.updateState(finalState) }354 }355 @Test356 fun testTradingBotLongTP(){357 val sellOrderResponseA: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.SELL, "orderA")358 val initialShortState = State (359 exchange = "binance",360 symbol = "SOLBTC",361 long_position = "long_pos_123",362 short_position = ""363 )364 val finalState = State (365 exchange = "binance",366 symbol = "SOLBTC",367 long_position = "",368 short_position = ""369 )370 val bot = TradingBot(371 tradeClient = tradeClient,372 positionRepository = positionRepository,373 stateRepository = stateRepository,374 tradeRepository = tradeRepository375 )376 val position = Position(377 exchange = "binance",378 symbol = "SOLBTC",379 )380 every { tradeClient.placeNewOrder(any())} returns Mono.just(sellOrderResponseA)381 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialShortState)382 every { tradeRepository.saveOrderResponse(sellOrderResponseA)} returns Mono.just("document-id")383 every { positionRepository.addCloseOrder( documentId = "long_pos_123", orderResponse = sellOrderResponseA) } returns Mono.just(position)384 every { stateRepository.updateState(State(exchange = "binance", symbol="SOLBTC", long_position="", short_position="")) } returns Mono.just(finalState)385 val botSrc: Mono<State> = bot.longTakeProfit()386 StepVerifier387 .create(botSrc)388 .expectNext(finalState)389 .expectComplete()390 .verify()391 // initial get state392 verify(exactly = 1) { stateRepository.getState("SOLBTC") }393 // closing shot and opening long - 2x long trades394 verify(exactly = 1) { tradeClient.placeNewOrder(any()) }395 // save short closing long trade396 verify(exactly = 1) { tradeRepository.saveOrderResponse(sellOrderResponseA) }397 // finally, update state with new long position398 verify(exactly = 1) { stateRepository.updateState(finalState) }399 }400 @Test401 fun testTradingBotLongTP_noLong(){402 val sellOrderResponseA: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.SELL, "orderA")403 val initialShortState = State (404 exchange = "binance",405 symbol = "SOLBTC",406 long_position = "",407 short_position = ""408 )409 val finalState = State (410 exchange = "binance",411 symbol = "SOLBTC",412 long_position = "",413 short_position = ""414 )415 val bot = TradingBot(416 tradeClient = tradeClient,417 positionRepository = positionRepository,418 stateRepository = stateRepository,419 tradeRepository = tradeRepository420 )421 val position = Position(422 exchange = "binance",423 symbol = "SOLBTC",424 )425 every { tradeClient.placeNewOrder(any())} returns Mono.just(sellOrderResponseA)426 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialShortState)427 val botSrc: Mono<State> = bot.longTakeProfit()428 StepVerifier429 .create(botSrc)430 .expectNext(finalState)431 .expectComplete()432 .verify()433 // initial get state434 verify(exactly = 1) { stateRepository.getState("SOLBTC") }435 }436 @Test437 fun testTradingBotShortTP_noShort(){438 val sellOrderResponseA: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.SELL, "orderA")439 val initialShortState = State (440 exchange = "binance",441 symbol = "SOLBTC",442 long_position = "",443 short_position = ""444 )445 val finalState = State (446 exchange = "binance",447 symbol = "SOLBTC",448 long_position = "",449 short_position = ""450 )451 val bot = TradingBot(452 tradeClient = tradeClient,453 positionRepository = positionRepository,454 stateRepository = stateRepository,455 tradeRepository = tradeRepository456 )457 val position = Position(458 exchange = "binance",459 symbol = "SOLBTC",460 )461 every { tradeClient.placeNewOrder(any())} returns Mono.just(sellOrderResponseA)462 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialShortState)463 val botSrc: Mono<State> = bot.shortTakeProfit()464 StepVerifier465 .create(botSrc)466 .expectNext(finalState)467 .expectComplete()468 .verify()469 // initial get state470 verify(exactly = 1) { stateRepository.getState("SOLBTC") }471 }472 @Test473 fun testTradingBotLong_alreadyLong(){474 val sellOrderResponseA: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.SELL, "orderA")475 val initialShortState = State (476 exchange = "binance",477 symbol = "SOLBTC",478 long_position = "existing-long-123",479 short_position = ""480 )481 val finalState = State (482 exchange = "binance",483 symbol = "SOLBTC",484 long_position = "existing-long-123",485 short_position = ""486 )487 val bot = TradingBot(488 tradeClient = tradeClient,489 positionRepository = positionRepository,490 stateRepository = stateRepository,491 tradeRepository = tradeRepository492 )493 every { tradeClient.placeNewOrder(any())} returns Mono.just(sellOrderResponseA)494 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialShortState)495 val botSrc: Mono<State> = bot.longTrigger()496 StepVerifier497 .create(botSrc)498 .expectNext(finalState)499 .expectComplete()500 .verify()501 // initial get state502 verify(exactly = 1) { stateRepository.getState("SOLBTC") }503 }504 @Test505 fun testTradingBotShort_alreadyShort(){506 val sellOrderResponseA: OrderResponse = TestDataHelper.createOrderResponse(OrderSide.SELL, "orderA")507 val initialShortState = State (508 exchange = "binance",509 symbol = "SOLBTC",510 long_position = "",511 short_position = "existing-short-123"512 )513 val finalState = State (514 exchange = "binance",515 symbol = "SOLBTC",516 long_position = "",517 short_position = "existing-short-123"518 )519 val bot = TradingBot(520 tradeClient = tradeClient,521 positionRepository = positionRepository,522 stateRepository = stateRepository,523 tradeRepository = tradeRepository524 )525 every { tradeClient.placeNewOrder(any())} returns Mono.just(sellOrderResponseA)526 every { stateRepository.getState("SOLBTC") } returns Mono.just(initialShortState)527 val botSrc: Mono<State> = bot.shortTrigger()528 StepVerifier529 .create(botSrc)530 .expectNext(finalState)...

Full Screen

Full Screen

StoreTest.kt

Source:StoreTest.kt Github

copy

Full Screen

1package org.mapdb.store2import org.eclipse.collections.impl.list.mutable.primitive.LongArrayList3import org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap4import org.junit.Assert.*5import org.junit.Test6import org.mapdb.*7import org.mapdb.TT.assertFailsWith8import org.mapdb.serializer.Serializers9import java.util.*10import java.util.concurrent.atomic.AtomicLong11/**12 * Tests contract on `Store` interface13 */14abstract class StoreTest {15 abstract fun openStore(): Store;16 @Test fun put_get() {17 val e = openStore()18 val l = 11231203099090L19 val recid = e.put(l, Serializers.LONG)20 assertEquals(l, e.get(recid, Serializers.LONG))21 e.verify()22 e.close()23 }24 @Test fun put_get_large() {25 val e = openStore()26 val b = TT.randomByteArray(1000000)27 Random().nextBytes(b)28 val recid = e.put(b, Serializers.BYTE_ARRAY_NOSIZE)29 assertTrue(Arrays.equals(b, e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)))30 e.verify()31 e.close()32 }33 @Test fun testSetGet() {34 val e = openStore()35 val recid = e.put(10000.toLong(), Serializers.LONG)36 val s2 = e.get(recid, Serializers.LONG)37 assertEquals(s2, java.lang.Long.valueOf(10000))38 e.verify()39 e.close()40 }41 @Test fun reserved_recids(){42 val e = openStore()43 for(expectedRecid in 1 .. CC.RECID_MAX_RESERVED){44 val allocRecid = e.put(1, Serializers.INTEGER)45 assertEquals(expectedRecid, allocRecid)46 }47 e.verify()48 e.close()49 }50 @Test51 fun large_record() {52 val e = openStore()53 val b = TT.randomByteArray(100000)54 val recid = e.put(b, Serializers.BYTE_ARRAY_NOSIZE)55 val b2 = e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)56 assertTrue(Arrays.equals(b, b2))57 e.verify()58 e.close()59 }60 @Test fun large_record_delete() {61 val e = openStore()62 val b = TT.randomByteArray(100000)63 val recid = e.put(b, Serializers.BYTE_ARRAY_NOSIZE)64 e.verify()65 e.delete(recid, Serializers.BYTE_ARRAY_NOSIZE)66 e.verify()67 e.close()68 }69 @Test fun large_record_delete2(){70 val s = openStore()71 val b = TT.randomByteArray(200000)72 val recid1 = s.put(b, Serializers.BYTE_ARRAY_NOSIZE)73 s.verify()74 val b2 = TT.randomByteArray(220000)75 val recid2 = s.put(b2, Serializers.BYTE_ARRAY_NOSIZE)76 s.verify()77 assertTrue(Arrays.equals(b, s.get(recid1, Serializers.BYTE_ARRAY_NOSIZE)))78 assertTrue(Arrays.equals(b2, s.get(recid2, Serializers.BYTE_ARRAY_NOSIZE)))79 s.delete(recid1, Serializers.BYTE_ARRAY_NOSIZE)80 assertTrue(Arrays.equals(b2, s.get(recid2, Serializers.BYTE_ARRAY_NOSIZE)))81 s.verify()82 s.delete(recid2, Serializers.BYTE_ARRAY_NOSIZE)83 s.verify()84 s.verify()85 s.close()86 }87 @Test fun large_record_update(){88 val s = openStore()89 var b = TT.randomByteArray(200000)90 val recid1 = s.put(b, Serializers.BYTE_ARRAY_NOSIZE)91 s.verify()92 val b2 = TT.randomByteArray(220000)93 val recid2 = s.put(b2, Serializers.BYTE_ARRAY_NOSIZE)94 s.verify()95 assertTrue(Arrays.equals(b, s.get(recid1, Serializers.BYTE_ARRAY_NOSIZE)))96 assertTrue(Arrays.equals(b2, s.get(recid2, Serializers.BYTE_ARRAY_NOSIZE)))97 b = TT.randomByteArray(210000)98 s.update(recid1, b, Serializers.BYTE_ARRAY_NOSIZE);99 assertTrue(Arrays.equals(b, s.get(recid1, Serializers.BYTE_ARRAY_NOSIZE)))100 assertTrue(Arrays.equals(b2, s.get(recid2, Serializers.BYTE_ARRAY_NOSIZE)))101 s.verify()102 b = TT.randomByteArray(28001)103 s.update(recid1, b, Serializers.BYTE_ARRAY_NOSIZE);104 assertTrue(Arrays.equals(b, s.get(recid1, Serializers.BYTE_ARRAY_NOSIZE)))105 assertTrue(Arrays.equals(b2, s.get(recid2, Serializers.BYTE_ARRAY_NOSIZE)))106 s.verify()107 s.close()108 }109 @Test110 fun get_non_existent() {111 val e = openStore()112 TT.assertFailsWith(DBException.GetVoid::class.java) {113 e.get(1, TT.Serializer_ILLEGAL_ACCESS)114 }115 e.verify()116 e.close()117 }118 @Test fun preallocate_cas() {119 val e = openStore()120 val recid = e.preallocate()121 e.verify()122 assertFalse(e.compareAndSwap(recid, 1L, 2L, Serializers.LONG))123 assertTrue(e.compareAndSwap(recid, null, 2L, Serializers.LONG))124 assertEquals(2L.toLong(), e.get(recid, Serializers.LONG))125 e.verify()126 e.close()127 }128 @Test fun preallocate_get_update_delete_update_get() {129 val e = openStore()130 val recid = e.preallocate()131 e.verify()132 assertNull(e.get(recid, TT.Serializer_ILLEGAL_ACCESS))133 e.update(recid, 1L, Serializers.LONG)134 assertEquals(1L.toLong(), e.get(recid, Serializers.LONG))135 e.delete(recid, Serializers.LONG)136 assertFailsWith(DBException.GetVoid::class.java) {137 assertNull(e.get(recid, TT.Serializer_ILLEGAL_ACCESS))138 }139 e.verify()140 assertFailsWith(DBException.GetVoid::class.java) {141 e.update(recid, 1L, Serializers.LONG)142 }143 e.verify()144 e.close()145 }146 @Test fun cas_delete() {147 val e = openStore()148 val recid = e.put(1L, Serializers.LONG)149 e.verify()150 assertTrue(e.compareAndSwap(recid, 1L, null, Serializers.LONG))151 assertNull(e.get(recid, TT.Serializer_ILLEGAL_ACCESS))152 assertTrue(e.compareAndSwap(recid, null, 1L, Serializers.LONG))153 assertEquals(1L, e.get(recid, Serializers.LONG))154 e.verify()155 e.close()156 }157 @Test fun cas_prealloc() {158 val e = openStore()159 val recid = e.preallocate()160 assertTrue(e.compareAndSwap(recid, null, 1L, Serializers.LONG))161 e.verify()162 assertEquals(1L, e.get(recid, Serializers.LONG))163 assertTrue(e.compareAndSwap(recid, 1L, null, Serializers.LONG))164 e.verify()165 assertNull(e.get(recid, TT.Serializer_ILLEGAL_ACCESS))166 e.verify()167 e.close()168 }169 @Test fun cas_prealloc_delete() {170 val e = openStore()171 val recid = e.preallocate()172 e.delete(recid, Serializers.LONG)173 assertFailsWith(DBException.GetVoid::class.java) {174 assertTrue(e.compareAndSwap(recid, null, 1L, Serializers.LONG))175 }176 e.verify()177 e.close()178 }179 @Test fun putGetUpdateDelete() {180 val e = openStore()181 var s = "aaaad9009"182 val recid = e.put(s, Serializers.STRING)183 assertEquals(s, e.get(recid, Serializers.STRING))184 s = "da8898fe89w98fw98f9"185 e.update(recid, s, Serializers.STRING)186 assertEquals(s, e.get(recid, Serializers.STRING))187 e.verify()188 e.delete(recid, Serializers.STRING)189 assertFailsWith(DBException.GetVoid::class.java) {190 e.get(recid, Serializers.STRING)191 }192 e.verify()193 e.close()194 }195 @Test fun nosize_array() {196 val e = openStore()197 var b = ByteArray(0)198 val recid = e.put(b, Serializers.BYTE_ARRAY_NOSIZE)199 assertTrue(Arrays.equals(b, e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)))200 b = byteArrayOf(1, 2, 3)201 e.update(recid, b, Serializers.BYTE_ARRAY_NOSIZE)202 assertTrue(Arrays.equals(b, e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)))203 e.verify()204 b = byteArrayOf()205 e.update(recid, b, Serializers.BYTE_ARRAY_NOSIZE)206 assertTrue(Arrays.equals(b, e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)))207 e.verify()208 e.delete(recid, Serializers.BYTE_ARRAY_NOSIZE)209 assertFailsWith(DBException.GetVoid::class.java) {210 e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)211 }212 e.verify()213 e.close()214 }215 @Test fun get_deleted() {216 val e = openStore()217 val recid = e.put(1L, Serializers.LONG)218 e.verify()219 e.delete(recid, Serializers.LONG)220 assertFailsWith(DBException.GetVoid::class.java) {221 e.get(recid, Serializers.LONG)222 }223 e.verify()224 e.close()225 }226 @Test fun update_deleted() {227 val e = openStore()228 val recid = e.put(1L, Serializers.LONG)229 e.delete(recid, Serializers.LONG)230 assertFailsWith(DBException.GetVoid::class.java) {231 e.update(recid, 2L, Serializers.LONG)232 }233 e.verify()234 e.close()235 }236 @Test fun double_delete() {237 val e = openStore()238 val recid = e.put(1L, Serializers.LONG)239 e.delete(recid, Serializers.LONG)240 assertFailsWith(DBException.GetVoid::class.java) {241 e.delete(recid, Serializers.LONG)242 }243 e.verify()244 e.close()245 }246 @Test fun empty_update_commit() {247 if (TT.shortTest())248 return249 var e = openStore()250 val recid = e.put("", Serializers.STRING)251 assertEquals("", e.get(recid, Serializers.STRING))252 for (i in 0..9999) {253 val s = TT.randomString(80000)254 e.update(recid, s, Serializers.STRING)255 assertEquals(s, e.get(recid, Serializers.STRING))256 e.commit()257 assertEquals(s, e.get(recid, Serializers.STRING))258 }259 e.verify()260 e.close()261 }262 @Test fun delete_reuse() {263 for(size in 1 .. 20){264 val e = openStore()265 val recid = e.put(TT.randomString(size), Serializers.STRING)266 e.delete(recid, Serializers.STRING)267 assertFailsWith(DBException.GetVoid::class.java) {268 e.get(recid, TT.Serializer_ILLEGAL_ACCESS)269 }270 val recid2 = e.put(TT.randomString(size), Serializers.STRING)271 assertEquals(recid, recid2)272 e.verify()273 e.close()274 }275 }276 @Test fun empty_rollback(){277 val e = openStore()278 if(e is StoreTx)279 e.rollback()280 e.verify()281 e.close()282 }283 @Test fun empty_commit(){284 val e = openStore()285 e.commit()286 e.verify()287 e.close()288 }289 @Test fun randomUpdates() {290 if(TT.shortTest())291 return;292 val s = openStore()293 val random = Random(1);294 val endTime = TT.nowPlusMinutes(10.0)295 val ref = LongObjectHashMap<ByteArray>()296 //TODO params could cause OOEM if too big. Make another case of tests with extremely large memory, or disk space297 val maxRecSize = 1000298 val maxSize = 66000 * 3299 //fill up300 for (i in 0 until maxSize){301 val size = random.nextInt(maxRecSize)302 val b = TT.randomByteArray(size, random.nextInt())303 val recid = s.put(b, Serializers.BYTE_ARRAY_NOSIZE)304 ref.put(recid, b)305 }306 s.verify()307 while(endTime>System.currentTimeMillis()){308 ref.forEachKeyValue { recid, record ->309 val old = s.get(recid, Serializers.BYTE_ARRAY_NOSIZE)310 assertTrue(Arrays.equals(record, old))311 val size = random.nextInt(maxRecSize)312 val b = TT.randomByteArray(size, random.nextInt())313 ref.put(recid,b.clone())314 s.update(recid, b, Serializers.BYTE_ARRAY_NOSIZE)315 assertTrue(Arrays.equals(b, s.get(recid, Serializers.BYTE_ARRAY_NOSIZE)));316 }317 s.verify()318 if(s is StoreWAL) {319 s.commit()320 s.verify()321 }322 }323 }324 @Test fun concurrent_CAS(){325 if(TT.shortTest())326 return;327 val s = openStore();328 if(s.isThreadSafe.not())329 return;330 val ntime = TT.nowPlusMinutes(1.0)331 var counter = AtomicLong(0);332 val recid = s.put(0L, Serializers.LONG)333 TT.fork(10){334 val random = Random();335 while(ntime>System.currentTimeMillis()){336 val plus = random.nextInt(1000).toLong()337 val v:Long = s.get(recid, Serializers.LONG)!!338 if(s.compareAndSwap(recid, v, v+plus, Serializers.LONG)){339 counter.addAndGet(plus);340 }341 }342 }343 assertTrue(counter.get()>0)344 assertEquals(counter.get(), s.get(recid, Serializers.LONG))345 }346 @Test fun varRecordSizeCompact(){347 if(TT.shortTest())348 return349 val maxStoreSize = 10*1024*1024350 var size = 1351 while(size<maxStoreSize) {352 val store = openStore()353 val maxCount = 1 + maxStoreSize / size;354 //insert recids355 val recids = LongArrayList()356 for (i in 0..maxCount) {357 val r = TT.randomByteArray(size, seed = i)358 val recid = store.put(r, Serializers.BYTE_ARRAY_NOSIZE)359 recids.add(recid)360 }361 fun verify() {362 //verify recids363 recids.forEachWithIndex { recid, i ->364 val r = store.get(recid, Serializers.BYTE_ARRAY_NOSIZE)365 assertTrue(Arrays.equals(r, TT.randomByteArray(size, seed=i)))366 }367 }368 verify()369 store.compact()370 verify()371 size += 1 + size/113372 }373 }374}375class StoreHeapTest : StoreTest() {376 override fun openStore() = StoreOnHeap();377}...

Full Screen

Full Screen

SearchTest.kt

Source:SearchTest.kt Github

copy

Full Screen

...19import org.mozilla.fenix.helpers.HomeActivityTestRule20import org.mozilla.fenix.helpers.SearchDispatcher21import org.mozilla.fenix.helpers.TestHelper.appContext22import org.mozilla.fenix.helpers.TestHelper.exitMenu23import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem24import org.mozilla.fenix.helpers.TestHelper.setCustomSearchEngine25import org.mozilla.fenix.ui.robots.homeScreen26import org.mozilla.fenix.ui.robots.multipleSelectionToolbar27/**28 * Tests for verifying the search fragment29 *30 * Including:31 * - Verify the toolbar, awesomebar, and shortcut bar are displayed32 * - Select shortcut button33 * - Select scan button34 *35 */36class SearchTest {37 private val featureSettingsHelper = FeatureSettingsHelper()38 lateinit var searchMockServer: MockWebServer39 @get:Rule40 val activityTestRule = AndroidComposeTestRule(41 HomeActivityTestRule(),42 { it.activity }43 )44 @Before45 fun setUp() {46 searchMockServer = MockWebServer().apply {47 dispatcher = SearchDispatcher()48 start()49 }50 featureSettingsHelper.setJumpBackCFREnabled(false)51 featureSettingsHelper.setPocketEnabled(false)52 }53 @After54 fun tearDown() {55 searchMockServer.shutdown()56 featureSettingsHelper.resetAllFeatureFlags()57 }58 @Test59 fun searchScreenItemsTest() {60 homeScreen {61 }.openSearch {62 verifySearchView()63 verifyBrowserToolbar()64 verifyScanButton()65 verifySearchEngineButton()66 }67 }68 @SmokeTest69 @Ignore("This test cannot run on virtual devices due to camera permissions being required")70 @Test71 fun scanButtonTest() {72 homeScreen {73 }.openSearch {74 clickScanButton()75 clickDenyPermission()76 clickScanButton()77 clickAllowPermission()78 }79 }80 @Test81 @Ignore("Flaky. See https://github.com/mozilla-mobile/fenix/issues/20973")82 fun shortcutButtonTest() {83 homeScreen {84 }.openThreeDotMenu {85 }.openSettings {86 }.openSearchSubMenu {87 enableShowSearchShortcuts()88 }.goBack {89 }.goBack {90 }.openSearch {91 verifySearchBarEmpty()92 clickSearchEngineButton(activityTestRule, "DuckDuckGo")93 typeSearch("mozilla")94 verifySearchEngineResults(2)95 clickSearchEngineResult(activityTestRule, "DuckDuckGo")96 verifySearchEngineURL("DuckDuckGo")97 }98 }99 @Test100 fun shortcutSearchEngineSettingsTest() {101 homeScreen {102 }.openThreeDotMenu {103 }.openSettings {104 }.openSearchSubMenu {105 enableShowSearchShortcuts()106 }.goBack {107 }.goBack {108 }.openSearch {109 scrollToSearchEngineSettings(activityTestRule)110 clickSearchEngineSettings(activityTestRule)111 verifySearchSettings()112 }113 }114 @Test115 fun clearSearchTest() {116 homeScreen {117 }.openSearch {118 typeSearch("test")119 clickClearButton()120 verifySearchBarEmpty()121 }122 }123 @Ignore("Failure caused by bugs: https://github.com/mozilla-mobile/fenix/issues/23818")124 @SmokeTest125 @Test126 fun searchGroupShowsInRecentlyVisitedTest() {127 val firstPage = searchMockServer.url("generic1.html").toString()128 val secondPage = searchMockServer.url("generic2.html").toString()129 // setting our custom mockWebServer search URL130 val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}"131 val customSearchEngine = createSearchEngine(132 name = "TestSearchEngine",133 url = searchString,134 icon = DefaultIconGenerator().generate(appContext, IconRequest(searchString)).bitmap135 )136 setCustomSearchEngine(customSearchEngine)137 // Performs a search and opens 2 dummy search results links to create a search group138 homeScreen {139 }.openSearch {140 }.submitQuery("test search") {141 longClickMatchingText("Link 1")142 clickContextOpenLinkInNewTab()143 longClickMatchingText("Link 2")144 clickContextOpenLinkInNewTab()145 }.goToHomescreen {146 verifyJumpBackInSectionIsDisplayed()147 verifyCurrentSearchGroupIsDisplayed(true, "test search", 3)148 verifyRecentlyVisitedSearchGroupDisplayed(false, "test search", 3)149 }.openTabDrawer {150 }.openTabFromGroup(firstPage) {151 }.openTabDrawer {152 }.openTabFromGroup(secondPage) {153 }.openTabDrawer {154 }.openTabsListThreeDotMenu {155 }.closeAllTabs {156 verifyRecentlyVisitedSearchGroupDisplayed(true, "test search", 3)157 }158 }159 @SmokeTest160 @Test161 fun noCurrentSearchGroupFromPrivateBrowsingTest() {162 // setting our custom mockWebServer search URL163 val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}"164 val customSearchEngine = createSearchEngine(165 name = "TestSearchEngine",166 url = searchString,167 icon = DefaultIconGenerator().generate(appContext, IconRequest(searchString)).bitmap168 )169 setCustomSearchEngine(customSearchEngine)170 // Performs a search and opens 2 dummy search results links to create a search group171 homeScreen {172 }.openSearch {173 }.submitQuery("test search") {174 longClickMatchingText("Link 1")175 clickContextOpenLinkInPrivateTab()176 longClickMatchingText("Link 2")177 clickContextOpenLinkInPrivateTab()178 }.goToHomescreen {179 verifyCurrentSearchGroupIsDisplayed(false, "test search", 3)180 }.openThreeDotMenu {181 }.openHistory {182 verifyHistoryItemExists(false, "3 sites")183 }184 }185 @SmokeTest186 @Test187 fun noRecentlyVisitedSearchGroupInPrivateBrowsingTest() {188 val firstPage = searchMockServer.url("generic1.html").toString()189 val secondPage = searchMockServer.url("generic2.html").toString()190 // setting our custom mockWebServer search URL191 val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}"192 val customSearchEngine = createSearchEngine(193 name = "TestSearchEngine",194 url = searchString,195 icon = DefaultIconGenerator().generate(appContext, IconRequest(searchString)).bitmap196 )197 setCustomSearchEngine(customSearchEngine)198 // Performs a search and opens 2 dummy search results links to create a search group199 homeScreen {200 }.togglePrivateBrowsingMode()201 homeScreen {202 }.openSearch {203 }.submitQuery("test search") {204 longClickMatchingText("Link 1")205 clickContextOpenLinkInPrivateTab()206 longClickMatchingText("Link 2")207 clickContextOpenLinkInPrivateTab()208 }.openTabDrawer {209 }.openTab(firstPage) {210 }.openTabDrawer {211 }.openTab(secondPage) {212 }.openTabDrawer {213 }.openTabsListThreeDotMenu {214 }.closeAllTabs {215 homeScreen {216 }.togglePrivateBrowsingMode()217 verifyRecentlyVisitedSearchGroupDisplayed(false, "test search", 3)218 }219 }220 @Ignore("Failure caused by bugs: https://github.com/mozilla-mobile/fenix/issues/23818")221 @SmokeTest222 @Test223 fun deleteItemsFromSearchGroupsHistoryTest() {224 val firstPage = searchMockServer.url("generic1.html").toString()225 val secondPage = searchMockServer.url("generic2.html").toString()226 // setting our custom mockWebServer search URL227 val searchString = "http://localhost:${searchMockServer.port}/searchResults.html?search={searchTerms}"228 val customSearchEngine = createSearchEngine(229 name = "TestSearchEngine",230 url = searchString,231 icon = DefaultIconGenerator().generate(appContext, IconRequest(searchString)).bitmap232 )233 setCustomSearchEngine(customSearchEngine)234 // Performs a search and opens 2 dummy search results links to create a search group235 homeScreen {236 }.openSearch {237 }.submitQuery("test search") {238 longClickMatchingText("Link 1")239 clickContextOpenLinkInNewTab()240 longClickMatchingText("Link 2")241 clickContextOpenLinkInNewTab()242 }.openTabDrawer {243 }.openTabFromGroup(firstPage) {244 }.openTabDrawer {245 }.openTabFromGroup(secondPage) {246 }.openTabDrawer {247 }.openTabsListThreeDotMenu {248 }.closeAllTabs {249 verifyRecentlyVisitedSearchGroupDisplayed(true, "test search", 3)250 }.openRecentlyVisitedSearchGroupHistoryList("test search") {251 clickDeleteHistoryButton(firstPage)252 longTapSelectItem(secondPage.toUri())253 multipleSelectionToolbar {254 openActionBarOverflowOrOptionsMenu(activityTestRule.activity)255 clickMultiSelectionDelete()256 }257 exitMenu()258 }259 homeScreen {260 // checking that the group is removed when only 1 item is left261 verifyRecentlyVisitedSearchGroupDisplayed(false, "test search", 1)262 }263 }264}...

Full Screen

Full Screen

ContextMenusTest.kt

Source:ContextMenusTest.kt Github

copy

Full Screen

...20import org.mozilla.fenix.ui.robots.navigationToolbar21/**22 * Tests for verifying basic functionality of content context menus23 *24 * - Verifies long click "Open link in new tab" UI and functionality25 * - Verifies long click "Open link in new Private tab" UI and functionality26 * - Verifies long click "Copy Link" UI and functionality27 * - Verifies long click "Share Link" UI and functionality28 * - Verifies long click "Open image in new tab" UI and functionality29 * - Verifies long click "Save Image" UI and functionality30 * - Verifies long click "Copy image location" UI and functionality31 * - Verifies long click items of mixed hypertext items32 *33 */34class ContextMenusTest {35 private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())36 private lateinit var mockWebServer: MockWebServer37 @get:Rule38 val activityIntentTestRule = HomeActivityIntentTestRule()39 @Before40 fun setUp() {41 activityIntentTestRule.activity.applicationContext.settings().shouldShowJumpBackInCFR = false42 mockWebServer = MockWebServer().apply {43 dispatcher = AndroidAssetDispatcher()44 start()45 }46 }47 @After48 fun tearDown() {49 mockWebServer.shutdown()50 }51 @SmokeTest52 @Test53 fun verifyContextOpenLinkNewTab() {54 val pageLinks =55 TestAssetHelper.getGenericAsset(mockWebServer, 4)56 val genericURL =57 TestAssetHelper.getGenericAsset(mockWebServer, 1)58 navigationToolbar {59 }.enterURLAndEnterToBrowser(pageLinks.url) {60 mDevice.waitForIdle()61 longClickMatchingText("Link 1")62 verifyLinkContextMenuItems(genericURL.url)63 clickContextOpenLinkInNewTab()64 verifySnackBarText("New tab opened")65 snackBarButtonClick()66 verifyUrl(genericURL.url.toString())67 }.openTabDrawer {68 verifyNormalModeSelected()69 verifyExistingOpenTabs("Test_Page_1")70 verifyExistingOpenTabs("Test_Page_4")71 }72 }73 @SmokeTest74 @Test75 fun verifyContextOpenLinkPrivateTab() {76 val pageLinks =77 TestAssetHelper.getGenericAsset(mockWebServer, 4)78 val genericURL =79 TestAssetHelper.getGenericAsset(mockWebServer, 2)80 navigationToolbar {81 }.enterURLAndEnterToBrowser(pageLinks.url) {82 mDevice.waitForIdle()83 longClickMatchingText("Link 2")84 verifyLinkContextMenuItems(genericURL.url)85 clickContextOpenLinkInPrivateTab()86 verifySnackBarText("New private tab opened")87 snackBarButtonClick()88 verifyUrl(genericURL.url.toString())89 }.openTabDrawer {90 verifyPrivateModeSelected()91 verifyExistingOpenTabs("Test_Page_2")92 }93 }94 @Test95 fun verifyContextCopyLink() {96 val pageLinks =97 TestAssetHelper.getGenericAsset(mockWebServer, 4)98 val genericURL =99 TestAssetHelper.getGenericAsset(mockWebServer, 3)100 navigationToolbar {101 }.enterURLAndEnterToBrowser(pageLinks.url) {102 mDevice.waitForIdle()103 longClickMatchingText("Link 3")104 verifyLinkContextMenuItems(genericURL.url)105 clickContextCopyLink()106 verifySnackBarText("Link copied to clipboard")107 }.openNavigationToolbar {108 }.visitLinkFromClipboard {109 verifyUrl(genericURL.url.toString())110 }111 }112 @Test113 fun verifyContextShareLink() {114 val pageLinks =115 TestAssetHelper.getGenericAsset(mockWebServer, 4)116 val genericURL =117 TestAssetHelper.getGenericAsset(mockWebServer, 1)118 navigationToolbar {119 }.enterURLAndEnterToBrowser(pageLinks.url) {120 mDevice.waitForIdle()121 longClickMatchingText("Link 1")122 verifyLinkContextMenuItems(genericURL.url)123 clickContextShareLink(genericURL.url) // verify share intent is matched with associated URL124 }125 }126 @Test127 fun verifyContextOpenImageNewTab() {128 val pageLinks =129 TestAssetHelper.getGenericAsset(mockWebServer, 4)130 val imageResource =131 TestAssetHelper.getImageAsset(mockWebServer)132 navigationToolbar {133 }.enterURLAndEnterToBrowser(pageLinks.url) {134 mDevice.waitForIdle()135 longClickMatchingText("test_link_image")136 verifyLinkImageContextMenuItems(imageResource.url)137 clickContextOpenImageNewTab()138 verifySnackBarText("New tab opened")139 snackBarButtonClick()140 verifyUrl(imageResource.url.toString())141 }142 }143 @Test144 fun verifyContextCopyImageLocation() {145 val pageLinks =146 TestAssetHelper.getGenericAsset(mockWebServer, 4)147 val imageResource =148 TestAssetHelper.getImageAsset(mockWebServer)149 navigationToolbar {150 }.enterURLAndEnterToBrowser(pageLinks.url) {151 mDevice.waitForIdle()152 longClickMatchingText("test_link_image")153 verifyLinkImageContextMenuItems(imageResource.url)154 clickContextCopyImageLocation()155 verifySnackBarText("Link copied to clipboard")156 }.openNavigationToolbar {157 }.visitLinkFromClipboard {158 verifyUrl(imageResource.url.toString())159 }160 }161 @Test162 fun verifyContextSaveImage() {163 val pageLinks =164 TestAssetHelper.getGenericAsset(mockWebServer, 4)165 val imageResource =166 TestAssetHelper.getImageAsset(mockWebServer)167 navigationToolbar {168 }.enterURLAndEnterToBrowser(pageLinks.url) {169 mDevice.waitForIdle()170 longClickMatchingText("test_link_image")171 verifyLinkImageContextMenuItems(imageResource.url)172 clickContextSaveImage()173 }174 downloadRobot {175 }.clickAllowPermission {176 verifyDownloadNotificationPopup()177 }.clickOpen("image/jpeg") {} // verify open intent is matched with associated data type178 downloadRobot {179 verifyPhotosAppOpens()180 }181 }182 @Test183 fun verifyContextMixedVariations() {184 val pageLinks =185 TestAssetHelper.getGenericAsset(mockWebServer, 4)186 val genericURL =187 TestAssetHelper.getGenericAsset(mockWebServer, 1)188 val imageResource =189 TestAssetHelper.getImageAsset(mockWebServer)190 navigationToolbar {191 }.enterURLAndEnterToBrowser(pageLinks.url) {192 mDevice.waitForIdle()193 longClickMatchingText("Link 1")194 verifyLinkContextMenuItems(genericURL.url)195 dismissContentContextMenu(genericURL.url)196 longClickMatchingText("test_link_image")197 verifyLinkImageContextMenuItems(imageResource.url)198 dismissContentContextMenu(imageResource.url)199 longClickMatchingText("test_no_link_image")200 verifyNoLinkImageContextMenuItems(imageResource.url)201 }202 }203 @SmokeTest204 @Test205 fun shareSelectedTextTest() {206 val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)207 navigationToolbar {208 }.enterURLAndEnterToBrowser(genericURL.url) {209 longClickMatchingText(genericURL.content)210 }.clickShareSelectedText {211 verifyAndroidShareLayout()212 }213 }214 @Ignore("Failing, see: https://github.com/mozilla-mobile/fenix/issues/24457")215 @SmokeTest216 @Test217 fun selectAndSearchTextTest() {218 val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)219 navigationToolbar {220 }.enterURLAndEnterToBrowser(genericURL.url) {221 longClickAndSearchText("Search", "content")222 mDevice.waitForIdle()223 verifyTabCounter("2")224 verifyUrl("google")225 }226 }227 @SmokeTest228 @Test229 fun privateSelectAndSearchTextTest() {230 val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)231 homeScreen {232 }.togglePrivateBrowsingMode()233 navigationToolbar {234 }.enterURLAndEnterToBrowser(genericURL.url) {235 longClickAndSearchText("Private Search", "content")236 mDevice.waitForIdle()237 verifyTabCounter("2")238 verifyUrl("google")239 }240 }241}...

Full Screen

Full Screen

DatabaseUtilsTest.kt

Source:DatabaseUtilsTest.kt Github

copy

Full Screen

...37 )38 verifyAll {39 roomDatabase.openHelper.readableDatabase40 database.compileStatement(query + "table")41 statement.longForQuery()42 statement.close()43 }44 }45 @Test46 fun `queryNumEntries should delegate to openHelper readable database with selection`() {47 every {48 statement.simpleQueryForLong()49 } returns 4350 assertEquals(51 43,52 roomDatabase.queryNumEntries(53 "table",54 "selection",55 "arg1",56 "arg2",57 ),58 )59 verifyAll {60 roomDatabase.openHelper.readableDatabase61 database.compileStatement(query + "table WHERE selection")62 statement.longForQuery("arg1", "arg2")63 statement.close()64 }65 }66 @Test67 fun `queryNumEntries should delegate to statement`() {68 every {69 statement.simpleQueryForLong()70 } returns 4371 assertEquals(72 43,73 database.queryNumEntries(74 "table",75 ),76 )77 verifyAll {78 database.compileStatement(query + "table")79 statement.longForQuery()80 statement.close()81 }82 }83 @Test84 fun `queryNumEntries should delegate to statement with selection`() {85 every {86 statement.simpleQueryForLong()87 } returns 4388 assertEquals(89 43,90 database.queryNumEntries(91 "table",92 "selection",93 "arg1",94 "arg2",95 ),96 )97 verifyAll {98 database.compileStatement(query + "table WHERE selection")99 statement.longForQuery("arg1", "arg2")100 statement.close()101 }102 }103 @Test104 fun `longForQuery should delegate to compiled statement`() {105 every {106 statement.longForQuery(107 any(),108 "arg1",109 "arg2",110 )111 } returns 43112 assertEquals(113 43,114 database.longForQuery(115 query,116 "arg1",117 "arg2",118 ),119 )120 verifyAll {121 database.compileStatement(query)122 statement.longForQuery("arg1", "arg2")123 statement.close()124 }125 }126 @Test127 fun `stringForQuery should delegate to compiled statement`() {128 every {129 statement.stringForQuery(130 any(),131 "arg1",132 "arg2",133 )134 } returns "string"135 assertEquals(136 "string",137 database.stringForQuery(138 query,139 "arg1",140 "arg2",141 ),142 )143 verifyAll {144 database.compileStatement(query)145 statement.stringForQuery("arg1", "arg2")146 statement.close()147 }148 }149 @Test150 fun `bindAllArgsAsStrings should bind all args as string`() {151 program.bindAllArgsAsStrings("1", "2", "3", "4")152 verifyAll {153 program.bindString(1, "1")154 program.bindString(2, "2")155 program.bindString(3, "3")156 program.bindString(4, "4")157 }158 }159 @Test160 fun `bindObject should bind null`() {161 program.bindObject(1, null)162 verifyAll { program.bindNull(1) }163 }164 @Test165 fun `bindObject should bind double`() {166 program.bindObject(3, 2.1)167 verifyAll { program.bindDouble(3, 2.1) }168 }169 @Test170 fun `bindObject should bind float`() {171 program.bindObject(3, 2.1F)172 verifyAll { program.bindDouble(3, 2.1F.toDouble()) }173 }174 @Test175 fun `bindObject should bind long`() {176 program.bindObject(3, 2L)177 verifyAll { program.bindLong(3, 2) }178 }179 @Test180 fun `bindObject should bind int`() {181 program.bindObject(3, 2)182 verifyAll { program.bindLong(3, 2) }183 }184 @Test185 fun `bindObject should bind short`() {186 program.bindObject(2, 1.toShort())187 verifyAll { program.bindLong(2, 1) }188 }189 @Test...

Full Screen

Full Screen

DatabaseUtilsFuncTest.kt

Source:DatabaseUtilsFuncTest.kt Github

copy

Full Screen

...41 ),42 )43 }44 @Test45 fun `longForQuery should return the first entry as long`() {46 assertEquals(47 1,48 database.longForQuery(49 "SELECT * FROM test",50 ),51 )52 }53 @Test54 fun `longForQuery should return the first filtered entry as long`() {55 assertEquals(56 2,57 database.longForQuery(58 "SELECT * FROM test WHERE col2 > ? AND col1 < ?",59 "2",60 "3",61 ),62 )63 }64 @Test65 fun `longForQuery should return the first entry as long for statement`() {66 assertEquals(67 2,68 database.compileStatement(69 "SELECT col2 FROM test",70 ).longForQuery(),71 )72 }73 @Test74 fun `longForQuery should return the first filtered entry as long for statement`() {75 assertEquals(76 5,77 database.compileStatement(78 "SELECT col2 FROM test WHERE col1 > ?",79 ).longForQuery("3"),80 )81 }82 @Test83 fun `stringForQuery should return the first entry as string`() {84 assertEquals(85 "2",86 database.stringForQuery(87 "SELECT col2, col1 FROM test",88 ),89 )90 }91 @Test92 fun `stringForQuery should return the first filtered entry as string`() {93 assertEquals(...

Full Screen

Full Screen

CommentViewModelTest.kt

Source:CommentViewModelTest.kt Github

copy

Full Screen

1package com.example.openmarket.viewmodel2import android.app.Application3import androidx.room.Room4import androidx.test.platform.app.InstrumentationRegistry5import com.example.openmarket.data.Comment6import com.example.openmarket.data.OpenMarketDatabase7import com.example.openmarket.viewmodel.`fake repositories`.CommentFakeRepository8import org.junit.After9import org.junit.Assert10import org.junit.Before11import org.junit.Test12import java.util.*13class CommentViewModelTest {14 private lateinit var openMarketDatabase: OpenMarketDatabase15 private lateinit var commentViewModel: CommentViewModel16 @Before17 fun setUp() {18 val context = InstrumentationRegistry.getInstrumentation().targetContext19 openMarketDatabase= OpenMarketDatabase.getInstance(context)20 commentViewModel= CommentViewModel(Application())21 commentViewModel.commentRepository= CommentFakeRepository(openMarketDatabase.getCommentDao(),openMarketDatabase.getProductCommentDao())22 }23 @After24 fun tearDown() {25 openMarketDatabase.close()26 }27 @Test28 fun getCommentForProduct() {29 var comment=Comment(0,"test comment",Date().toString(),"test_username")30 var product_id:Long=1231 commentViewModel.insertComment(comment,product_id)32 var contains=commentViewModel.getCommentForProduct(product_id).value?.contains(comment)33 assert(contains as Boolean)34 }35 @Test36 fun getCommentByUsername() {37 var username="test_username"38 var comment=Comment(0,"test comment",Date().toString(),username)39 var product_id:Long=1240 commentViewModel.insertComment(comment,product_id)41 var contains=commentViewModel.getCommentByUsername(username).value?.contains(comment)42 assert(contains as Boolean)43 }44 @Test45 fun getCommentById() {46 var comment=Comment(0,"test comment",Date().toString(),"test_username")47 var product_id:Long=1248 commentViewModel.insertComment(comment,product_id)49 var comment2=commentViewModel.getCommentById(comment.id).value as Comment50 Assert.assertEquals(comment,comment2)51 }52 @Test53 fun updateComment() {54 var comment=Comment(0,"test comment",Date().toString(),"test_username")55 var product_id:Long=1256 commentViewModel.insertComment(comment,product_id)57 comment=Comment(0,"test comment changed",Date().toString(),"test_username")58 commentViewModel.updateComment(comment)59 var old_comment=commentViewModel.getCommentById(comment.id).value as Comment60 Assert.assertEquals(comment,old_comment)61 }62}...

Full Screen

Full Screen

long

Using AI Code Generation

copy

Full Screen

1 }2 public void Open(String url) {3 driver.get(url);4 }5 public void close() {6 driver.close();7 }8}

Full Screen

Full Screen

long

Using AI Code Generation

copy

Full Screen

1 System.out.println("Browser name is "+ test.Open.getBrowserName());2 System.out.println("Url is "+ test.Open.getUrl());3 System.out.println("Username is "+ test.Open.getUsername());4 System.out.println("Password is "+ test.Open.getPassword());5 System.out.println("Driver is "+ test.Open.getDriver());6 }7}

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