64
64
import static org .junit .Assert .assertNotEquals ;
65
65
import static org .mockito .ArgumentMatchers .any ;
66
66
import static org .mockito .ArgumentMatchers .eq ;
67
- import static org .mockito .Mockito .doAnswer ;
68
- import static org .mockito .Mockito .mock ;
69
- import static org .mockito .Mockito .spy ;
70
- import static org .mockito .Mockito .verify ;
71
- import static org .mockito .Mockito .when ;
67
+ import static org .mockito .Mockito .*;
72
68
73
69
/**
74
70
* Tests for {@link OptimizelyManager}
@@ -500,14 +496,20 @@ public void initializeSyncWithUpdateOnNewDatafileDisabled() {
500
496
OptimizelyManager manager = new OptimizelyManager (testProjectId , testSdkKey , null , logger , pollingInterval , datafileHandler , null , 0 ,
501
497
null , null , null , null , null , null , null , null , null );
502
498
503
- doAnswer (
504
- new Answer <Object >() {
505
- public Object answer (InvocationOnMock invocation ) {
506
- String newDatafile = manager .getDatafile (context , R .raw .datafile_api );
507
- datafileHandler .saveDatafile (context , manager .getDatafileConfig (), newDatafile );
508
- return null ;
509
- }
510
- }).when (manager .getDatafileHandler ()).downloadDatafile (any (Context .class ), any (DatafileConfig .class ), any (DatafileLoadedListener .class ));
499
+ ArgumentCaptor <Context > contextCaptor = ArgumentCaptor .forClass (Context .class );
500
+ ArgumentCaptor <DatafileConfig > configCaptor = ArgumentCaptor .forClass (DatafileConfig .class );
501
+ ArgumentCaptor <DatafileLoadedListener > listenerCaptor = ArgumentCaptor .forClass (DatafileLoadedListener .class );
502
+
503
+ doAnswer (invocation -> {
504
+ Context capturedContext = contextCaptor .getValue ();
505
+ DatafileConfig capturedConfig = configCaptor .getValue ();
506
+ DatafileLoadedListener capturedListener = listenerCaptor .getValue ();
507
+
508
+ String newDatafile = manager .getDatafile (capturedContext , R .raw .datafile_api );
509
+ datafileHandler .saveDatafile (capturedContext , capturedConfig , newDatafile );
510
+
511
+ return datafileHandler ;
512
+ }).when (manager .getDatafileHandler ()).downloadDatafile (contextCaptor .capture (), configCaptor .capture (), listenerCaptor .capture ());
511
513
512
514
OptimizelyClient client = manager .initialize (context , defaultDatafile , downloadToCache , updateConfigOnNewDatafile );
513
515
@@ -533,14 +535,20 @@ public void initializeSyncWithUpdateOnNewDatafileEnabled() {
533
535
OptimizelyManager manager = new OptimizelyManager (testProjectId , testSdkKey , null , logger , pollingInterval , datafileHandler , null , 0 ,
534
536
null , null , null , null , null , null , null , null , null );
535
537
536
- doAnswer (
537
- new Answer <Object >() {
538
- public Object answer (InvocationOnMock invocation ) {
539
- String newDatafile = manager .getDatafile (context , R .raw .datafile_api );
540
- datafileHandler .saveDatafile (context , manager .getDatafileConfig (), newDatafile );
541
- return null ;
542
- }
543
- }).when (manager .getDatafileHandler ()).downloadDatafile (any (Context .class ), any (DatafileConfig .class ), any (DatafileLoadedListener .class ));
538
+ ArgumentCaptor <Context > contextCaptor = ArgumentCaptor .forClass (Context .class );
539
+ ArgumentCaptor <DatafileConfig > configCaptor = ArgumentCaptor .forClass (DatafileConfig .class );
540
+ ArgumentCaptor <DatafileLoadedListener > listenerCaptor = ArgumentCaptor .forClass (DatafileLoadedListener .class );
541
+
542
+ doAnswer (invocation -> {
543
+ Context capturedContext = contextCaptor .getValue ();
544
+ DatafileConfig capturedConfig = configCaptor .getValue ();
545
+ DatafileLoadedListener capturedListener = listenerCaptor .getValue ();
546
+
547
+ String newDatafile = manager .getDatafile (capturedContext , R .raw .datafile_api );
548
+ datafileHandler .saveDatafile (capturedContext , capturedConfig , newDatafile );
549
+
550
+ return datafileHandler ;
551
+ }).when (manager .getDatafileHandler ()).downloadDatafile (contextCaptor .capture (), configCaptor .capture (), listenerCaptor .capture ());
544
552
545
553
OptimizelyClient client = manager .initialize (context , defaultDatafile , downloadToCache , updateConfigOnNewDatafile );
546
554
@@ -566,14 +574,20 @@ public void initializeSyncWithDownloadToCacheDisabled() {
566
574
OptimizelyManager manager = new OptimizelyManager (testProjectId , testSdkKey , null , logger , pollingInterval , datafileHandler , null , 0 ,
567
575
null , null , null , null , null , null , null , null , null );
568
576
569
- doAnswer (
570
- new Answer <Object >() {
571
- public Object answer (InvocationOnMock invocation ) {
572
- String newDatafile = manager .getDatafile (context , R .raw .datafile_api );
573
- datafileHandler .saveDatafile (context , manager .getDatafileConfig (), newDatafile );
574
- return null ;
575
- }
576
- }).when (manager .getDatafileHandler ()).downloadDatafile (any (Context .class ), any (DatafileConfig .class ), any (DatafileLoadedListener .class ));
577
+ ArgumentCaptor <Context > contextCaptor = ArgumentCaptor .forClass (Context .class );
578
+ ArgumentCaptor <DatafileConfig > configCaptor = ArgumentCaptor .forClass (DatafileConfig .class );
579
+ ArgumentCaptor <DatafileLoadedListener > listenerCaptor = ArgumentCaptor .forClass (DatafileLoadedListener .class );
580
+
581
+ doAnswer (invocation -> {
582
+ Context capturedContext = contextCaptor .getValue ();
583
+ DatafileConfig capturedConfig = configCaptor .getValue ();
584
+ DatafileLoadedListener capturedListener = listenerCaptor .getValue ();
585
+
586
+ String newDatafile = manager .getDatafile (capturedContext , R .raw .datafile_api );
587
+ datafileHandler .saveDatafile (capturedContext , capturedConfig , newDatafile );
588
+
589
+ return datafileHandler ;
590
+ }).when (manager .getDatafileHandler ()).downloadDatafile (contextCaptor .capture (), configCaptor .capture (), listenerCaptor .capture ());
577
591
578
592
OptimizelyClient client = manager .initialize (context , defaultDatafile , downloadToCache , updateConfigOnNewDatafile );
579
593
@@ -599,12 +613,20 @@ public void initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingEnab
599
613
OptimizelyManager manager = new OptimizelyManager (testProjectId , testSdkKey , null , logger , pollingInterval , datafileHandler , null , 0 ,
600
614
null , null , null , null , null , null , null , null , null );
601
615
602
- doAnswer (
603
- (Answer <Object >) invocation -> {
604
- String newDatafile = manager .getDatafile (context , R .raw .datafile_api );
605
- datafileHandler .saveDatafile (context , manager .getDatafileConfig (), newDatafile );
606
- return null ;
607
- }).when (manager .getDatafileHandler ()).downloadDatafile (any (Context .class ), any (DatafileConfig .class ), any (DatafileLoadedListener .class ));
616
+ ArgumentCaptor <Context > contextCaptor = ArgumentCaptor .forClass (Context .class );
617
+ ArgumentCaptor <DatafileConfig > configCaptor = ArgumentCaptor .forClass (DatafileConfig .class );
618
+ ArgumentCaptor <DatafileLoadedListener > listenerCaptor = ArgumentCaptor .forClass (DatafileLoadedListener .class );
619
+
620
+ doAnswer (invocation -> {
621
+ Context capturedContext = contextCaptor .getValue ();
622
+ DatafileConfig capturedConfig = configCaptor .getValue ();
623
+ DatafileLoadedListener capturedListener = listenerCaptor .getValue ();
624
+
625
+ String newDatafile = manager .getDatafile (capturedContext , R .raw .datafile_api );
626
+ datafileHandler .saveDatafile (capturedContext , capturedConfig , newDatafile );
627
+
628
+ return datafileHandler ;
629
+ }).when (manager .getDatafileHandler ()).downloadDatafile (contextCaptor .capture (), configCaptor .capture (), listenerCaptor .capture ());
608
630
609
631
OptimizelyClient client = manager .initialize (context , defaultDatafile , downloadToCache , updateConfigOnNewDatafile );
610
632
@@ -631,14 +653,20 @@ public void initializeSyncWithUpdateOnNewDatafileEnabledWithPeriodicPollingEnabl
631
653
OptimizelyManager manager = new OptimizelyManager (testProjectId , testSdkKey , null , logger , pollingInterval , datafileHandler , null , 0 ,
632
654
null , null , null , null , null , null , null , null , null );
633
655
634
- doAnswer (
635
- new Answer <Object >() {
636
- public Object answer (InvocationOnMock invocation ) {
637
- String newDatafile = manager .getDatafile (context , R .raw .datafile_api );
638
- datafileHandler .saveDatafile (context , manager .getDatafileConfig (), newDatafile );
639
- return null ;
640
- }
641
- }).when (manager .getDatafileHandler ()).downloadDatafile (any (Context .class ), any (DatafileConfig .class ), any (DatafileLoadedListener .class ));
656
+ ArgumentCaptor <Context > contextCaptor = ArgumentCaptor .forClass (Context .class );
657
+ ArgumentCaptor <DatafileConfig > configCaptor = ArgumentCaptor .forClass (DatafileConfig .class );
658
+ ArgumentCaptor <DatafileLoadedListener > listenerCaptor = ArgumentCaptor .forClass (DatafileLoadedListener .class );
659
+
660
+ doAnswer (invocation -> {
661
+ Context capturedContext = contextCaptor .getValue ();
662
+ DatafileConfig capturedConfig = configCaptor .getValue ();
663
+ DatafileLoadedListener capturedListener = listenerCaptor .getValue ();
664
+
665
+ String newDatafile = manager .getDatafile (capturedContext , R .raw .datafile_api );
666
+ datafileHandler .saveDatafile (capturedContext , capturedConfig , newDatafile );
667
+
668
+ return datafileHandler ;
669
+ }).when (manager .getDatafileHandler ()).downloadDatafile (contextCaptor .capture (), configCaptor .capture (), listenerCaptor .capture ());
642
670
643
671
OptimizelyClient client = manager .initialize (context , defaultDatafile , downloadToCache , updateConfigOnNewDatafile );
644
672
@@ -664,15 +692,21 @@ public void initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingDisa
664
692
OptimizelyManager manager = new OptimizelyManager (testProjectId , testSdkKey , null , logger , pollingInterval , datafileHandler , null , 0 ,
665
693
null , null , null , null , null , null , null , null , null );
666
694
667
- doAnswer (
668
- new Answer < Object >() {
669
- public Object answer ( InvocationOnMock invocation ) {
670
- String newDatafile = manager . getDatafile ( context , R . raw . datafile_api );
671
- datafileHandler . saveDatafile ( context , manager . getDatafileConfig (), newDatafile );
672
- return null ;
673
- }
674
- }). when ( manager . getDatafileHandler ()). downloadDatafile ( any ( Context . class ), any ( DatafileConfig . class ), any ( DatafileLoadedListener . class ) );
695
+ ArgumentCaptor < Context > contextCaptor = ArgumentCaptor . forClass ( Context . class );
696
+ ArgumentCaptor < DatafileConfig > configCaptor = ArgumentCaptor . forClass ( DatafileConfig . class );
697
+ ArgumentCaptor < DatafileLoadedListener > listenerCaptor = ArgumentCaptor . forClass ( DatafileLoadedListener . class );
698
+
699
+ doAnswer ( invocation -> {
700
+ Context capturedContext = contextCaptor . getValue () ;
701
+ DatafileConfig capturedConfig = configCaptor . getValue ();
702
+ DatafileLoadedListener capturedListener = listenerCaptor . getValue ( );
675
703
704
+ String newDatafile = manager .getDatafile (capturedContext , R .raw .datafile_api );
705
+ datafileHandler .saveDatafile (capturedContext , capturedConfig , newDatafile );
706
+
707
+ return datafileHandler ;
708
+ }).when (manager .getDatafileHandler ()).downloadDatafile (contextCaptor .capture (), configCaptor .capture (), listenerCaptor .capture ());
709
+
676
710
OptimizelyClient client = manager .initialize (context , defaultDatafile , downloadToCache , updateConfigOnNewDatafile );
677
711
678
712
try {
@@ -698,14 +732,20 @@ public void initializeSyncWithUpdateOnNewDatafileEnabledWithPeriodicPollingDisab
698
732
OptimizelyManager manager = new OptimizelyManager (testProjectId , testSdkKey , null , logger , pollingInterval , datafileHandler , null , 0 ,
699
733
null , null , null , null , null , null , null , null , null );
700
734
701
- doAnswer (
702
- new Answer <Object >() {
703
- public Object answer (InvocationOnMock invocation ) {
704
- String newDatafile = manager .getDatafile (context , R .raw .datafile_api );
705
- datafileHandler .saveDatafile (context , manager .getDatafileConfig (), newDatafile );
706
- return null ;
707
- }
708
- }).when (manager .getDatafileHandler ()).downloadDatafile (any (Context .class ), any (DatafileConfig .class ), any (DatafileLoadedListener .class ));
735
+ ArgumentCaptor <Context > contextCaptor = ArgumentCaptor .forClass (Context .class );
736
+ ArgumentCaptor <DatafileConfig > configCaptor = ArgumentCaptor .forClass (DatafileConfig .class );
737
+ ArgumentCaptor <DatafileLoadedListener > listenerCaptor = ArgumentCaptor .forClass (DatafileLoadedListener .class );
738
+
739
+ doAnswer (invocation -> {
740
+ Context capturedContext = contextCaptor .getValue ();
741
+ DatafileConfig capturedConfig = configCaptor .getValue ();
742
+ DatafileLoadedListener capturedListener = listenerCaptor .getValue ();
743
+
744
+ String newDatafile = manager .getDatafile (capturedContext , R .raw .datafile_api );
745
+ datafileHandler .saveDatafile (capturedContext , capturedConfig , newDatafile );
746
+
747
+ return datafileHandler ;
748
+ }).when (manager .getDatafileHandler ()).downloadDatafile (contextCaptor .capture (), configCaptor .capture (), listenerCaptor .capture ());
709
749
710
750
OptimizelyClient client = manager .initialize (context , defaultDatafile , downloadToCache , updateConfigOnNewDatafile );
711
751
0 commit comments