diff --git a/.gitignore b/.gitignore index 790fc0ca..a09571ad 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ target/ # Eclipse **/*.project **/*.classpath -**/*.settings \ No newline at end of file +**/*.settings +.qodo diff --git a/DiffblueCustomInputExamplesREADME.txt b/DiffblueCustomInputExamplesREADME.txt new file mode 100644 index 00000000..685c9e9a --- /dev/null +++ b/DiffblueCustomInputExamplesREADME.txt @@ -0,0 +1,33 @@ +------------------------------ +Diffblue Custom Input Examples +------------------------------ + +Cover will natively generate tests that exercise as much of the method under test as possible, using its own analysis of the code. + +However, additional context can be provided to Cover through custom inputs, allowing it to generate different or additional tests based on the supplied data. + +Cover will assess the inputs and include those most suitable, though it may not necessarily use all provided inputs. + +There are multiple methods available for different scenarios. This branch includes examples demonstrating the following custom input options: + +1) DiffblueRules.yaml file: Providing example entries for different use cases - further information on these can be found on our documentation website (https://docs.diffblue.com/features/cover-cli/writing-tests/custom-inputs#custom-inputs) + + Immediate rule entries will be prioritised for consideration by Cover if identified as being relevant for the method under test + Properties rule entries can be used to specify property files for consideration and their location. These can be specified for certain classes/methods or for Cover to consider across all classes. Example entries and properties file provided are dummy data only as examples of how these may be included if desired/relevant + +2) Test Factories: An additional class file setting out input values for an associating class; combined with a DiffblueRules file entry - further information on this can be found on our documentation website (https://docs.diffblue.com/features/cover-cli/writing-tests/custom-inputs#factory-rule) + + Stand-alone class files have been added for this example: UserFactory, DateAndTime and DateFactory + To use the User factory please comment out the Username & password immediate rules within the DiffblueRules.yaml file and uncomment the "com.piggymetrics.account.domain.User" factory rule section + +3) Annotations: A couple of example annotations that can be included directly within the class file to suggest inputs or promote methods ("InTest" & "interestingTestFactory") - further information on possible annotations can be found on our documentation website (https://docs.diffblue.com/features/cover-annotations/custom-input-annotations & https://docs.diffblue.com/features/cover-annotations/interesting-value-annotations) + + For the "InTest" annotation a stand-alone class file has been added for this example: UserValidator + To use this annotation please comment out the Username & password immediate rules within the DiffblueRules.yaml file and uncomment the two "@InTestsUseStrings" sections within the class file + + For the "interestingTestFactory" annotation the "@InterestingTestFactory" section of the two factory files (DateFactory & UserFactory) can be uncommented + +4) DiffblueBaseClass: Used as a super-class contain method to be run before writing tests - further information on this class file can be found on our documentation website (https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup#custom-base-class) + + Stand-alone class files have been added for this example: LicenseChecker and LicenseCheckerDiffblueBase + Use cases of this class include scenarios where environment settings or licencing information would need to be set or reset before or after tests are executed. \ No newline at end of file diff --git a/DiffblueRules.yml b/DiffblueRules.yml new file mode 100644 index 00000000..43566876 --- /dev/null +++ b/DiffblueRules.yml @@ -0,0 +1,130 @@ +#com.piggymetrics.account.domain.User: +# - factory: "com.piggymetrics.account.domain.UserFactory.createUser:()Lcom/piggymetrics/account/domain/User;" +# - factory: "com.piggymetrics.account.domain.UserFactory.createInvalidUser:()Lcom/piggymetrics/account/domain/User;" + +java.time.ZonedDateTime: + - factory: + method: "com.piggymetrics.account.domain.DateFactory.getSpecificDateForTesting:()Lcom/piggymetrics/account/domain/DateAndTime;" +# method: "com.piggymetrics.account.domain.DateFactory.getAnotherSpecificDateForTesting:()Lcom/piggymetrics/account/domain/DateAndTime;" + method: zonedDateTime + +java.util.Properties: + - class: com.piggymetrics.account.config.ResourceServerConfig + properties: + file: /resource.properties + +# - properties: +# file: /resource.properties + +int: + + - immediate: 10 + parameter: "^.*amount.*$" + + - immediate: 20 + parameter: "^.*amount.*$" + + - immediate: 30 + parameter: "amount" + method: addToBalance + +java.lang.String: + + - immediate: "Mr" + parameter: "^.*[Tt]itle.*$" + + - immediate: "Dr" + parameter: "^.*[Tt]itle.*$" + + - immediate: "John" + parameter: "^.*[Ff]irst.*[Nn]ame.*$" + + - immediate: "Doe" + parameter: "^.*[Ll]ast.*[Nn]ame.*$" + + - immediate: "Smith" + parameter: "^.*[Nn]ame.*$" + + - immediate: "abc" + parameter: "^.*[Pp]assw(or)?d$" + + - immediate: "qwertyuio" + parameter: "^.*[Pp]assw(or)?d$" + + - immediate: "qw" + parameter: "^.*[Uu]ser[Nn]ame.*$" + + - immediate: "smith" + parameter: "^.*[Uu]ser[Nn]ame.*$" + + - immediate: "ABC123" + parameter: "^.*[Tt]oken.*$" + + - immediate: "123ABC" + parameter: "^.*[Tt]oken.*$" + + - immediate: "jane.doe@example.org" + parameter: "^.*[Ee]mail.*$" + + - immediate: "https://example.org/example" + parameter: "^.*(url|Url|URL).*$" + + - immediate: "Dog" + classOrMethod: "^.*[Pp]et[Tt]ype.*$" + + - immediate: "Cat" + classOrMethod: "^.*[Pp]et[Tt]ype.*$" + + - immediate: "42 Main St" + parameter: "^.*[Aa]ddr(ess)?.*$" + + - immediate: "EXAMPLEKEaaabbbcccdddeeefffggggg" + parameter: "^.*[Ll]icense.*$" + + - immediate: "YwjalrXUtnFEMIK7123456789" + parameter: "^.*[Ll]icense.*$" + + - immediate: "2022-03-01" + parameter: "^.*[Dd]ate.*$" + + - immediate: "2020/03/01" + parameter: "^.*[Dd]ate.*$" + + - immediate: "2024-01-01" + classOrMethod: "LocalDate" + + - immediate: "01234567-89AB-CDEF-FEDC-BA9876543210" + parameter: "uuid" + + - immediate: "11111111111111" + parameter: "uuid" + + - immediate: "/directory/foo.txt" + parameter: "^.*[Ff]ile[Pp]ath.*$" + + - immediate: "An error occurred" + classOrMethod: "^.*Exception.*$" + parameter: "^.*[Mm]essage.*$" + + - immediate: "2.6" + classOrMethod: "^.*BigDecimal.*$" + + - immediate: "4.7" + classOrMethod: "^.*BigDecimal.*$" + + - immediate: "5.6" + classOrMethod: "^.*BigDecimal.*$" + + - immediate: "-2.3" + classOrMethod: "^.*BigDecimal.*$" + +java.lang.String[]: + + - immediate: [ "abcdefg", "abcdefg123" ] + parameter: "^.*[Pp]assw(or)?d$" + + - immediate: [ "2020-03-01", "2021-03-01" ] + parameter: "^.*[Dd]ate.*$" + + - immediate: [ "john.doe@example.org", "john.smith@example.org" ] + parameter: "^.*[Ee]mail.*$" \ No newline at end of file diff --git a/account-service/pom.xml b/account-service/pom.xml index 92b0f214..6ef39db7 100644 --- a/account-service/pom.xml +++ b/account-service/pom.xml @@ -92,6 +92,40 @@ 4.12 test + + org.junit.jupiter + junit-jupiter + 5.8.1 + compile + + + io.projectreactor + reactor-test + + + com.diffblue.cover + cover-annotations + 1.3.0 + provided + + + org.mockito + mockito-core + 4.1.0 + test + + + org.springframework + spring-core + 6.0.11 + compile + + + org.springframework.boot + spring-boot + 2.5.1 + compile + diff --git a/account-service/report.json b/account-service/report.json deleted file mode 100644 index c2dd9bcd..00000000 --- a/account-service/report.json +++ /dev/null @@ -1,1426 +0,0 @@ -{ - "meta" : { - "reportVersion" : "2.6" - }, - "run" : { - "version" : "2025.01.01-2348203-licensed", - "creationTimestamp" : "2025-01-13T16:41:01.495Z", - "command" : "dcover create --batch --report-file=report.json --coverage-reports --spring-integration-tests --verbose --exclude=com.piggymetrics.notification.service.NotificationServiceImpl. --working-directory=account-service", - "totalTime" : 434.064, - "environmentDetectionTime" : 0.681, - "indexingTime" : 0.356, - "entryPointsTime" : 0.648, - "generationTime" : 297.529, - "timeToFirstTest" : 129.68, - "timeToLastTest" : 350.479, - "indexQueryTime" : 17.16, - "verificationTime" : 27.447, - "validationTime" : 49.625 - }, - "codes" : { - "E052" : "Missing dependency", - "R000" : "Success", - "R002" : "Missing observers", - "R004" : "No meaningful assertions found", - "R013" : "No inputs found that don't throw a trivial exception", - "T000" : "Method eligible for test creation", - "T001" : "Trivial getter", - "T002" : "Trivial setter", - "T003" : "Private method", - "T005" : "Trivial constructor", - "T006" : "Main method", - "T010" : "Abstract or interface method", - "T012" : "Synthetic method", - "V000" : "Validated successfully" - }, - "summary" : { - "classesCount" : 17, - "methodsCount" : 99, - "cumulativeDiffblueTestCount" : 15, - "cumulativeManualTestCount" : 14, - "completeTestCount" : 17, - "incompleteTestCount" : 0, - "skeletonTestCount" : 0, - "totalPhysicalLineCount" : 524, - "perMethodTestability" : { - "T000" : 31, - "T001" : 19, - "T002" : 21, - "T003" : 6, - "T005" : 8, - "T006" : 1, - "T010" : 5, - "T012" : 8 - }, - "perMethodOutcome" : { - "E052" : 12, - "R000" : 53, - "R002" : 5, - "R004" : 2, - "R013" : 2, - "T003" : 6, - "T005" : 5, - "T006" : 1, - "T010" : 5, - "T012" : 8 - }, - "perTestOutcome" : { - "R000" : 17 - }, - "perTestValidation" : { - "V000" : 17 - } - }, - "classes" : { - "com.piggymetrics.account.AccountApplication" : { - "methodsCount" : 2, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T005" : 1, - "T006" : 1 - }, - "perMethodOutcome" : { - "T005" : 1, - "T006" : 1 - } - }, - "com.piggymetrics.account.client.AuthServiceClient" : { - "methodsCount" : 1, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T010" : 1 - }, - "perMethodOutcome" : { - "T010" : 1 - } - }, - "com.piggymetrics.account.client.StatisticsServiceClient" : { - "methodsCount" : 1, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T010" : 1 - }, - "perMethodOutcome" : { - "T010" : 1 - } - }, - "com.piggymetrics.account.client.StatisticsServiceClientFallback" : { - "methodsCount" : 3, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T005" : 1, - "T012" : 1 - }, - "perMethodOutcome" : { - "R004" : 1, - "T005" : 1, - "T012" : 1 - } - }, - "com.piggymetrics.account.config.ResourceServerConfig" : { - "methodsCount" : 6, - "completeTestCount" : 4, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 5, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 4, - "R013" : 1, - "T005" : 1 - }, - "perTestOutcome" : { - "R000" : 4 - } - }, - "com.piggymetrics.account.controller.AccountController" : { - "methodsCount" : 5, - "completeTestCount" : 4, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 4, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 4, - "T005" : 1 - }, - "perTestOutcome" : { - "R000" : 4 - } - }, - "com.piggymetrics.account.controller.ErrorHandler" : { - "methodsCount" : 2, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 2 - }, - "perMethodOutcome" : { - "R002" : 2 - } - }, - "com.piggymetrics.account.domain.Account" : { - "methodsCount" : 13, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 6, - "T002" : 6, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 13 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.account.domain.Currency" : { - "methodsCount" : 5, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 1, - "T003" : 1, - "T012" : 3 - }, - "perMethodOutcome" : { - "R000" : 1, - "T003" : 1, - "T012" : 3 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.account.domain.Item" : { - "methodsCount" : 11, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 5, - "T002" : 5, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 11 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.account.domain.Saving" : { - "methodsCount" : 11, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 5, - "T002" : 5, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 11 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.account.domain.TimePeriod" : { - "methodsCount" : 4, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T003" : 1, - "T012" : 3 - }, - "perMethodOutcome" : { - "T003" : 1, - "T012" : 3 - } - }, - "com.piggymetrics.account.domain.User" : { - "methodsCount" : 5, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 2, - "T002" : 2, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 5 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.account.repository.AccountRepository" : { - "methodsCount" : 12, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 12 - }, - "perMethodOutcome" : { - "E052" : 12 - } - }, - "com.piggymetrics.account.service.AccountService" : { - "methodsCount" : 3, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T010" : 3 - }, - "perMethodOutcome" : { - "T010" : 3 - } - }, - "com.piggymetrics.account.service.AccountServiceImpl" : { - "methodsCount" : 4, - "completeTestCount" : 2, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 4 - }, - "perMethodOutcome" : { - "R000" : 2, - "R013" : 1, - "T005" : 1 - }, - "perTestOutcome" : { - "R000" : 2 - } - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices" : { - "methodsCount" : 11, - "completeTestCount" : 2, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 3, - "T002" : 3, - "T003" : 4, - "T012" : 1 - }, - "perMethodOutcome" : { - "R000" : 2, - "R002" : 3, - "R004" : 1, - "T003" : 4, - "T012" : 1 - }, - "perTestOutcome" : { - "R000" : 2 - } - } - }, - "methods" : { - "com.piggymetrics.account.AccountApplication.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 17 - ] - }, - "com.piggymetrics.account.AccountApplication.main:([Ljava/lang/String;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T006", - "perMethodOutcome" : "T006", - "lineNumbers" : [ - 20, - 21 - ] - }, - "com.piggymetrics.account.client.AuthServiceClient.createUser:(Lcom/piggymetrics/account/domain/User;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.account.client.StatisticsServiceClient.updateStatistics:(Ljava/lang/String;Lcom/piggymetrics/account/domain/Account;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.account.client.StatisticsServiceClientFallback.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 13 - ] - }, - "com.piggymetrics.account.client.StatisticsServiceClientFallback.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 12 - ] - }, - "com.piggymetrics.account.client.StatisticsServiceClientFallback.updateStatistics:(Ljava/lang/String;Lcom/piggymetrics/account/domain/Account;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R004", - "lineNumbers" : [ - 16, - 17 - ] - }, - "com.piggymetrics.account.config.ResourceServerConfig.:(Lorg/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerProperties;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 29, - 30, - 31 - ] - }, - "com.piggymetrics.account.config.ResourceServerConfig.clientCredentialsResourceDetails:()Lorg/springframework/security/oauth2/client/token/grant/client/ClientCredentialsResourceDetails;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 36 - ] - }, - "com.piggymetrics.account.config.ResourceServerConfig.clientCredentialsRestTemplate:()Lorg/springframework/security/oauth2/client/OAuth2RestTemplate;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 46 - ] - }, - "com.piggymetrics.account.config.ResourceServerConfig.configure:(Lorg/springframework/security/config/annotation/web/builders/HttpSecurity;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R013", - "lineNumbers" : [ - 56, - 57, - 58, - 59 - ] - }, - "com.piggymetrics.account.config.ResourceServerConfig.oauth2FeignRequestInterceptor:()Lfeign/RequestInterceptor;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 41 - ] - }, - "com.piggymetrics.account.config.ResourceServerConfig.tokenServices:()Lorg/springframework/security/oauth2/provider/token/ResourceServerTokenServices;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 51 - ] - }, - "com.piggymetrics.account.controller.AccountController.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 14 - ] - }, - "com.piggymetrics.account.controller.AccountController.createNewAccount:(Lcom/piggymetrics/account/domain/User;)Lcom/piggymetrics/account/domain/Account;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 37 - ] - }, - "com.piggymetrics.account.controller.AccountController.getAccountByName:(Ljava/lang/String;)Lcom/piggymetrics/account/domain/Account;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 22 - ] - }, - "com.piggymetrics.account.controller.AccountController.getCurrentAccount:(Ljava/security/Principal;)Lcom/piggymetrics/account/domain/Account;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 27 - ] - }, - "com.piggymetrics.account.controller.AccountController.saveCurrentAccount:(Ljava/security/Principal;Lcom/piggymetrics/account/domain/Account;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 32, - 33 - ] - }, - "com.piggymetrics.account.controller.ErrorHandler.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R002", - "lineNumbers" : [ - 11, - 13 - ] - }, - "com.piggymetrics.account.controller.ErrorHandler.processValidationError:(Ljava/lang/IllegalArgumentException;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R002", - "lineNumbers" : [ - 20, - 21 - ] - }, - "com.piggymetrics.account.domain.Account.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 15 - ] - }, - "com.piggymetrics.account.domain.Account.getExpenses:()Ljava/util/List;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 60 - ] - }, - "com.piggymetrics.account.domain.Account.getIncomes:()Ljava/util/List;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 52 - ] - }, - "com.piggymetrics.account.domain.Account.getLastSeen:()Ljava/util/Date;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 44 - ] - }, - "com.piggymetrics.account.domain.Account.getName:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 36 - ] - }, - "com.piggymetrics.account.domain.Account.getNote:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 76 - ] - }, - "com.piggymetrics.account.domain.Account.getSaving:()Lcom/piggymetrics/account/domain/Saving;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 68 - ] - }, - "com.piggymetrics.account.domain.Account.setExpenses:(Ljava/util/List;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 64, - 65 - ] - }, - "com.piggymetrics.account.domain.Account.setIncomes:(Ljava/util/List;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 56, - 57 - ] - }, - "com.piggymetrics.account.domain.Account.setLastSeen:(Ljava/util/Date;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 48, - 49 - ] - }, - "com.piggymetrics.account.domain.Account.setName:(Ljava/lang/String;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 40, - 41 - ] - }, - "com.piggymetrics.account.domain.Account.setNote:(Ljava/lang/String;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 80, - 81 - ] - }, - "com.piggymetrics.account.domain.Account.setSaving:(Lcom/piggymetrics/account/domain/Saving;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 72, - 73 - ] - }, - "com.piggymetrics.account.domain.Currency.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 5, - 3 - ] - }, - "com.piggymetrics.account.domain.Currency.:(Ljava/lang/String;I)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.account.domain.Currency.getDefault:()Lcom/piggymetrics/account/domain/Currency;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 8 - ] - }, - "com.piggymetrics.account.domain.Currency.valueOf:(Ljava/lang/String;)Lcom/piggymetrics/account/domain/Currency;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.account.domain.Currency.values:()[Lcom/piggymetrics/account/domain/Currency;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.account.domain.Item.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 8 - ] - }, - "com.piggymetrics.account.domain.Item.getAmount:()Ljava/math/BigDecimal;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 35 - ] - }, - "com.piggymetrics.account.domain.Item.getCurrency:()Lcom/piggymetrics/account/domain/Currency;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 43 - ] - }, - "com.piggymetrics.account.domain.Item.getIcon:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 59 - ] - }, - "com.piggymetrics.account.domain.Item.getPeriod:()Lcom/piggymetrics/account/domain/TimePeriod;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 51 - ] - }, - "com.piggymetrics.account.domain.Item.getTitle:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 27 - ] - }, - "com.piggymetrics.account.domain.Item.setAmount:(Ljava/math/BigDecimal;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 39, - 40 - ] - }, - "com.piggymetrics.account.domain.Item.setCurrency:(Lcom/piggymetrics/account/domain/Currency;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 47, - 48 - ] - }, - "com.piggymetrics.account.domain.Item.setIcon:(Ljava/lang/String;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 63, - 64 - ] - }, - "com.piggymetrics.account.domain.Item.setPeriod:(Lcom/piggymetrics/account/domain/TimePeriod;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 55, - 56 - ] - }, - "com.piggymetrics.account.domain.Item.setTitle:(Ljava/lang/String;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 31, - 32 - ] - }, - "com.piggymetrics.account.domain.Saving.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 6 - ] - }, - "com.piggymetrics.account.domain.Saving.getAmount:()Ljava/math/BigDecimal;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 24 - ] - }, - "com.piggymetrics.account.domain.Saving.getCapitalization:()Ljava/lang/Boolean;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 56 - ] - }, - "com.piggymetrics.account.domain.Saving.getCurrency:()Lcom/piggymetrics/account/domain/Currency;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 32 - ] - }, - "com.piggymetrics.account.domain.Saving.getDeposit:()Ljava/lang/Boolean;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 48 - ] - }, - "com.piggymetrics.account.domain.Saving.getInterest:()Ljava/math/BigDecimal;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 40 - ] - }, - "com.piggymetrics.account.domain.Saving.setAmount:(Ljava/math/BigDecimal;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 28, - 29 - ] - }, - "com.piggymetrics.account.domain.Saving.setCapitalization:(Ljava/lang/Boolean;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 60, - 61 - ] - }, - "com.piggymetrics.account.domain.Saving.setCurrency:(Lcom/piggymetrics/account/domain/Currency;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 36, - 37 - ] - }, - "com.piggymetrics.account.domain.Saving.setDeposit:(Ljava/lang/Boolean;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 52, - 53 - ] - }, - "com.piggymetrics.account.domain.Saving.setInterest:(Ljava/math/BigDecimal;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 44, - 45 - ] - }, - "com.piggymetrics.account.domain.TimePeriod.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 5, - 3 - ] - }, - "com.piggymetrics.account.domain.TimePeriod.:(Ljava/lang/String;I)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.account.domain.TimePeriod.valueOf:(Ljava/lang/String;)Lcom/piggymetrics/account/domain/TimePeriod;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.account.domain.TimePeriod.values:()[Lcom/piggymetrics/account/domain/TimePeriod;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.account.domain.User.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 7 - ] - }, - "com.piggymetrics.account.domain.User.getPassword:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 26 - ] - }, - "com.piggymetrics.account.domain.User.getUsername:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 18 - ] - }, - "com.piggymetrics.account.domain.User.setPassword:(Ljava/lang/String;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 30, - 31 - ] - }, - "com.piggymetrics.account.domain.User.setUsername:(Ljava/lang/String;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 22, - 23 - ] - }, - "com.piggymetrics.account.repository.AccountRepository.count:()J" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.delete:(Ljava/lang/Object;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.deleteAll:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.deleteAll:(Ljava/lang/Iterable;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.deleteById:(Ljava/lang/Object;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.existsById:(Ljava/lang/Object;)Z" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.findAll:()Ljava/lang/Iterable;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.findAllById:(Ljava/lang/Iterable;)Ljava/lang/Iterable;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.findById:(Ljava/lang/Object;)Ljava/util/Optional;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.findByName:(Ljava/lang/String;)Lcom/piggymetrics/account/domain/Account;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.save:(Ljava/lang/Object;)Ljava/lang/Object;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.repository.AccountRepository.saveAll:(Ljava/lang/Iterable;)Ljava/lang/Iterable;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.account.service.AccountService.create:(Lcom/piggymetrics/account/domain/User;)Lcom/piggymetrics/account/domain/Account;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.account.service.AccountService.findByName:(Ljava/lang/String;)Lcom/piggymetrics/account/domain/Account;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.account.service.AccountService.saveChanges:(Ljava/lang/String;Lcom/piggymetrics/account/domain/Account;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.account.service.AccountServiceImpl.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 20, - 22 - ] - }, - "com.piggymetrics.account.service.AccountServiceImpl.create:(Lcom/piggymetrics/account/domain/User;)Lcom/piggymetrics/account/domain/Account;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R013", - "lineNumbers" : [ - 48, - 49, - 51, - 53, - 54, - 55, - 56, - 57, - 58, - 60, - 61, - 62, - 63, - 65, - 67, - 69 - ] - }, - "com.piggymetrics.account.service.AccountServiceImpl.findByName:(Ljava/lang/String;)Lcom/piggymetrics/account/domain/Account;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 38, - 39 - ] - }, - "com.piggymetrics.account.service.AccountServiceImpl.saveChanges:(Ljava/lang/String;Lcom/piggymetrics/account/domain/Account;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 78, - 79, - 81, - 82, - 83, - 84, - 85, - 86, - 88, - 90, - 91 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 33 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.:(Ljava/lang/String;Ljava/lang/String;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R004", - "lineNumbers" : [ - 46, - 31, - 42, - 44, - 47, - 48, - 49 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.extractAuthentication:(Ljava/util/Map;)Lorg/springframework/security/oauth2/provider/OAuth2Authentication;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 75, - 76, - 77, - 78, - 79, - 81, - 82 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.getMap:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/Map;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 113, - 115, - 116, - 117, - 118, - 119, - 121, - 122, - 123, - 124, - 126, - 127, - 129, - 131, - 132, - 133, - 132, - 134 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.getPrincipal:(Ljava/util/Map;)Ljava/lang/Object;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 86, - 87, - 88, - 86, - 91 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.getRequest:(Ljava/util/Map;)Lorg/springframework/security/oauth2/provider/OAuth2Request;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 96, - 98, - 99, - 100, - 102 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.loadAuthentication:(Ljava/lang/String;)Lorg/springframework/security/oauth2/provider/OAuth2Authentication;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 66, - 67, - 68, - 69, - 71 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.readAccessToken:(Ljava/lang/String;)Lorg/springframework/security/oauth2/common/OAuth2AccessToken;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 108 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.setAuthoritiesExtractor:(Lorg/springframework/boot/autoconfigure/security/oauth2/resource/AuthoritiesExtractor;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R002", - "lineNumbers" : [ - 60, - 61 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.setRestTemplate:(Lorg/springframework/security/oauth2/client/OAuth2RestOperations;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R002", - "lineNumbers" : [ - 56, - 57 - ] - }, - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices.setTokenType:(Ljava/lang/String;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R002", - "lineNumbers" : [ - 52, - 53 - ] - } - } -} \ No newline at end of file diff --git a/account-service/src/main/java/com/piggymetrics/account/domain/DateAndTime.java b/account-service/src/main/java/com/piggymetrics/account/domain/DateAndTime.java new file mode 100644 index 00000000..e23be7bd --- /dev/null +++ b/account-service/src/main/java/com/piggymetrics/account/domain/DateAndTime.java @@ -0,0 +1,15 @@ +package com.piggymetrics.account.domain; + +import java.time.*; + +public class DateAndTime { + + public ZonedDateTime zonedDateTime(Clock clock) { + LocalDate ldt = LocalDate.now(clock); + LocalTime lt = LocalTime.now(clock); + ZoneId zone = ZoneId.of("America/Los_Angeles"); + ZonedDateTime zdt = ZonedDateTime.of(ldt, lt, zone); + zdt = zdt.plusDays(2).plusHours(3).plusMinutes(4).plusSeconds(5).plusNanos(6); + return zdt; + } +} diff --git a/account-service/src/main/java/com/piggymetrics/account/domain/DateFactory.java b/account-service/src/main/java/com/piggymetrics/account/domain/DateFactory.java new file mode 100644 index 00000000..210cd7d4 --- /dev/null +++ b/account-service/src/main/java/com/piggymetrics/account/domain/DateFactory.java @@ -0,0 +1,25 @@ +package com.piggymetrics.account.domain; + +import java.time.*; +import com.diffblue.cover.annotations.InterestingTestFactory; + +public class DateFactory { + + @InterestingTestFactory + public static Clock getSpecificDateForTesting() { + LocalDate ld = LocalDate.of(1965,Month.APRIL,25); + ZoneId zone = ZoneId.of("America/Los_Angeles"); + Clock clock = Clock.fixed(ld.atStartOfDay().atZone(zone).toInstant(), zone); + return clock; + } + +/* + //@InterestingTestFactory + public static Clock getAnotherSpecificDateForTesting() { + LocalDate ld = LocalDate.of(1979,Month.APRIL,27); + ZoneId zone = ZoneId.of("America/Los_Angeles"); + Clock clock = Clock.fixed(ld.atStartOfDay().atZone(zone).toInstant(), zone); + return clock; + } +*/ +} diff --git a/account-service/src/main/java/com/piggymetrics/account/domain/LicenseChecker.java b/account-service/src/main/java/com/piggymetrics/account/domain/LicenseChecker.java new file mode 100644 index 00000000..f6a6343a --- /dev/null +++ b/account-service/src/main/java/com/piggymetrics/account/domain/LicenseChecker.java @@ -0,0 +1,69 @@ +package com.piggymetrics.account.domain; + +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotNull; + +public class LicenseChecker { + + @NotNull + @Length(min = 25, max = 50) + private static String VALID_LICENSE_KEY; // License key loaded dynamically + + public static void setValidLicenseKey(String licenseKey) { + if (licenseKey == null || licenseKey.isEmpty() || licenseKey.length() < 25 || licenseKey.length() > 50) { + throw new IllegalArgumentException("Invalid license key provided. It must be between 25 and 50 characters."); + } + VALID_LICENSE_KEY = licenseKey; + } + + // Returns true if the provided license key is valid + public static boolean validateLicense(String providedLicenseKey) { + if (VALID_LICENSE_KEY == null || VALID_LICENSE_KEY.isEmpty()) { + System.err.println("VALID_LICENSE_KEY is not set. Please configure the license key before validation."); + return false; + } + if (providedLicenseKey == null || providedLicenseKey.isEmpty()) { + System.err.println("License key cannot be null or empty."); + return false; + } + return VALID_LICENSE_KEY.equals(providedLicenseKey); + } + + // Checks the license key passed as an argument + public static void runCheck(String[] args) { + if (VALID_LICENSE_KEY == null) { + System.err.println("No VALID_LICENSE_KEY has been configured. Exiting."); + System.exit(1); + } + + if (args == null || args.length == 0) { + System.err.println("No license key provided. Please provide a valid license key."); + System.exit(1); + } + + String providedLicenseKey = args[0]; + + if (!validateLicense(providedLicenseKey)) { + System.err.println("Invalid license key. Please check your license and try again."); + System.exit(1); + } + + System.out.println("License successfully validated. Proceeding with program execution..."); + } + + // Main method to demonstrate usage + public static void main(String[] args) { + try { + setValidLicenseKey("EXAMPLEKEYwjalrXUtnFEMIK7MDENGbPxRfiCY"); // Replace with actual key + } catch (IllegalArgumentException e) { + System.err.println(e.getMessage()); + System.exit(1); + } + + runCheck(args); + + // If the license check passes, the rest of the program can execute + System.out.println("Application is now running..."); + } +} diff --git a/account-service/src/main/java/com/piggymetrics/account/domain/LicenseCheckerDiffblueBase.java b/account-service/src/main/java/com/piggymetrics/account/domain/LicenseCheckerDiffblueBase.java new file mode 100644 index 00000000..205e2d5b --- /dev/null +++ b/account-service/src/main/java/com/piggymetrics/account/domain/LicenseCheckerDiffblueBase.java @@ -0,0 +1,12 @@ +package com.piggymetrics.account.domain; + +import org.junit.jupiter.api.BeforeEach; + +public class LicenseCheckerDiffblueBase { + + @BeforeEach + void setLicenseKey() { + LicenseChecker.setValidLicenseKey("12312312414fdgdfgfdgdfGbPxRfiCY"); + } + +} \ No newline at end of file diff --git a/account-service/src/main/java/com/piggymetrics/account/domain/UserFactory.java b/account-service/src/main/java/com/piggymetrics/account/domain/UserFactory.java new file mode 100644 index 00000000..e587cd17 --- /dev/null +++ b/account-service/src/main/java/com/piggymetrics/account/domain/UserFactory.java @@ -0,0 +1,25 @@ +package com.piggymetrics.account.domain; + +import com.diffblue.cover.annotations.InterestingTestFactory; + +public class UserFactory { + + @InterestingTestFactory + //Valid user creation test data + public static User createUser() { + User user = new User(); + user.setUsername("smithy"); + user.setPassword("qwertyuio123"); + return user; + } + + //@InterestingTestFactory + //Invalid user creation test data + public static User createInvalidUser() { + User user = new User(); + user.setPassword("abc"); + user.setUsername("qaz"); + return user; + } + +} diff --git a/account-service/src/main/java/com/piggymetrics/account/domain/UserValidator.java b/account-service/src/main/java/com/piggymetrics/account/domain/UserValidator.java new file mode 100644 index 00000000..49a73ee2 --- /dev/null +++ b/account-service/src/main/java/com/piggymetrics/account/domain/UserValidator.java @@ -0,0 +1,48 @@ +package com.piggymetrics.account.domain; + +import com.diffblue.cover.annotations.InTestsUseStrings; + +public class UserValidator { + + public static boolean validate(User user) { + if (user == null) { + throw new IllegalArgumentException("User cannot be null"); + } + + boolean isUsernameValid = validateUsername(user.getUsername()); + boolean isPasswordValid = validatePassword(user.getPassword()); + + if (!isUsernameValid || !isPasswordValid) { + throw new IllegalArgumentException("Credentials Invalid"); + } + + if (!isUsernameValid && !isPasswordValid) { + throw new IllegalArgumentException("Credentials Invalid"); + } + + return true; + + } + + public static boolean validateUsername(String username) throws IllegalArgumentException { + /*public static boolean validateUsername( + @InTestsUseStrings({"alice123", "qa"}) String username) + throws IllegalArgumentException {*/ + if (username == null || username.length() < 3 || username.length() > 20) { + return false; + } else { + return true; + } + } + + public static boolean validatePassword(String password) throws IllegalArgumentException { + /*public static boolean validatePassword( + @InTestsUseStrings({"qwerty", "123"}) String password) + throws IllegalArgumentException {*/ + if (password == null || password.length() < 6 || password.length() > 40) { + return false; + } else { + return true; + } + } +} \ No newline at end of file diff --git a/account-service/src/main/resources/resource.properties b/account-service/src/main/resources/resource.properties new file mode 100644 index 00000000..80401386 --- /dev/null +++ b/account-service/src/main/resources/resource.properties @@ -0,0 +1,27 @@ +# Server Configuration +server.port=8080 + +# OAuth2 Security Configuration +security.oauth2.client.client-id=account-service +security.oauth2.client.client-secret=secret +security.oauth2.client.access-token-uri=http://auth-service/oauth/token +security.oauth2.client.user-authorization-uri=http://auth-service/oauth/authorize +security.oauth2.client.scope=server +security.oauth2.client.grant-type=client_credentials + +# OAuth2 Resource Server Configuration +security.oauth2.resource.user-info-uri=http://auth-service/user +security.oauth2.resource.token-info-uri=http://auth-service/oauth/check_token +security.oauth2.resource.jwt.key-uri=http://auth-service/oauth/token_key +security.oauth2.resource.id=account-service + +# Feign Client Configuration +feign.oauth2.enabled=true + +# Logging Configuration +logging.level.org.springframework.security=DEBUG +logging.level.com.piggymetrics.account=DEBUG + +# Application Specific Configuration +account.service.defaultUser=demo +account.service.api.basePath=/api/accounts diff --git a/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java b/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java deleted file mode 100644 index 393183b1..00000000 --- a/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.piggymetrics.account; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class AccountServiceApplicationTests { - - @Test - public void contextLoads() { - - } - -} diff --git a/account-service/src/test/java/com/piggymetrics/account/client/StatisticsServiceClientFallbackDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/client/StatisticsServiceClientFallbackDiffblueTest.java new file mode 100644 index 00000000..499d0452 --- /dev/null +++ b/account-service/src/test/java/com/piggymetrics/account/client/StatisticsServiceClientFallbackDiffblueTest.java @@ -0,0 +1,110 @@ +package com.piggymetrics.account.client; + +import com.piggymetrics.account.domain.Account; +import com.piggymetrics.account.domain.Currency; +import com.piggymetrics.account.domain.Saving; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.Date; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ContextConfiguration(classes = {StatisticsServiceClientFallback.class}) +@ExtendWith(SpringExtension.class) +class StatisticsServiceClientFallbackDiffblueTest { + @Autowired + private StatisticsServiceClientFallback statisticsServiceClientFallback; + + /** + * Test + * {@link StatisticsServiceClientFallback#updateStatistics(String, Account)}. + *

+ * Method under test: + * {@link StatisticsServiceClientFallback#updateStatistics(String, Account)} + */ + @Test + @DisplayName("Test updateStatistics(String, Account)") + @Disabled("TODO: Complete this test") + void testUpdateStatistics() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + Saving saving = new Saving(); + saving.setAmount(new BigDecimal("2.6")); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + saving.setInterest(new BigDecimal("2.6")); + + Account account = new Account(); + account.setExpenses(new ArrayList<>()); + account.setIncomes(new ArrayList<>()); + account.setLastSeen(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); + account.setName("Smith"); + account.setNote("Note"); + account.setSaving(saving); + + // Act + statisticsServiceClientFallback.updateStatistics("Smith", account); + } +} diff --git a/account-service/src/test/java/com/piggymetrics/account/client/StatisticsServiceClientFallbackTest.java b/account-service/src/test/java/com/piggymetrics/account/client/StatisticsServiceClientFallbackTest.java deleted file mode 100644 index 4e21343b..00000000 --- a/account-service/src/test/java/com/piggymetrics/account/client/StatisticsServiceClientFallbackTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.piggymetrics.account.client; - -import com.piggymetrics.account.domain.Account; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.rule.OutputCapture; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.hamcrest.Matchers.containsString; - -/** - * @author cdov - */ -@RunWith(SpringRunner.class) -@SpringBootTest(properties = { - "feign.hystrix.enabled=true" -}) -public class StatisticsServiceClientFallbackTest { - @Autowired - private StatisticsServiceClient statisticsServiceClient; - - @Rule - public final OutputCapture outputCapture = new OutputCapture(); - - @Before - public void setup() { - outputCapture.reset(); - } - - @Test - public void testUpdateStatisticsWithFailFallback(){ - statisticsServiceClient.updateStatistics("test", new Account()); - - outputCapture.expect(containsString("Error during update statistics for account: test")); - - } - -} - diff --git a/account-service/src/test/java/com/piggymetrics/account/config/ResourceServerConfigDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/config/ResourceServerConfigDiffblueTest.java index e36ad6a9..65bbc62c 100644 --- a/account-service/src/test/java/com/piggymetrics/account/config/ResourceServerConfigDiffblueTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/config/ResourceServerConfigDiffblueTest.java @@ -1,114 +1,740 @@ package com.piggymetrics.account.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import com.piggymetrics.account.repository.AccountRepository; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import com.piggymetrics.account.service.security.CustomUserInfoTokenServices; -import de.flapdoodle.embed.mongo.MongodExecutable; -import org.junit.Test; -import org.junit.runner.RunWith; + +import java.util.HashMap; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; -import org.springframework.http.client.InterceptingClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; import org.springframework.security.oauth2.client.OAuth2RestTemplate; import org.springframework.security.oauth2.client.http.OAuth2ErrorHandler; import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; import org.springframework.security.oauth2.common.AuthenticationScheme; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.util.DefaultUriBuilderFactory; -@SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) -public class ResourceServerConfigDiffblueTest { - @MockBean - private AccountRepository accountRepository; - - @MockBean - private MongodExecutable mongodExecutable; - - @Autowired - private ResourceServerConfig resourceServerConfig; - - @Autowired - private ResourceServerProperties resourceServerProperties; - - /** - * Test {@link ResourceServerConfig#clientCredentialsResourceDetails()}. - *

- * Method under test: - * {@link ResourceServerConfig#clientCredentialsResourceDetails()} - */ - @Test - public void testClientCredentialsResourceDetails() { - // Arrange and Act - ClientCredentialsResourceDetails actualClientCredentialsResourceDetailsResult = resourceServerConfig - .clientCredentialsResourceDetails(); - - // Assert - assertEquals("access_token", actualClientCredentialsResourceDetailsResult.getTokenName()); - assertEquals("client_credentials", actualClientCredentialsResourceDetailsResult.getGrantType()); - assertNull(actualClientCredentialsResourceDetailsResult.getAccessTokenUri()); - assertNull(actualClientCredentialsResourceDetailsResult.getClientId()); - assertNull(actualClientCredentialsResourceDetailsResult.getClientSecret()); - assertNull(actualClientCredentialsResourceDetailsResult.getId()); - assertNull(actualClientCredentialsResourceDetailsResult.getScope()); - assertEquals(AuthenticationScheme.header, actualClientCredentialsResourceDetailsResult.getAuthenticationScheme()); - assertEquals(AuthenticationScheme.header, - actualClientCredentialsResourceDetailsResult.getClientAuthenticationScheme()); - assertFalse(actualClientCredentialsResourceDetailsResult.isAuthenticationRequired()); - assertFalse(actualClientCredentialsResourceDetailsResult.isScoped()); - assertTrue(actualClientCredentialsResourceDetailsResult.isClientOnly()); - } - - /** - * Test {@link ResourceServerConfig#oauth2FeignRequestInterceptor()}. - *

- * Method under test: - * {@link ResourceServerConfig#oauth2FeignRequestInterceptor()} - */ - @Test - public void testOauth2FeignRequestInterceptor() { - // Arrange, Act and Assert - assertTrue(resourceServerConfig.oauth2FeignRequestInterceptor() instanceof OAuth2FeignRequestInterceptor); - } - - /** - * Test {@link ResourceServerConfig#clientCredentialsRestTemplate()}. - *

- * Method under test: - * {@link ResourceServerConfig#clientCredentialsRestTemplate()} - */ - @Test - public void testClientCredentialsRestTemplate() { - // Arrange and Act - OAuth2RestTemplate actualClientCredentialsRestTemplateResult = resourceServerConfig.clientCredentialsRestTemplate(); - - // Assert - assertTrue( - actualClientCredentialsRestTemplateResult.getRequestFactory() instanceof InterceptingClientHttpRequestFactory); - assertTrue( - actualClientCredentialsRestTemplateResult.getOAuth2ClientContext() instanceof DefaultOAuth2ClientContext); - assertTrue(actualClientCredentialsRestTemplateResult.getErrorHandler() instanceof OAuth2ErrorHandler); - assertTrue(actualClientCredentialsRestTemplateResult.getResource() instanceof ClientCredentialsResourceDetails); - assertTrue(actualClientCredentialsRestTemplateResult.getUriTemplateHandler() instanceof DefaultUriBuilderFactory); - assertEquals(1, actualClientCredentialsRestTemplateResult.getInterceptors().size()); - assertEquals(7, actualClientCredentialsRestTemplateResult.getMessageConverters().size()); - } - - /** - * Test {@link ResourceServerConfig#tokenServices()}. - *

- * Method under test: {@link ResourceServerConfig#tokenServices()} - */ - @Test - public void testTokenServices() { - // Arrange, Act and Assert - assertTrue(resourceServerConfig.tokenServices() instanceof CustomUserInfoTokenServices); - } +@ContextConfiguration(classes = {ResourceServerConfig.class, ResourceServerProperties.class}) +@ExtendWith(SpringExtension.class) +class ResourceServerConfigDiffblueTest { + @Autowired + private ResourceServerConfig resourceServerConfig; + + @Autowired + private ResourceServerProperties resourceServerProperties; + + /** + * Test {@link ResourceServerConfig#clientCredentialsResourceDetails()}. + *

+ * Method under test: + * {@link ResourceServerConfig#clientCredentialsResourceDetails()} + */ + @Test + @DisplayName("Test clientCredentialsResourceDetails()") + @Tag("MaintainedByDiffblue") + void testClientCredentialsResourceDetails() { + // Diffblue Cover was unable to create a Spring-specific test for this Spring method. + // Run dcover create --keep-partial-tests to gain insights into why + // a non-Spring test was created. + + // Arrange and Act + ClientCredentialsResourceDetails actualClientCredentialsResourceDetailsResult = (new ResourceServerConfig( + new ResourceServerProperties())).clientCredentialsResourceDetails(); + + // Assert + assertEquals("access_token", actualClientCredentialsResourceDetailsResult.getTokenName()); + assertEquals("client_credentials", actualClientCredentialsResourceDetailsResult.getGrantType()); + assertNull(actualClientCredentialsResourceDetailsResult.getAccessTokenUri()); + assertNull(actualClientCredentialsResourceDetailsResult.getClientId()); + assertNull(actualClientCredentialsResourceDetailsResult.getClientSecret()); + assertNull(actualClientCredentialsResourceDetailsResult.getId()); + assertNull(actualClientCredentialsResourceDetailsResult.getScope()); + assertEquals(AuthenticationScheme.header, actualClientCredentialsResourceDetailsResult.getAuthenticationScheme()); + assertEquals(AuthenticationScheme.header, + actualClientCredentialsResourceDetailsResult.getClientAuthenticationScheme()); + assertFalse(actualClientCredentialsResourceDetailsResult.isAuthenticationRequired()); + assertFalse(actualClientCredentialsResourceDetailsResult.isScoped()); + assertTrue(actualClientCredentialsResourceDetailsResult.isClientOnly()); + } + + /** + * Test {@link ResourceServerConfig#clientCredentialsResourceDetails()}. + *

+ * Method under test: + * {@link ResourceServerConfig#clientCredentialsResourceDetails()} + */ + @Test + @DisplayName("Test clientCredentialsResourceDetails()") + @Disabled("TODO: Complete this test") + @Tag("MaintainedByDiffblue") + void testClientCredentialsResourceDetails2() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // java.lang.IllegalStateException: Failed to load ApplicationContext + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.IllegalStateException: Cannot load configuration class: com.piggymetrics.account.config.ResourceServerConfig + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:414) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.ExceptionInInitializerError + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @25825f8c + // at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464) + // at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) + // at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) + // at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) + // at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) + // at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) + // at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) + // at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:174) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:153) + // at org.springframework.cglib.proxy.Enhancer.(Enhancer.java:73) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @25825f8c + // at org.springframework.cglib.core.ReflectUtils$1.run(ReflectUtils.java:61) + // at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) + // at org.springframework.cglib.core.ReflectUtils.(ReflectUtils.java:52) + // at org.springframework.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:243) + // at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) + // at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) + // at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) + // at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) + // at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) + // at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) + // at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) + // at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:174) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:153) + // at org.springframework.cglib.proxy.Enhancer.(Enhancer.java:73) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // To avoid this error, consider adding a custom base class to setup static + // mocking for java.lang.reflect.AccessibleObject. + // For details on how to set up a custom base class, please follow this link: + // https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + resourceServerConfig.clientCredentialsResourceDetails(); + } + + /** + * Test {@link ResourceServerConfig#oauth2FeignRequestInterceptor()}. + *

+ * Method under test: + * {@link ResourceServerConfig#oauth2FeignRequestInterceptor()} + */ + @Test + @DisplayName("Test oauth2FeignRequestInterceptor()") + @Disabled("TODO: Complete this test") + @Tag("MaintainedByDiffblue") + void testOauth2FeignRequestInterceptor() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // java.lang.IllegalStateException: Failed to load ApplicationContext + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.IllegalStateException: Cannot load configuration class: com.piggymetrics.account.config.ResourceServerConfig + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:414) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.NoClassDefFoundError: Could not initialize class org.springframework.cglib.proxy.Enhancer + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.ExceptionInInitializerError: Exception org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @25825f8c [in thread "TimedExecutor-9"] + // at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464) + // at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) + // at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) + // at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) + // at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) + // at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) + // at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) + // at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:174) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:153) + // at org.springframework.cglib.proxy.Enhancer.(Enhancer.java:73) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // To avoid this error, consider adding a custom base class to setup static + // mocking for org.springframework.cglib.core.ReflectUtils. + // For details on how to set up a custom base class, please follow this link: + // https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + resourceServerConfig.oauth2FeignRequestInterceptor(); + } + + /** + * Test {@link ResourceServerConfig#clientCredentialsRestTemplate()}. + *

+ * Method under test: + * {@link ResourceServerConfig#clientCredentialsRestTemplate()} + */ + @Test + @DisplayName("Test clientCredentialsRestTemplate()") + @Disabled("TODO: Complete this test") + @Tag("MaintainedByDiffblue") + void testClientCredentialsRestTemplate() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // java.lang.IllegalStateException: Failed to load ApplicationContext + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.IllegalStateException: Cannot load configuration class: com.piggymetrics.account.config.ResourceServerConfig + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:414) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.NoClassDefFoundError: Could not initialize class org.springframework.cglib.proxy.Enhancer + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.ExceptionInInitializerError: Exception org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @25825f8c [in thread "TimedExecutor-9"] + // at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464) + // at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) + // at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) + // at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) + // at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) + // at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) + // at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) + // at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:174) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:153) + // at org.springframework.cglib.proxy.Enhancer.(Enhancer.java:73) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // To avoid this error, consider adding a custom base class to setup static + // mocking for org.springframework.cglib.core.ReflectUtils. + // For details on how to set up a custom base class, please follow this link: + // https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + resourceServerConfig.clientCredentialsRestTemplate(); + } + + /** + * Test {@link ResourceServerConfig#clientCredentialsRestTemplate()}. + *

+ * Method under test: + * {@link ResourceServerConfig#clientCredentialsRestTemplate()} + */ + @Test + @DisplayName("Test clientCredentialsRestTemplate()") + @Tag("MaintainedByDiffblue") + void testClientCredentialsRestTemplate2() { + // Diffblue Cover was unable to create a Spring-specific test for this Spring method. + // Run dcover create --keep-partial-tests to gain insights into why + // a non-Spring test was created. + + // Arrange and Act + OAuth2RestTemplate actualClientCredentialsRestTemplateResult = (new ResourceServerConfig( + new ResourceServerProperties())).clientCredentialsRestTemplate(); + + // Assert + assertTrue(actualClientCredentialsRestTemplateResult.getRequestFactory() instanceof SimpleClientHttpRequestFactory); + assertTrue( + actualClientCredentialsRestTemplateResult.getOAuth2ClientContext() instanceof DefaultOAuth2ClientContext); + assertTrue(actualClientCredentialsRestTemplateResult.getErrorHandler() instanceof OAuth2ErrorHandler); + assertTrue(actualClientCredentialsRestTemplateResult.getResource() instanceof ClientCredentialsResourceDetails); + assertTrue(actualClientCredentialsRestTemplateResult.getUriTemplateHandler() instanceof DefaultUriBuilderFactory); + assertEquals(6, actualClientCredentialsRestTemplateResult.getMessageConverters().size()); + assertTrue(actualClientCredentialsRestTemplateResult.getInterceptors().isEmpty()); + } + + /** + * Test {@link ResourceServerConfig#tokenServices()}. + *

+ * Method under test: {@link ResourceServerConfig#tokenServices()} + */ + @Test + @DisplayName("Test tokenServices()") + @Disabled("TODO: Complete this test") + @Tag("MaintainedByDiffblue") + void testTokenServices() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // java.lang.IllegalStateException: Failed to load ApplicationContext + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.IllegalStateException: Cannot load configuration class: com.piggymetrics.account.config.ResourceServerConfig + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:414) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.NoClassDefFoundError: Could not initialize class org.springframework.cglib.proxy.Enhancer + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.ExceptionInInitializerError: Exception org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @25825f8c [in thread "TimedExecutor-9"] + // at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464) + // at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) + // at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) + // at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) + // at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) + // at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) + // at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) + // at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:174) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:153) + // at org.springframework.cglib.proxy.Enhancer.(Enhancer.java:73) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // To avoid this error, consider adding a custom base class to setup static + // mocking for org.springframework.cglib.core.ReflectUtils. + // For details on how to set up a custom base class, please follow this link: + // https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + resourceServerConfig.tokenServices(); + } + + /** + * Test {@link ResourceServerConfig#tokenServices()}. + *

    + *
  • Then return {@link CustomUserInfoTokenServices}.
  • + *
+ *

+ * Method under test: {@link ResourceServerConfig#tokenServices()} + */ + @Test + @DisplayName("Test tokenServices(); then return CustomUserInfoTokenServices") + @Tag("MaintainedByDiffblue") + void testTokenServices_thenReturnCustomUserInfoTokenServices() { + // Diffblue Cover was unable to create a Spring-specific test for this Spring method. + // Run dcover create --keep-partial-tests to gain insights into why + // a non-Spring test was created. + + // Arrange, Act and Assert + assertTrue((new ResourceServerConfig(new ResourceServerProperties())) + .tokenServices() instanceof CustomUserInfoTokenServices); + } + + /** + * Test {@link ResourceServerConfig#configure(HttpSecurity)} with {@code http}. + *

+ * Method under test: {@link ResourceServerConfig#configure(HttpSecurity)} + */ + @Test + @DisplayName("Test configure(HttpSecurity) with 'http'") + @Disabled("TODO: Complete this test") + @Tag("MaintainedByDiffblue") + void testConfigureWithHttp() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // java.lang.IllegalStateException: Failed to load ApplicationContext + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.IllegalStateException: Cannot load configuration class: com.piggymetrics.account.config.ResourceServerConfig + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:414) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.NoClassDefFoundError: Could not initialize class org.springframework.cglib.proxy.Enhancer + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // java.lang.ExceptionInInitializerError: Exception org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @25825f8c [in thread "TimedExecutor-9"] + // at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464) + // at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) + // at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) + // at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) + // at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) + // at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) + // at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) + // at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) + // at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:174) + // at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:153) + // at org.springframework.cglib.proxy.Enhancer.(Enhancer.java:73) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) + // at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:128) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) + // To avoid this error, consider adding a custom base class to setup static + // mocking for org.springframework.cglib.core.ReflectUtils. + // For details on how to set up a custom base class, please follow this link: + // https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + AuthenticationManagerBuilder authenticationBuilder = new AuthenticationManagerBuilder(null); + + // Act + resourceServerConfig.configure(new HttpSecurity(null, authenticationBuilder, new HashMap<>())); + } } diff --git a/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerDiffblueTest.java index 79901541..03472a7c 100644 --- a/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerDiffblueTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerDiffblueTest.java @@ -1,198 +1,598 @@ package com.piggymetrics.account.controller; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.ObjectMapper; import com.piggymetrics.account.domain.Account; import com.piggymetrics.account.domain.Currency; import com.piggymetrics.account.domain.Saving; import com.piggymetrics.account.domain.User; +import com.piggymetrics.account.domain.UserFactory; import com.piggymetrics.account.service.AccountService; -import com.sun.security.auth.UserPrincipal; + import java.math.BigDecimal; + import java.security.Principal; import java.time.LocalDate; import java.time.ZoneOffset; import java.util.ArrayList; import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @ContextConfiguration(classes = {AccountController.class}) -@RunWith(SpringJUnit4ClassRunner.class) -public class AccountControllerDiffblueTest { - @Autowired - private AccountController accountController; - - @MockBean - private AccountService accountService; - - /** - * Test {@link AccountController#getAccountByName(String)}. - *

- * Method under test: {@link AccountController#getAccountByName(String)} - */ - @Test - public void testGetAccountByName() throws Exception { - // Arrange - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - - Account account = new Account(); - account.setExpenses(new ArrayList<>()); - account.setIncomes(new ArrayList<>()); - account.setLastSeen(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); - account.setName("Name"); - account.setNote("Note"); - account.setSaving(saving); - when(accountService.findByName(Mockito.any())).thenReturn(account); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/{name}", "Name"); - - // Act and Assert - MockMvcBuilders.standaloneSetup(accountController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"name\":\"Name\",\"lastSeen\":0,\"incomes\":[],\"expenses\":[],\"saving\":{\"amount\":2.3,\"currency\":\"USD\",\"interest" - + "\":2.3,\"deposit\":true,\"capitalization\":true},\"note\":\"Note\"}")); - } - - /** - * Test {@link AccountController#getCurrentAccount(Principal)}. - *

- * Method under test: {@link AccountController#getCurrentAccount(Principal)} - */ - @Test - public void testGetCurrentAccount() throws Exception { - // Arrange - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - - Account account = new Account(); - account.setExpenses(new ArrayList<>()); - account.setIncomes(new ArrayList<>()); - account.setLastSeen(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); - account.setName("Name"); - account.setNote("Note"); - account.setSaving(saving); - when(accountService.findByName(Mockito.any())).thenReturn(account); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/current"); - requestBuilder.principal(new UserPrincipal("principal")); - - // Act and Assert - MockMvcBuilders.standaloneSetup(accountController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"name\":\"Name\",\"lastSeen\":0,\"incomes\":[],\"expenses\":[],\"saving\":{\"amount\":2.3,\"currency\":\"USD\",\"interest" - + "\":2.3,\"deposit\":true,\"capitalization\":true},\"note\":\"Note\"}")); - } - - /** - * Test {@link AccountController#saveCurrentAccount(Principal, Account)}. - *

- * Method under test: - * {@link AccountController#saveCurrentAccount(Principal, Account)} - */ - @Test - public void testSaveCurrentAccount() throws Exception { - // Arrange - doNothing().when(accountService).saveChanges(Mockito.any(), Mockito.any()); - MockHttpServletRequestBuilder putResult = MockMvcRequestBuilders.put("/current"); - putResult.principal(new UserPrincipal("principal")); - java.sql.Date lastSeen = mock(java.sql.Date.class); - when(lastSeen.getTime()).thenReturn(10L); - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - - Account account = new Account(); - account.setExpenses(new ArrayList<>()); - account.setIncomes(new ArrayList<>()); - account.setLastSeen(lastSeen); - account.setName("Name"); - account.setNote("Note"); - account.setSaving(saving); - String content = (new ObjectMapper()).writeValueAsString(account); - MockHttpServletRequestBuilder requestBuilder = putResult.contentType(MediaType.APPLICATION_JSON).content(content); - - // Act and Assert - MockMvcBuilders.standaloneSetup(accountController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()); - } - - /** - * Test {@link AccountController#createNewAccount(User)}. - *

- * Method under test: {@link AccountController#createNewAccount(User)} - */ - @Test - public void testCreateNewAccount() throws Exception { - // Arrange - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - - Account account = new Account(); - account.setExpenses(new ArrayList<>()); - account.setIncomes(new ArrayList<>()); - account.setLastSeen(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); - account.setName("Name"); - account.setNote("Note"); - account.setSaving(saving); - when(accountService.create(Mockito.any())).thenReturn(account); - - User user = new User(); - user.setPassword("iloveyou"); - user.setUsername("janedoe"); - String content = (new ObjectMapper()).writeValueAsString(user); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/") - .contentType(MediaType.APPLICATION_JSON) - .content(content); - - // Act and Assert - MockMvcBuilders.standaloneSetup(accountController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"name\":\"Name\",\"lastSeen\":0,\"incomes\":[],\"expenses\":[],\"saving\":{\"amount\":2.3,\"currency\":\"USD\",\"interest" - + "\":2.3,\"deposit\":true,\"capitalization\":true},\"note\":\"Note\"}")); - } +@ExtendWith(SpringExtension.class) +class AccountControllerDiffblueTest { + @MockBean + private AccountService accountService; + + @Autowired + private AccountController accountController; + + /** + * Test {@link AccountController#createNewAccount(User)}. + *

+ * Method under test: {@link AccountController#createNewAccount(User)} + */ + @Test + @DisplayName("Test createNewAccount(User)") + @Disabled("TODO: Complete this test") + @Tag("MaintainedByDiffblue") + void testCreateNewAccount() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // java.lang.IllegalStateException: Failed to load ApplicationContext + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // org.mockito.exceptions.base.MockitoException: + // Mockito cannot mock this class: interface com.piggymetrics.account.service.AccountService. + // Mockito can only mock non-private & non-final classes. + // If you're not sure why you're getting this error, please report to the mailing list. + // Java : 17 + // JVM vendor name : Oracle Corporation + // JVM vendor version : 17.0.11+7-LTS-207 + // JVM name : Java HotSpot(TM) 64-Bit Server VM + // JVM version : 17.0.11+7-LTS-207 + // JVM info : mixed mode, sharing + // OS name : Windows 11 + // OS version : 10.0 + // Underlying exception : java.lang.UnsupportedOperationException: Cannot define class using reflection + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // java.lang.UnsupportedOperationException: Cannot define class using reflection + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Unavailable.defineClass(ClassInjector.java:821) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.inject(ClassInjector.java:185) + // at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:187) + // at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79) + // at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457) + // at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:121) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65) + // at org.mockito.Mockito.mock(Mockito.java:1855) + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // com.diffblue.cover.sandbox.execution.ForbiddenByPolicyException: Sandboxing policy violation + // at java.base/java.lang.Class.forName0(Native Method) + // at java.base/java.lang.Class.forName(Class.java:375) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Indirect.make(ClassInjector.java:640) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:302) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:290) + // at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.(ClassInjector.java:70) + // at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:184) + // at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79) + // at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457) + // at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:121) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65) + // at org.mockito.Mockito.mock(Mockito.java:1855) + // at org.mockito.Mockito.mock(Mockito.java:1768) + // com.diffblue.cover.exception.BaseException: Sandboxing policy violation + // at java.base/java.lang.Class.forName0(Native Method) + // at java.base/java.lang.Class.forName(Class.java:375) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Indirect.make(ClassInjector.java:640) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:302) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:290) + // at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.(ClassInjector.java:70) + // at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:184) + // at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79) + // at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457) + // at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:121) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65) + // at org.mockito.Mockito.mock(Mockito.java:1855) + // at org.mockito.Mockito.mock(Mockito.java:1768) + // To avoid this error, consider adding a custom base class to setup static + // mocking for java.lang.ClassLoader. + // For details on how to set up a custom base class, please follow this link: + // https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + MockHttpServletRequestBuilder contentTypeResult = MockMvcRequestBuilders.post("/") + .contentType(MediaType.APPLICATION_JSON); + + ObjectMapper objectMapper = new ObjectMapper(); + MockHttpServletRequestBuilder requestBuilder = contentTypeResult + .content(objectMapper.writeValueAsString(UserFactory.createUser())); + + // Act + MockMvcBuilders.standaloneSetup(accountController).build().perform(requestBuilder); + } + + /** + * Test {@link AccountController#saveCurrentAccount(Principal, Account)}. + *

+ * Method under test: + * {@link AccountController#saveCurrentAccount(Principal, Account)} + */ + @Test + @DisplayName("Test saveCurrentAccount(Principal, Account)") + @Disabled("TODO: Complete this test") + @Tag("MaintainedByDiffblue") + void testSaveCurrentAccount() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // java.lang.IllegalStateException: Failed to load ApplicationContext + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // org.mockito.exceptions.base.MockitoException: + // Mockito cannot mock this class: interface com.piggymetrics.account.service.AccountService. + // Mockito can only mock non-private & non-final classes. + // If you're not sure why you're getting this error, please report to the mailing list. + // Java : 17 + // JVM vendor name : Oracle Corporation + // JVM vendor version : 17.0.11+7-LTS-207 + // JVM name : Java HotSpot(TM) 64-Bit Server VM + // JVM version : 17.0.11+7-LTS-207 + // JVM info : mixed mode, sharing + // OS name : Windows 11 + // OS version : 10.0 + // Underlying exception : java.lang.IllegalArgumentException: Could not create type + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // java.lang.IllegalArgumentException: Could not create type + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:140) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:40) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:77) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:43) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:42) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:53) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:96) + // at org.mockito.Mockito.mock(Mockito.java:1954) + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // java.lang.NoSuchMethodError: 'net.bytebuddy.dynamic.loading.MultipleParentClassLoader$Builder net.bytebuddy.dynamic.loading.MultipleParentClassLoader$Builder.appendMostSpecific(java.lang.Class[])' + // at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:134) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.lambda$mockClass$0(TypeCachingBytecodeGenerator.java:47) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:40) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:77) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:43) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:42) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:53) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:96) + // at org.mockito.Mockito.mock(Mockito.java:1954) + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // To avoid this error, consider adding a custom base class to setup static + // mocking for org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator. + // For details on how to set up a custom base class, please follow this link: + // https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + Saving saving = new Saving(); + saving.setAmount(new BigDecimal("2.6")); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + saving.setInterest(new BigDecimal("2.6")); + + Account account = new Account(); + account.setExpenses(new ArrayList<>()); + account.setIncomes(new ArrayList<>()); + account.setLastSeen(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); + account.setName("Smith"); + account.setNote("Note"); + account.setSaving(saving); + String content = (new ObjectMapper()).writeValueAsString(account); + MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/current") + .contentType(MediaType.APPLICATION_JSON) + .content(content); + + // Act + MockMvcBuilders.standaloneSetup(accountController).build().perform(requestBuilder); + } + + /** + * Test {@link AccountController#getCurrentAccount(Principal)}. + *

+ * Method under test: {@link AccountController#getCurrentAccount(Principal)} + */ + @Test + @DisplayName("Test getCurrentAccount(Principal)") + @Disabled("TODO: Complete this test") + @Tag("MaintainedByDiffblue") + void testGetCurrentAccount() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // java.lang.IllegalStateException: Failed to load ApplicationContext + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // org.mockito.exceptions.base.MockitoException: + // Mockito cannot mock this class: interface com.piggymetrics.account.service.AccountService. + // Mockito can only mock non-private & non-final classes. + // If you're not sure why you're getting this error, please report to the mailing list. + // Java : 17 + // JVM vendor name : Oracle Corporation + // JVM vendor version : 17.0.11+7-LTS-207 + // JVM name : Java HotSpot(TM) 64-Bit Server VM + // JVM version : 17.0.11+7-LTS-207 + // JVM info : mixed mode, sharing + // OS name : Windows 11 + // OS version : 10.0 + // Underlying exception : java.lang.IllegalArgumentException: Could not create type + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // java.lang.IllegalArgumentException: Could not create type + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:140) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:40) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:77) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:43) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:42) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:53) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:96) + // at org.mockito.Mockito.mock(Mockito.java:1954) + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // java.lang.NoSuchMethodError: 'net.bytebuddy.dynamic.loading.MultipleParentClassLoader$Builder net.bytebuddy.dynamic.loading.MultipleParentClassLoader$Builder.appendMostSpecific(java.lang.Class[])' + // at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:134) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.lambda$mockClass$0(TypeCachingBytecodeGenerator.java:47) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:40) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:77) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:43) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:42) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:53) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:96) + // at org.mockito.Mockito.mock(Mockito.java:1954) + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // To avoid this error, consider adding a custom base class to setup static + // mocking for org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator. + // For details on how to set up a custom base class, please follow this link: + // https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/current"); + + // Act + MockMvcBuilders.standaloneSetup(accountController).build().perform(requestBuilder); + } + + /** + * Test {@link AccountController#getAccountByName(String)}. + *

+ * Method under test: {@link AccountController#getAccountByName(String)} + */ + @Test + @DisplayName("Test getAccountByName(String)") + @Disabled("TODO: Complete this test") + @Tag("MaintainedByDiffblue") + void testGetAccountByName() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // java.lang.IllegalStateException: Failed to load ApplicationContext + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // org.mockito.exceptions.base.MockitoException: + // Mockito cannot mock this class: interface com.piggymetrics.account.service.AccountService. + // Mockito can only mock non-private & non-final classes. + // If you're not sure why you're getting this error, please report to the mailing list. + // Java : 17 + // JVM vendor name : Oracle Corporation + // JVM vendor version : 17.0.11+7-LTS-207 + // JVM name : Java HotSpot(TM) 64-Bit Server VM + // JVM version : 17.0.11+7-LTS-207 + // JVM info : mixed mode, sharing + // OS name : Windows 11 + // OS version : 10.0 + // Underlying exception : java.lang.UnsupportedOperationException: Cannot define class using reflection + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // java.lang.UnsupportedOperationException: Cannot define class using reflection + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Unavailable.defineClass(ClassInjector.java:821) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.inject(ClassInjector.java:185) + // at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:187) + // at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79) + // at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457) + // at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:121) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65) + // at org.mockito.Mockito.mock(Mockito.java:1855) + // at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:157) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createMock(MockitoPostProcessor.java:222) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.registerMock(MockitoPostProcessor.java:192) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.register(MockitoPostProcessor.java:174) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:144) + // at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.postProcessBeanFactory(MockitoPostProcessor.java:131) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:172) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) + // com.diffblue.cover.sandbox.execution.ForbiddenByPolicyException: Sandboxing policy violation + // at java.base/java.lang.Class.forName0(Native Method) + // at java.base/java.lang.Class.forName(Class.java:375) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Indirect.make(ClassInjector.java:640) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:302) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:290) + // at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.(ClassInjector.java:70) + // at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:184) + // at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79) + // at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457) + // at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:121) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65) + // at org.mockito.Mockito.mock(Mockito.java:1855) + // at org.mockito.Mockito.mock(Mockito.java:1768) + // com.diffblue.cover.exception.BaseException: Sandboxing policy violation + // at java.base/java.lang.Class.forName0(Native Method) + // at java.base/java.lang.Class.forName(Class.java:375) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Indirect.make(ClassInjector.java:640) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:302) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:290) + // at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) + // at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.(ClassInjector.java:70) + // at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:184) + // at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79) + // at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4457) + // at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:121) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) + // at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) + // at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) + // at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71) + // at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42) + // at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25) + // at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35) + // at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65) + // at org.mockito.Mockito.mock(Mockito.java:1855) + // at org.mockito.Mockito.mock(Mockito.java:1768) + // To avoid this error, consider adding a custom base class to setup static + // mocking for java.lang.ClassLoader. + // For details on how to set up a custom base class, please follow this link: + // https://docs.diffblue.com/features/cover-cli/writing-tests/custom-test-setup + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/{name}", "Smith"); + + // Act + MockMvcBuilders.standaloneSetup(accountController).build().perform(requestBuilder); + } } diff --git a/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java b/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java deleted file mode 100644 index b078ea6f..00000000 --- a/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.piggymetrics.account.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.ImmutableList; -import com.piggymetrics.account.domain.*; -import com.piggymetrics.account.service.AccountService; -import com.sun.security.auth.UserPrincipal; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import java.math.BigDecimal; -import java.util.Date; - -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class AccountControllerTest { - - private static final ObjectMapper mapper = new ObjectMapper(); - - @InjectMocks - private AccountController accountController; - - @Mock - private AccountService accountService; - - private MockMvc mockMvc; - - @Before - public void setup() { - initMocks(this); - this.mockMvc = MockMvcBuilders.standaloneSetup(accountController).build(); - } - - @Test - public void shouldGetAccountByName() throws Exception { - - final Account account = new Account(); - account.setName("test"); - - when(accountService.findByName(account.getName())).thenReturn(account); - - mockMvc.perform(get("/" + account.getName())) - .andExpect(jsonPath("$.name").value(account.getName())) - .andExpect(status().isOk()); - } - - @Test - public void shouldGetCurrentAccount() throws Exception { - - final Account account = new Account(); - account.setName("test"); - - when(accountService.findByName(account.getName())).thenReturn(account); - - mockMvc.perform(get("/current").principal(new UserPrincipal(account.getName()))) - .andExpect(jsonPath("$.name").value(account.getName())) - .andExpect(status().isOk()); - } - - @Test - public void shouldSaveCurrentAccount() throws Exception { - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal(1500)); - saving.setCurrency(Currency.USD); - saving.setInterest(new BigDecimal("3.32")); - saving.setDeposit(true); - saving.setCapitalization(false); - - Item grocery = new Item(); - grocery.setTitle("Grocery"); - grocery.setAmount(new BigDecimal(10)); - grocery.setCurrency(Currency.USD); - grocery.setPeriod(TimePeriod.DAY); - grocery.setIcon("meal"); - - Item salary = new Item(); - salary.setTitle("Salary"); - salary.setAmount(new BigDecimal(9100)); - salary.setCurrency(Currency.USD); - salary.setPeriod(TimePeriod.MONTH); - salary.setIcon("wallet"); - - final Account account = new Account(); - account.setName("test"); - account.setNote("test note"); - account.setLastSeen(new Date()); - account.setSaving(saving); - account.setExpenses(ImmutableList.of(grocery)); - account.setIncomes(ImmutableList.of(salary)); - - String json = mapper.writeValueAsString(account); - - mockMvc.perform(put("/current").principal(new UserPrincipal(account.getName())).contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()); - } - - @Test - public void shouldFailOnValidationTryingToSaveCurrentAccount() throws Exception { - - final Account account = new Account(); - account.setName("test"); - - String json = mapper.writeValueAsString(account); - - mockMvc.perform(put("/current").principal(new UserPrincipal(account.getName())).contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isBadRequest()); - } - - @Test - public void shouldRegisterNewAccount() throws Exception { - - final User user = new User(); - user.setUsername("test"); - user.setPassword("password"); - - String json = mapper.writeValueAsString(user); - System.out.println(json); - mockMvc.perform(post("/").principal(new UserPrincipal("test")).contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()); - } - - @Test - public void shouldFailOnValidationTryingToRegisterNewAccount() throws Exception { - - final User user = new User(); - user.setUsername("t"); - - String json = mapper.writeValueAsString(user); - - mockMvc.perform(post("/").principal(new UserPrincipal("test")).contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isBadRequest()); - } -} diff --git a/account-service/src/test/java/com/piggymetrics/account/controller/ErrorHandlerDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/controller/ErrorHandlerDiffblueTest.java new file mode 100644 index 00000000..bf09efda --- /dev/null +++ b/account-service/src/test/java/com/piggymetrics/account/controller/ErrorHandlerDiffblueTest.java @@ -0,0 +1,28 @@ +package com.piggymetrics.account.controller; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class ErrorHandlerDiffblueTest { + /** + * Test {@link ErrorHandler#processValidationError(IllegalArgumentException)}. + *

+ * Method under test: + * {@link ErrorHandler#processValidationError(IllegalArgumentException)} + */ + @Test + @DisplayName("Test processValidationError(IllegalArgumentException)") + void testProcessValidationError() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Missing observers. + // Diffblue Cover was unable to create an assertion. + // Add getters for the following fields or make them package-private: + // ErrorHandler.log + + // Arrange + ErrorHandler errorHandler = new ErrorHandler(); + + // Act + errorHandler.processValidationError(new IllegalArgumentException("foo")); + } +} diff --git a/account-service/src/test/java/com/piggymetrics/account/domain/AccountDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/domain/AccountDiffblueTest.java index f8c2e9e1..fcdb5eae 100644 --- a/account-service/src/test/java/com/piggymetrics/account/domain/AccountDiffblueTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/domain/AccountDiffblueTest.java @@ -1,71 +1,135 @@ package com.piggymetrics.account.domain; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.math.BigDecimal; import java.time.LocalDate; import java.time.ZoneOffset; import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.junit.Test; -public class AccountDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link Account} - *
  • {@link Account#setExpenses(List)} - *
  • {@link Account#setIncomes(List)} - *
  • {@link Account#setLastSeen(Date)} - *
  • {@link Account#setName(String)} - *
  • {@link Account#setNote(String)} - *
  • {@link Account#setSaving(Saving)} - *
  • {@link Account#getExpenses()} - *
  • {@link Account#getIncomes()} - *
  • {@link Account#getLastSeen()} - *
  • {@link Account#getName()} - *
  • {@link Account#getNote()} - *
  • {@link Account#getSaving()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - Account actualAccount = new Account(); - ArrayList expenses = new ArrayList<>(); - actualAccount.setExpenses(expenses); - ArrayList incomes = new ArrayList<>(); - actualAccount.setIncomes(incomes); - Date lastSeen = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); - actualAccount.setLastSeen(lastSeen); - actualAccount.setName("Name"); - actualAccount.setNote("Note"); - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - actualAccount.setSaving(saving); - List actualExpenses = actualAccount.getExpenses(); - List actualIncomes = actualAccount.getIncomes(); - Date actualLastSeen = actualAccount.getLastSeen(); - String actualName = actualAccount.getName(); - String actualNote = actualAccount.getNote(); - Saving actualSaving = actualAccount.getSaving(); +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class AccountDiffblueTest { + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Account#setExpenses(List)} + *
  • {@link Account#setIncomes(List)} + *
  • {@link Account#setLastSeen(Date)} + *
  • {@link Account#setName(String)} + *
  • {@link Account#setNote(String)} + *
  • {@link Account#setSaving(Saving)} + *
  • {@link Account#getExpenses()} + *
  • {@link Account#getIncomes()} + *
  • {@link Account#getLastSeen()} + *
  • {@link Account#getName()} + *
  • {@link Account#getNote()} + *
  • {@link Account#getSaving()} + *
+ */ + @Test + @DisplayName("Test getters and setters") + void testGettersAndSetters() { + // Arrange + Account account = new Account(); + ArrayList expenses = new ArrayList<>(); + + // Act + account.setExpenses(expenses); + ArrayList incomes = new ArrayList<>(); + account.setIncomes(incomes); + Date lastSeen = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + account.setLastSeen(lastSeen); + account.setName("Name"); + account.setNote("Note"); + Saving saving = new Saving(); + saving.setAmount(new BigDecimal("2.4")); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + saving.setInterest(new BigDecimal("2.4")); + account.setSaving(saving); + List actualExpenses = account.getExpenses(); + List actualIncomes = account.getIncomes(); + Date actualLastSeen = account.getLastSeen(); + String actualName = account.getName(); + String actualNote = account.getNote(); + Saving actualSaving = account.getSaving(); + + // Assert + assertEquals("Name", actualName); + assertEquals("Note", actualNote); + assertTrue(actualExpenses.isEmpty()); + assertTrue(actualIncomes.isEmpty()); + assertSame(saving, actualSaving); + assertSame(expenses, actualExpenses); + assertSame(incomes, actualIncomes); + assertSame(lastSeen, actualLastSeen); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Account#setExpenses(List)} + *
  • {@link Account#setIncomes(List)} + *
  • {@link Account#setLastSeen(Date)} + *
  • {@link Account#setName(String)} + *
  • {@link Account#setNote(String)} + *
  • {@link Account#setSaving(Saving)} + *
  • {@link Account#getExpenses()} + *
  • {@link Account#getIncomes()} + *
  • {@link Account#getLastSeen()} + *
  • {@link Account#getName()} + *
  • {@link Account#getNote()} + *
  • {@link Account#getSaving()} + *
+ */ + @Test + @DisplayName("Test getters and setters") + void testGettersAndSetters2() { + // Arrange + Account account = new Account(); + ArrayList expenses = new ArrayList<>(); + + // Act + account.setExpenses(expenses); + ArrayList incomes = new ArrayList<>(); + account.setIncomes(incomes); + Date lastSeen = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + account.setLastSeen(lastSeen); + account.setName("Smith"); + account.setNote("Note"); + Saving saving = new Saving(); + saving.setAmount(new BigDecimal("2.6")); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + saving.setInterest(new BigDecimal("2.6")); + account.setSaving(saving); + List actualExpenses = account.getExpenses(); + List actualIncomes = account.getIncomes(); + Date actualLastSeen = account.getLastSeen(); + String actualName = account.getName(); + String actualNote = account.getNote(); + Saving actualSaving = account.getSaving(); - // Assert - assertEquals("Name", actualName); - assertEquals("Note", actualNote); - assertTrue(actualExpenses.isEmpty()); - assertTrue(actualIncomes.isEmpty()); - assertSame(saving, actualSaving); - assertSame(expenses, actualExpenses); - assertSame(incomes, actualIncomes); - assertSame(lastSeen, actualLastSeen); - } + // Assert + assertEquals("Note", actualNote); + assertEquals("Smith", actualName); + assertTrue(actualExpenses.isEmpty()); + assertTrue(actualIncomes.isEmpty()); + assertSame(saving, actualSaving); + assertSame(expenses, actualExpenses); + assertSame(incomes, actualIncomes); + assertSame(lastSeen, actualLastSeen); + } } diff --git a/account-service/src/test/java/com/piggymetrics/account/domain/CurrencyDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/domain/CurrencyDiffblueTest.java deleted file mode 100644 index 3d7fd6d8..00000000 --- a/account-service/src/test/java/com/piggymetrics/account/domain/CurrencyDiffblueTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.piggymetrics.account.domain; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; - -public class CurrencyDiffblueTest { - /** - * Test {@link Currency#getDefault()}. - *

- * Method under test: {@link Currency#getDefault()} - */ - @Test - public void testGetDefault() { - // Arrange, Act and Assert - assertEquals(Currency.USD, Currency.valueOf("USD").getDefault()); - } -} diff --git a/account-service/src/test/java/com/piggymetrics/account/domain/DateAndTimeDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/domain/DateAndTimeDiffblueTest.java new file mode 100644 index 00000000..f578630f --- /dev/null +++ b/account-service/src/test/java/com/piggymetrics/account/domain/DateAndTimeDiffblueTest.java @@ -0,0 +1,39 @@ +package com.piggymetrics.account.domain; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.time.Clock; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class DateAndTimeDiffblueTest { + + /** + * Test {@link DateAndTime#zonedDateTime(Clock)}. + *

    + *
  • Then return toLocalDateTime toLocalTime toString is + * {@code 03:04:05.000000006}.
  • + *
+ *

+ * Method under test: {@link DateAndTime#zonedDateTime(Clock)} + */ + @Test + @DisplayName("Test zonedDateTime(Clock); then return toLocalDateTime toLocalTime toString is '03:04:05.000000006'") + void testZonedDateTime_thenReturnToLocalDateTimeToLocalTimeToStringIs030405000000006() { + // Arrange + DateAndTime dateAndTime = new DateAndTime(); + + // Act + ZonedDateTime actualZonedDateTimeResult = dateAndTime.zonedDateTime(DateFactory.getSpecificDateForTesting()); + + // Assert + LocalDateTime toLocalDateTimeResult = actualZonedDateTimeResult.toLocalDateTime(); + assertEquals("03:04:05.000000006", toLocalDateTimeResult.toLocalTime().toString()); + assertEquals("1965-04-27", toLocalDateTimeResult.toLocalDate().toString()); + assertEquals("America/Los_Angeles", actualZonedDateTimeResult.getZone().toString()); + } + +} diff --git a/account-service/src/test/java/com/piggymetrics/account/domain/ItemDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/domain/ItemDiffblueTest.java index 948a3208..73b491e3 100644 --- a/account-service/src/test/java/com/piggymetrics/account/domain/ItemDiffblueTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/domain/ItemDiffblueTest.java @@ -1,50 +1,99 @@ package com.piggymetrics.account.domain; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + import java.math.BigDecimal; -import org.junit.Test; - -public class ItemDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link Item} - *
  • {@link Item#setAmount(BigDecimal)} - *
  • {@link Item#setCurrency(Currency)} - *
  • {@link Item#setIcon(String)} - *
  • {@link Item#setPeriod(TimePeriod)} - *
  • {@link Item#setTitle(String)} - *
  • {@link Item#getAmount()} - *
  • {@link Item#getCurrency()} - *
  • {@link Item#getIcon()} - *
  • {@link Item#getPeriod()} - *
  • {@link Item#getTitle()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - Item actualItem = new Item(); - BigDecimal amount = new BigDecimal("2.3"); - actualItem.setAmount(amount); - actualItem.setCurrency(Currency.USD); - actualItem.setIcon("Icon"); - actualItem.setPeriod(TimePeriod.YEAR); - actualItem.setTitle("Dr"); - BigDecimal actualAmount = actualItem.getAmount(); - Currency actualCurrency = actualItem.getCurrency(); - String actualIcon = actualItem.getIcon(); - TimePeriod actualPeriod = actualItem.getPeriod(); - - // Assert - assertEquals("Dr", actualItem.getTitle()); - assertEquals("Icon", actualIcon); - assertEquals(Currency.USD, actualCurrency); - assertEquals(TimePeriod.YEAR, actualPeriod); - assertEquals(new BigDecimal("2.3"), actualAmount); - assertSame(amount, actualAmount); - } + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class ItemDiffblueTest { + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Item#setAmount(BigDecimal)} + *
  • {@link Item#setCurrency(Currency)} + *
  • {@link Item#setIcon(String)} + *
  • {@link Item#setPeriod(TimePeriod)} + *
  • {@link Item#setTitle(String)} + *
  • {@link Item#getAmount()} + *
  • {@link Item#getCurrency()} + *
  • {@link Item#getIcon()} + *
  • {@link Item#getPeriod()} + *
  • {@link Item#getTitle()} + *
+ */ + @Test + @DisplayName("Test getters and setters") + void testGettersAndSetters() { + // Arrange + Item item = new Item(); + BigDecimal amount = new BigDecimal("2.6"); + + // Act + item.setAmount(amount); + item.setCurrency(Currency.USD); + item.setIcon("Icon"); + item.setPeriod(TimePeriod.YEAR); + item.setTitle("Dr"); + BigDecimal actualAmount = item.getAmount(); + Currency actualCurrency = item.getCurrency(); + String actualIcon = item.getIcon(); + TimePeriod actualPeriod = item.getPeriod(); + + // Assert + assertEquals("Dr", item.getTitle()); + assertEquals("Icon", actualIcon); + assertEquals(Currency.USD, actualCurrency); + assertEquals(TimePeriod.YEAR, actualPeriod); + assertEquals(new BigDecimal("2.6"), actualAmount); + assertSame(amount, actualAmount); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Item#setAmount(BigDecimal)} + *
  • {@link Item#setCurrency(Currency)} + *
  • {@link Item#setIcon(String)} + *
  • {@link Item#setPeriod(TimePeriod)} + *
  • {@link Item#setTitle(String)} + *
  • {@link Item#getAmount()} + *
  • {@link Item#getCurrency()} + *
  • {@link Item#getIcon()} + *
  • {@link Item#getPeriod()} + *
  • {@link Item#getTitle()} + *
+ */ + @Test + @DisplayName("Test getters and setters") + void testGettersAndSetters2() { + // Arrange + Item item = new Item(); + BigDecimal amount = new BigDecimal("2.6"); + + // Act + item.setAmount(amount); + item.setCurrency(Currency.USD); + item.setIcon("Icon"); + item.setPeriod(TimePeriod.YEAR); + item.setTitle("Mr"); + BigDecimal actualAmount = item.getAmount(); + Currency actualCurrency = item.getCurrency(); + String actualIcon = item.getIcon(); + TimePeriod actualPeriod = item.getPeriod(); + + // Assert + assertEquals("Icon", actualIcon); + assertEquals("Mr", item.getTitle()); + assertEquals(Currency.USD, actualCurrency); + assertEquals(TimePeriod.YEAR, actualPeriod); + assertEquals(new BigDecimal("2.6"), actualAmount); + assertSame(amount, actualAmount); + } } diff --git a/account-service/src/test/java/com/piggymetrics/account/domain/LicenseCheckerDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/domain/LicenseCheckerDiffblueTest.java new file mode 100644 index 00000000..1e54cf5c --- /dev/null +++ b/account-service/src/test/java/com/piggymetrics/account/domain/LicenseCheckerDiffblueTest.java @@ -0,0 +1,179 @@ +package com.piggymetrics.account.domain; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class LicenseCheckerDiffblueTest extends LicenseCheckerDiffblueBase { + /** + * Test {@link LicenseChecker#setValidLicenseKey(String)}. + *

+ * Method under test: {@link LicenseChecker#setValidLicenseKey(String)} + */ + @Test + @DisplayName("Test setValidLicenseKey(String)") + void testSetValidLicenseKey() { + // Arrange, Act and Assert + assertThrows(IllegalArgumentException.class, () -> LicenseChecker + .setValidLicenseKey("Invalid license key provided. It must be between 25 and 50 characters.")); + } + + /** + * Test {@link LicenseChecker#setValidLicenseKey(String)}. + *

    + *
  • When empty string.
  • + *
  • Then throw {@link IllegalArgumentException}.
  • + *
+ *

+ * Method under test: {@link LicenseChecker#setValidLicenseKey(String)} + */ + @Test + @DisplayName("Test setValidLicenseKey(String); when empty string; then throw IllegalArgumentException") + void testSetValidLicenseKey_whenEmptyString_thenThrowIllegalArgumentException() { + // Arrange, Act and Assert + assertThrows(IllegalArgumentException.class, () -> LicenseChecker.setValidLicenseKey("")); + } + + /** + * Test {@link LicenseChecker#setValidLicenseKey(String)}. + *

    + *
  • When {@code License Key}.
  • + *
  • Then throw {@link IllegalArgumentException}.
  • + *
+ *

+ * Method under test: {@link LicenseChecker#setValidLicenseKey(String)} + */ + @Test + @DisplayName("Test setValidLicenseKey(String); when 'License Key'; then throw IllegalArgumentException") + void testSetValidLicenseKey_whenLicenseKey_thenThrowIllegalArgumentException() { + // Arrange, Act and Assert + assertThrows(IllegalArgumentException.class, () -> LicenseChecker.setValidLicenseKey("License Key")); + } + + /** + * Test {@link LicenseChecker#setValidLicenseKey(String)}. + *

    + *
  • When {@code null}.
  • + *
  • Then throw {@link IllegalArgumentException}.
  • + *
+ *

+ * Method under test: {@link LicenseChecker#setValidLicenseKey(String)} + */ + @Test + @DisplayName("Test setValidLicenseKey(String); when 'null'; then throw IllegalArgumentException") + void testSetValidLicenseKey_whenNull_thenThrowIllegalArgumentException() { + // Arrange, Act and Assert + assertThrows(IllegalArgumentException.class, () -> LicenseChecker.setValidLicenseKey(null)); + } + + /** + * Test {@link LicenseChecker#validateLicense(String)}. + *

    + *
  • When {@code 12312312414fdgdfgfdgdfGbPxRfiCY}.
  • + *
  • Then return {@code true}.
  • + *
+ *

+ * Method under test: {@link LicenseChecker#validateLicense(String)} + */ + @Test + @DisplayName("Test validateLicense(String); when '12312312414fdgdfgfdgdfGbPxRfiCY'; then return 'true'") + void testValidateLicense_when12312312414fdgdfgfdgdfGbPxRfiCY_thenReturnTrue() { + // Arrange, Act and Assert + assertTrue(LicenseChecker.validateLicense("12312312414fdgdfgfdgdfGbPxRfiCY")); + } + + /** + * Test {@link LicenseChecker#validateLicense(String)}. + *

    + *
  • When {@code EXAMPLEKEaaabbbcccdddeeefffggggg}.
  • + *
  • Then return {@code false}.
  • + *
+ *

+ * Method under test: {@link LicenseChecker#validateLicense(String)} + */ + @Test + @DisplayName("Test validateLicense(String); when 'EXAMPLEKEaaabbbcccdddeeefffggggg'; then return 'false'") + void testValidateLicense_whenEXAMPLEKEaaabbbcccdddeeefffggggg_thenReturnFalse() { + // Arrange, Act and Assert + assertFalse(LicenseChecker.validateLicense("EXAMPLEKEaaabbbcccdddeeefffggggg")); + } + + /** + * Test {@link LicenseChecker#validateLicense(String)}. + *

    + *
  • When empty string.
  • + *
  • Then return {@code false}.
  • + *
+ *

+ * Method under test: {@link LicenseChecker#validateLicense(String)} + */ + @Test + @DisplayName("Test validateLicense(String); when empty string; then return 'false'") + void testValidateLicense_whenEmptyString_thenReturnFalse() { + // Arrange, Act and Assert + assertFalse(LicenseChecker.validateLicense("")); + } + + /** + * Test {@link LicenseChecker#validateLicense(String)}. + *

    + *
  • When {@code null}.
  • + *
  • Then return {@code false}.
  • + *
+ *

+ * Method under test: {@link LicenseChecker#validateLicense(String)} + */ + @Test + @DisplayName("Test validateLicense(String); when 'null'; then return 'false'") + void testValidateLicense_whenNull_thenReturnFalse() { + // Arrange, Act and Assert + assertFalse(LicenseChecker.validateLicense(null)); + } + + /** + * Test {@link LicenseChecker#runCheck(String[])}. + *

    + *
  • When array of {@link String} with + * {@code 12312312414fdgdfgfdgdfGbPxRfiCY}.
  • + *
+ *

+ * Method under test: {@link LicenseChecker#runCheck(String[])} + */ + @Test + @DisplayName("Test runCheck(String[]); when array of String with '12312312414fdgdfgfdgdfGbPxRfiCY'") + void testRunCheck_whenArrayOfStringWith12312312414fdgdfgfdgdfGbPxRfiCY() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Diffblue AI was unable to find a test + + // Arrange and Act + LicenseChecker.runCheck(new String[]{"12312312414fdgdfgfdgdfGbPxRfiCY"}); + } + + /** + * Test {@link LicenseChecker#runCheck(String[])}. + *

    + *
  • When array of {@link String} with {@code Args}.
  • + *
+ *

+ * Method under test: {@link LicenseChecker#runCheck(String[])} + */ + @Test + @DisplayName("Test runCheck(String[]); when array of String with 'Args'") + @Disabled("TODO: Complete this test") + void testRunCheck_whenArrayOfStringWithArgs() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Sandboxing policy violation. + // Diffblue Cover ran code in your project that tried + // to call 'System.exit'. + // Diffblue Cover's default sandboxing policy disallows this in order to prevent + // your code from damaging your system environment. + // See https://diff.blue/R011 to resolve this issue. + + // Arrange and Act + LicenseChecker.runCheck(new String[]{"Args"}); + } +} diff --git a/account-service/src/test/java/com/piggymetrics/account/domain/SavingDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/domain/SavingDiffblueTest.java index fde9973d..3822d65f 100644 --- a/account-service/src/test/java/com/piggymetrics/account/domain/SavingDiffblueTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/domain/SavingDiffblueTest.java @@ -1,54 +1,59 @@ package com.piggymetrics.account.domain; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.math.BigDecimal; -import org.junit.Test; -public class SavingDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link Saving} - *
  • {@link Saving#setAmount(BigDecimal)} - *
  • {@link Saving#setCapitalization(Boolean)} - *
  • {@link Saving#setCurrency(Currency)} - *
  • {@link Saving#setDeposit(Boolean)} - *
  • {@link Saving#setInterest(BigDecimal)} - *
  • {@link Saving#getAmount()} - *
  • {@link Saving#getCapitalization()} - *
  • {@link Saving#getCurrency()} - *
  • {@link Saving#getDeposit()} - *
  • {@link Saving#getInterest()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - Saving actualSaving = new Saving(); - BigDecimal amount = new BigDecimal("2.3"); - actualSaving.setAmount(amount); - actualSaving.setCapitalization(true); - actualSaving.setCurrency(Currency.USD); - actualSaving.setDeposit(true); - BigDecimal interest = new BigDecimal("2.3"); - actualSaving.setInterest(interest); - BigDecimal actualAmount = actualSaving.getAmount(); - Boolean actualCapitalization = actualSaving.getCapitalization(); - Currency actualCurrency = actualSaving.getCurrency(); - Boolean actualDeposit = actualSaving.getDeposit(); - BigDecimal actualInterest = actualSaving.getInterest(); +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class SavingDiffblueTest { + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Saving#setAmount(BigDecimal)} + *
  • {@link Saving#setCapitalization(Boolean)} + *
  • {@link Saving#setCurrency(Currency)} + *
  • {@link Saving#setDeposit(Boolean)} + *
  • {@link Saving#setInterest(BigDecimal)} + *
  • {@link Saving#getAmount()} + *
  • {@link Saving#getCapitalization()} + *
  • {@link Saving#getCurrency()} + *
  • {@link Saving#getDeposit()} + *
  • {@link Saving#getInterest()} + *
+ */ + @Test + @DisplayName("Test getters and setters") + void testGettersAndSetters() { + // Arrange + Saving saving = new Saving(); + BigDecimal amount = new BigDecimal("2.6"); + + // Act + saving.setAmount(amount); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + BigDecimal interest = new BigDecimal("2.6"); + saving.setInterest(interest); + BigDecimal actualAmount = saving.getAmount(); + Boolean actualCapitalization = saving.getCapitalization(); + Currency actualCurrency = saving.getCurrency(); + Boolean actualDeposit = saving.getDeposit(); + BigDecimal actualInterest = saving.getInterest(); - // Assert - assertEquals(Currency.USD, actualCurrency); - assertTrue(actualCapitalization); - assertTrue(actualDeposit); - assertEquals(new BigDecimal("2.3"), actualAmount); - assertEquals(new BigDecimal("2.3"), actualInterest); - assertSame(amount, actualAmount); - assertSame(interest, actualInterest); - } + // Assert + assertEquals(Currency.USD, actualCurrency); + assertTrue(actualCapitalization); + assertTrue(actualDeposit); + assertEquals(new BigDecimal("2.6"), actualAmount); + assertEquals(new BigDecimal("2.6"), actualInterest); + assertSame(amount, actualAmount); + assertSame(interest, actualInterest); + } } diff --git a/account-service/src/test/java/com/piggymetrics/account/domain/UserDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/domain/UserDiffblueTest.java index 2ce281bd..7cd6ed4d 100644 --- a/account-service/src/test/java/com/piggymetrics/account/domain/UserDiffblueTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/domain/UserDiffblueTest.java @@ -1,31 +1,116 @@ package com.piggymetrics.account.domain; -import static org.junit.Assert.assertEquals; -import org.junit.Test; - -public class UserDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link User} - *
  • {@link User#setPassword(String)} - *
  • {@link User#setUsername(String)} - *
  • {@link User#getPassword()} - *
  • {@link User#getUsername()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - User actualUser = new User(); - actualUser.setPassword("iloveyou"); - actualUser.setUsername("janedoe"); - String actualPassword = actualUser.getPassword(); - - // Assert - assertEquals("iloveyou", actualPassword); - assertEquals("janedoe", actualUser.getUsername()); - } +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +class UserDiffblueTest { + /** + * Test {@link User#setUsername(String)}. + *
    + *
  • When {@code qw}.
  • + *
  • Then throw {@link IllegalArgumentException}.
  • + *
+ *

+ * Method under test: {@link User#setUsername(String)} + */ + @Test + @DisplayName("Test setUsername(String); when 'qw'; then throw IllegalArgumentException") + @Tag("MaintainedByDiffblue") + void testSetUsername_whenQw_thenThrowIllegalArgumentException() { + // Arrange, Act and Assert + assertThrows(IllegalArgumentException.class, () -> (new User()).setUsername("qw")); + } + + /** + * Test {@link User#setUsername(String)}. + *

    + *
  • When {@code Smith}.
  • + *
  • Then {@link User} (default constructor) Username is {@code Smith}.
  • + *
+ *

+ * Method under test: {@link User#setUsername(String)} + */ + @Test + @DisplayName("Test setUsername(String); when 'Smith'; then User (default constructor) Username is 'Smith'") + @Tag("MaintainedByDiffblue") + void testSetUsername_whenSmith_thenUserUsernameIsSmith() { + // Arrange + User user = new User(); + + // Act + user.setUsername("Smith"); + + // Assert + assertEquals("Smith", user.getUsername()); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link User#getPassword()} + *
  • {@link User#getUsername()} + *
+ */ + @Test + @DisplayName("Test getters and setters") + @Tag("MaintainedByDiffblue") + void testGettersAndSetters() { + // Arrange + User user = new User(); + + // Act + String actualPassword = user.getPassword(); + + // Assert + assertNull(actualPassword); + assertNull(user.getUsername()); + } + + /** + * Test {@link User#setPassword(String)}. + *
    + *
  • When {@code abc}.
  • + *
  • Then throw {@link IllegalArgumentException}.
  • + *
+ *

+ * Method under test: {@link User#setPassword(String)} + */ + @Test + @DisplayName("Test setPassword(String); when 'abc'; then throw IllegalArgumentException") + @Tag("MaintainedByDiffblue") + void testSetPassword_whenAbc_thenThrowIllegalArgumentException() { + // Arrange, Act and Assert + assertThrows(IllegalArgumentException.class, () -> (new User()).setPassword("abc")); + } + + /** + * Test {@link User#setPassword(String)}. + *

    + *
  • When {@code qwertyuio}.
  • + *
  • Then {@link User} (default constructor) Password is + * {@code qwertyuio}.
  • + *
+ *

+ * Method under test: {@link User#setPassword(String)} + */ + @Test + @DisplayName("Test setPassword(String); when 'qwertyuio'; then User (default constructor) Password is 'qwertyuio'") + @Tag("MaintainedByDiffblue") + void testSetPassword_whenQwertyuio_thenUserPasswordIsQwertyuio() { + // Arrange + User user = new User(); + + // Act + user.setPassword("qwertyuio"); + + // Assert + assertEquals("qwertyuio", user.getPassword()); + } } diff --git a/account-service/src/test/java/com/piggymetrics/account/domain/UserValidatorDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/domain/UserValidatorDiffblueTest.java new file mode 100644 index 00000000..8614d08d --- /dev/null +++ b/account-service/src/test/java/com/piggymetrics/account/domain/UserValidatorDiffblueTest.java @@ -0,0 +1,257 @@ +package com.piggymetrics.account.domain; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +class UserValidatorDiffblueTest { + + /** + * Test {@link UserValidator#validate(User)}. + *

    + *
  • Given {@code null}.
  • + *
  • When createUser Username is {@code null}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validate(User)} + */ + @Test + @DisplayName("Test validate(User); given 'null'; when createUser Username is 'null'") + @Tag("MaintainedByDiffblue") + void testValidate_givenNull_whenCreateUserUsernameIsNull() { + // Arrange + User user = UserFactory.createUser(); + user.setUsername(null); + user.setPassword(null); + + // Act and Assert + assertThrows(IllegalArgumentException.class, () -> UserValidator.validate(user)); + } + + /** + * Test {@link UserValidator#validate(User)}. + *

    + *
  • Given {@code qw}.
  • + *
  • When createUser Username is {@code qw}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validate(User)} + */ + @Test + @DisplayName("Test validate(User); given 'qw'; when createUser Username is 'qw'") + @Tag("MaintainedByDiffblue") + void testValidate_givenQw_whenCreateUserUsernameIsQw() { + // Arrange + User user = UserFactory.createUser(); + user.setUsername("qw"); + user.setPassword(null); + + // Act and Assert + assertThrows(IllegalArgumentException.class, () -> UserValidator.validate(user)); + } + + /** + * Test {@link UserValidator#validate(User)}. + *

    + *
  • Given {@code SmithCredentials Invalid}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validate(User)} + */ + @Test + @DisplayName("Test validate(User); given 'SmithCredentials Invalid'") + @Tag("MaintainedByDiffblue") + void testValidate_givenSmithCredentialsInvalid() { + // Arrange + User user = UserFactory.createUser(); + user.setUsername("SmithCredentials Invalid"); + user.setPassword(null); + + // Act and Assert + assertThrows(IllegalArgumentException.class, () -> UserValidator.validate(user)); + } + + /** + * Test {@link UserValidator#validate(User)}. + *

    + *
  • Given {@code User}.
  • + *
  • When createUser Password is {@code User}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validate(User)} + */ + @Test + @DisplayName("Test validate(User); given 'User'; when createUser Password is 'User'") + @Tag("MaintainedByDiffblue") + void testValidate_givenUser_whenCreateUserPasswordIsUser() { + // Arrange + User user = UserFactory.createUser(); + user.setUsername(null); + user.setPassword("User"); + + // Act and Assert + assertThrows(IllegalArgumentException.class, () -> UserValidator.validate(user)); + } + + /** + * Test {@link UserValidator#validate(User)}. + *

    + *
  • Given {@code User}.
  • + *
  • When createUser Username is {@code User}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validate(User)} + */ + @Test + @DisplayName("Test validate(User); given 'User'; when createUser Username is 'User'") + @Tag("MaintainedByDiffblue") + void testValidate_givenUser_whenCreateUserUsernameIsUser() { + // Arrange + User user = UserFactory.createUser(); + user.setUsername("User"); + user.setPassword(null); + + // Act and Assert + assertThrows(IllegalArgumentException.class, () -> UserValidator.validate(user)); + } + + /** + * Test {@link UserValidator#validate(User)}. + *

    + *
  • When createUser.
  • + *
  • Then return {@code true}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validate(User)} + */ + @Test + @DisplayName("Test validate(User); when createUser; then return 'true'") + @Tag("MaintainedByDiffblue") + void testValidate_whenCreateUser_thenReturnTrue() { + // Arrange, Act and Assert + assertTrue(UserValidator.validate(UserFactory.createUser())); + } + + /** + * Test {@link UserValidator#validateUsername(String)}. + *

    + *
  • When {@code null}.
  • + *
  • Then return {@code false}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validateUsername(String)} + */ + @Test + @DisplayName("Test validateUsername(String); when 'null'; then return 'false'") + @Tag("MaintainedByDiffblue") + void testValidateUsername_whenNull_thenReturnFalse() throws IllegalArgumentException { + // Arrange, Act and Assert + assertFalse(UserValidator.validateUsername(null)); + } + + /** + * Test {@link UserValidator#validateUsername(String)}. + *

    + *
  • When {@code qw}.
  • + *
  • Then return {@code false}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validateUsername(String)} + */ + @Test + @DisplayName("Test validateUsername(String); when 'qw'; then return 'false'") + @Tag("MaintainedByDiffblue") + void testValidateUsername_whenQw_thenReturnFalse() throws IllegalArgumentException { + // Arrange, Act and Assert + assertFalse(UserValidator.validateUsername("qw")); + } + + /** + * Test {@link UserValidator#validateUsername(String)}. + *

    + *
  • When {@code SmithUsernameUsername}.
  • + *
  • Then return {@code false}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validateUsername(String)} + */ + @Test + @DisplayName("Test validateUsername(String); when 'SmithUsernameUsername'; then return 'false'") + @Tag("MaintainedByDiffblue") + void testValidateUsername_whenSmithUsernameUsername_thenReturnFalse() throws IllegalArgumentException { + // Arrange, Act and Assert + assertFalse(UserValidator.validateUsername("SmithUsernameUsername")); + } + + /** + * Test {@link UserValidator#validateUsername(String)}. + *

    + *
  • When {@code Smith}.
  • + *
  • Then return {@code true}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validateUsername(String)} + */ + @Test + @DisplayName("Test validateUsername(String); when 'Smith'; then return 'true'") + @Tag("MaintainedByDiffblue") + void testValidateUsername_whenSmith_thenReturnTrue() throws IllegalArgumentException { + // Arrange, Act and Assert + assertTrue(UserValidator.validateUsername("Smith")); + } + + /** + * Test {@link UserValidator#validatePassword(String)}. + *

    + *
  • When {@code abc}.
  • + *
  • Then return {@code false}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validatePassword(String)} + */ + @Test + @DisplayName("Test validatePassword(String); when 'abc'; then return 'false'") + @Tag("MaintainedByDiffblue") + void testValidatePassword_whenAbc_thenReturnFalse() throws IllegalArgumentException { + // Arrange, Act and Assert + assertFalse(UserValidator.validatePassword("abc")); + } + + /** + * Test {@link UserValidator#validatePassword(String)}. + *

    + *
  • When {@code null}.
  • + *
  • Then return {@code false}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validatePassword(String)} + */ + @Test + @DisplayName("Test validatePassword(String); when 'null'; then return 'false'") + @Tag("MaintainedByDiffblue") + void testValidatePassword_whenNull_thenReturnFalse() throws IllegalArgumentException { + // Arrange, Act and Assert + assertFalse(UserValidator.validatePassword(null)); + } + + /** + * Test {@link UserValidator#validatePassword(String)}. + *

    + *
  • When {@code qwertyuio}.
  • + *
  • Then return {@code true}.
  • + *
+ *

+ * Method under test: {@link UserValidator#validatePassword(String)} + */ + @Test + @DisplayName("Test validatePassword(String); when 'qwertyuio'; then return 'true'") + @Tag("MaintainedByDiffblue") + void testValidatePassword_whenQwertyuio_thenReturnTrue() throws IllegalArgumentException { + // Arrange, Act and Assert + assertTrue(UserValidator.validatePassword("qwertyuio")); + } +} diff --git a/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java b/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java deleted file mode 100644 index a28ec2bf..00000000 --- a/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.piggymetrics.account.repository; - -import com.piggymetrics.account.domain.Account; -import com.piggymetrics.account.domain.Currency; -import com.piggymetrics.account.domain.Item; -import com.piggymetrics.account.domain.Saving; -import com.piggymetrics.account.domain.TimePeriod; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.math.BigDecimal; -import java.util.Arrays; -import java.util.Date; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringRunner.class) -@DataMongoTest -public class AccountRepositoryTest { - - @Autowired - private AccountRepository repository; - - @Test - public void shouldFindAccountByName() { - - Account stub = getStubAccount(); - repository.save(stub); - - Account found = repository.findByName(stub.getName()); - assertEquals(stub.getLastSeen(), found.getLastSeen()); - assertEquals(stub.getNote(), found.getNote()); - assertEquals(stub.getIncomes().size(), found.getIncomes().size()); - assertEquals(stub.getExpenses().size(), found.getExpenses().size()); - } - - private Account getStubAccount() { - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal(1500)); - saving.setCurrency(Currency.USD); - saving.setInterest(new BigDecimal("3.32")); - saving.setDeposit(true); - saving.setCapitalization(false); - - Item vacation = new Item(); - vacation.setTitle("Vacation"); - vacation.setAmount(new BigDecimal(3400)); - vacation.setCurrency(Currency.EUR); - vacation.setPeriod(TimePeriod.YEAR); - vacation.setIcon("tourism"); - - Item grocery = new Item(); - grocery.setTitle("Grocery"); - grocery.setAmount(new BigDecimal(10)); - grocery.setCurrency(Currency.USD); - grocery.setPeriod(TimePeriod.DAY); - grocery.setIcon("meal"); - - Item salary = new Item(); - salary.setTitle("Salary"); - salary.setAmount(new BigDecimal(9100)); - salary.setCurrency(Currency.USD); - salary.setPeriod(TimePeriod.MONTH); - salary.setIcon("wallet"); - - Account account = new Account(); - account.setName("test"); - account.setNote("test note"); - account.setLastSeen(new Date()); - account.setSaving(saving); - account.setExpenses(Arrays.asList(grocery, vacation)); - account.setIncomes(Arrays.asList(salary)); - - return account; - } -} diff --git a/account-service/src/test/java/com/piggymetrics/account/service/AccountServiceImplDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/service/AccountServiceImplDiffblueTest.java new file mode 100644 index 00000000..2e93b1a0 --- /dev/null +++ b/account-service/src/test/java/com/piggymetrics/account/service/AccountServiceImplDiffblueTest.java @@ -0,0 +1,259 @@ +package com.piggymetrics.account.service; + +import com.piggymetrics.account.client.AuthServiceClient; +import com.piggymetrics.account.client.StatisticsServiceClient; +import com.piggymetrics.account.domain.Account; +import com.piggymetrics.account.domain.Currency; +import com.piggymetrics.account.domain.Saving; +import com.piggymetrics.account.domain.User; +import com.piggymetrics.account.repository.AccountRepository; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.Date; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ContextConfiguration(classes = {AccountServiceImpl.class}) +@ExtendWith(SpringExtension.class) +class AccountServiceImplDiffblueTest { + @MockBean + private AccountRepository accountRepository; + + @Autowired + private AccountServiceImpl accountServiceImpl; + + @MockBean + private AuthServiceClient authServiceClient; + + @MockBean + private StatisticsServiceClient statisticsServiceClient; + + /** + * Test {@link AccountServiceImpl#findByName(String)}. + *

+ * Method under test: {@link AccountServiceImpl#findByName(String)} + */ + @Test + @DisplayName("Test findByName(String)") + @Disabled("TODO: Complete this test") + void testFindByName() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + accountServiceImpl.findByName("Smith"); + } + + /** + * Test {@link AccountServiceImpl#create(User)}. + *

+ * Method under test: {@link AccountServiceImpl#create(User)} + */ + @Test + @DisplayName("Test create(User)") + @Disabled("TODO: Complete this test") + void testCreate() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + User user = new User(); + user.setPassword("abc"); + user.setUsername("Smith"); + + // Act + accountServiceImpl.create(user); + } + + /** + * Test {@link AccountServiceImpl#saveChanges(String, Account)}. + *

+ * Method under test: {@link AccountServiceImpl#saveChanges(String, Account)} + */ + @Test + @DisplayName("Test saveChanges(String, Account)") + @Disabled("TODO: Complete this test") + void testSaveChanges() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + Saving saving = new Saving(); + saving.setAmount(new BigDecimal("2.6")); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + saving.setInterest(new BigDecimal("2.6")); + + Account update = new Account(); + update.setExpenses(new ArrayList<>()); + update.setIncomes(new ArrayList<>()); + update.setLastSeen(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); + update.setName("Smith"); + update.setNote("Note"); + update.setSaving(saving); + + // Act + accountServiceImpl.saveChanges("Smith", update); + } +} diff --git a/account-service/src/test/java/com/piggymetrics/account/service/AccountServiceTest.java b/account-service/src/test/java/com/piggymetrics/account/service/AccountServiceTest.java deleted file mode 100644 index 675d54c5..00000000 --- a/account-service/src/test/java/com/piggymetrics/account/service/AccountServiceTest.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.piggymetrics.account.service; - -import com.piggymetrics.account.client.AuthServiceClient; -import com.piggymetrics.account.client.StatisticsServiceClient; -import com.piggymetrics.account.domain.*; -import com.piggymetrics.account.repository.AccountRepository; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -import java.math.BigDecimal; -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; - -public class AccountServiceTest { - - @InjectMocks - private AccountServiceImpl accountService; - - @Mock - private StatisticsServiceClient statisticsClient; - - @Mock - private AuthServiceClient authClient; - - @Mock - private AccountRepository repository; - - @Before - public void setup() { - initMocks(this); - } - - @Test - public void shouldFindByName() { - - final Account account = new Account(); - account.setName("test"); - - when(accountService.findByName(account.getName())).thenReturn(account); - Account found = accountService.findByName(account.getName()); - - assertEquals(account, found); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailWhenNameIsEmpty() { - accountService.findByName(""); - } - - @Test - public void shouldCreateAccountWithGivenUser() { - - User user = new User(); - user.setUsername("test"); - - Account account = accountService.create(user); - - assertEquals(user.getUsername(), account.getName()); - assertEquals(0, account.getSaving().getAmount().intValue()); - assertEquals(Currency.getDefault(), account.getSaving().getCurrency()); - assertEquals(0, account.getSaving().getInterest().intValue()); - assertEquals(false, account.getSaving().getDeposit()); - assertEquals(false, account.getSaving().getCapitalization()); - assertNotNull(account.getLastSeen()); - - verify(authClient, times(1)).createUser(user); - verify(repository, times(1)).save(account); - } - - @Test - public void shouldSaveChangesWhenUpdatedAccountGiven() { - - Item grocery = new Item(); - grocery.setTitle("Grocery"); - grocery.setAmount(new BigDecimal(10)); - grocery.setCurrency(Currency.USD); - grocery.setPeriod(TimePeriod.DAY); - grocery.setIcon("meal"); - - Item salary = new Item(); - salary.setTitle("Salary"); - salary.setAmount(new BigDecimal(9100)); - salary.setCurrency(Currency.USD); - salary.setPeriod(TimePeriod.MONTH); - salary.setIcon("wallet"); - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal(1500)); - saving.setCurrency(Currency.USD); - saving.setInterest(new BigDecimal("3.32")); - saving.setDeposit(true); - saving.setCapitalization(false); - - final Account update = new Account(); - update.setName("test"); - update.setNote("test note"); - update.setIncomes(Arrays.asList(salary)); - update.setExpenses(Arrays.asList(grocery)); - update.setSaving(saving); - - final Account account = new Account(); - - when(accountService.findByName("test")).thenReturn(account); - accountService.saveChanges("test", update); - - assertEquals(update.getNote(), account.getNote()); - assertNotNull(account.getLastSeen()); - - assertEquals(update.getSaving().getAmount(), account.getSaving().getAmount()); - assertEquals(update.getSaving().getCurrency(), account.getSaving().getCurrency()); - assertEquals(update.getSaving().getInterest(), account.getSaving().getInterest()); - assertEquals(update.getSaving().getDeposit(), account.getSaving().getDeposit()); - assertEquals(update.getSaving().getCapitalization(), account.getSaving().getCapitalization()); - - assertEquals(update.getExpenses().size(), account.getExpenses().size()); - assertEquals(update.getIncomes().size(), account.getIncomes().size()); - - assertEquals(update.getExpenses().get(0).getTitle(), account.getExpenses().get(0).getTitle()); - assertEquals(0, update.getExpenses().get(0).getAmount().compareTo(account.getExpenses().get(0).getAmount())); - assertEquals(update.getExpenses().get(0).getCurrency(), account.getExpenses().get(0).getCurrency()); - assertEquals(update.getExpenses().get(0).getPeriod(), account.getExpenses().get(0).getPeriod()); - assertEquals(update.getExpenses().get(0).getIcon(), account.getExpenses().get(0).getIcon()); - - assertEquals(update.getIncomes().get(0).getTitle(), account.getIncomes().get(0).getTitle()); - assertEquals(0, update.getIncomes().get(0).getAmount().compareTo(account.getIncomes().get(0).getAmount())); - assertEquals(update.getIncomes().get(0).getCurrency(), account.getIncomes().get(0).getCurrency()); - assertEquals(update.getIncomes().get(0).getPeriod(), account.getIncomes().get(0).getPeriod()); - assertEquals(update.getIncomes().get(0).getIcon(), account.getIncomes().get(0).getIcon()); - - verify(repository, times(1)).save(account); - verify(statisticsClient, times(1)).updateStatistics("test", account); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailWhenNoAccountsExistedWithGivenName() { - final Account update = new Account(); - update.setIncomes(Arrays.asList(new Item())); - update.setExpenses(Arrays.asList(new Item())); - - when(accountService.findByName("test")).thenReturn(null); - accountService.saveChanges("test", update); - } -} diff --git a/account-service/src/test/java/com/piggymetrics/account/service/security/CustomUserInfoTokenServicesDiffblueTest.java b/account-service/src/test/java/com/piggymetrics/account/service/security/CustomUserInfoTokenServicesDiffblueTest.java index b842819d..2f57c809 100644 --- a/account-service/src/test/java/com/piggymetrics/account/service/security/CustomUserInfoTokenServicesDiffblueTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/service/security/CustomUserInfoTokenServicesDiffblueTest.java @@ -1,56 +1,103 @@ package com.piggymetrics.account.service.security; -import com.piggymetrics.account.repository.AccountRepository; -import de.flapdoodle.embed.mongo.MongodExecutable; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.autoconfigure.security.oauth2.resource.AuthoritiesExtractor; +import org.springframework.boot.autoconfigure.security.oauth2.resource.FixedAuthoritiesExtractor; import org.springframework.security.core.AuthenticationException; +import org.springframework.security.oauth2.client.OAuth2RestOperations; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails; import org.springframework.security.oauth2.common.exceptions.InvalidTokenException; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) -public class CustomUserInfoTokenServicesDiffblueTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @MockBean - private AccountRepository accountRepository; - - @Autowired - private CustomUserInfoTokenServices customUserInfoTokenServices; - - @MockBean - private MongodExecutable mongodExecutable; - - /** - * Test {@link CustomUserInfoTokenServices#loadAuthentication(String)}. - *

- * Method under test: - * {@link CustomUserInfoTokenServices#loadAuthentication(String)} - */ - @Test - public void testLoadAuthentication() throws AuthenticationException, InvalidTokenException { - // Arrange, Act and Assert - thrown.expect(InvalidTokenException.class); - customUserInfoTokenServices.loadAuthentication("ABC123"); - } - - /** - * Test {@link CustomUserInfoTokenServices#readAccessToken(String)}. - *

- * Method under test: - * {@link CustomUserInfoTokenServices#readAccessToken(String)} - */ - @Test - public void testReadAccessToken() { - // Arrange, Act and Assert - thrown.expect(UnsupportedOperationException.class); - customUserInfoTokenServices.readAccessToken("ABC123"); - } +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ContextConfiguration(classes = {CustomUserInfoTokenServices.class, String.class}) +@ExtendWith(SpringExtension.class) +class CustomUserInfoTokenServicesDiffblueTest { + @Autowired + private CustomUserInfoTokenServices customUserInfoTokenServices; + + /** + * Test {@link CustomUserInfoTokenServices#loadAuthentication(String)}. + *

+ * Method under test: + * {@link CustomUserInfoTokenServices#loadAuthentication(String)} + */ + @Test + @DisplayName("Test loadAuthentication(String)") + void testLoadAuthentication() throws AuthenticationException, InvalidTokenException { + // Arrange, Act and Assert + assertThrows(InvalidTokenException.class, () -> customUserInfoTokenServices.loadAuthentication("ABC123")); + } + + /** + * Test {@link CustomUserInfoTokenServices#readAccessToken(String)}. + *

+ * Method under test: + * {@link CustomUserInfoTokenServices#readAccessToken(String)} + */ + @Test + @DisplayName("Test readAccessToken(String)") + void testReadAccessToken() { + // Arrange, Act and Assert + assertThrows(UnsupportedOperationException.class, () -> customUserInfoTokenServices.readAccessToken("ABC123")); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • + * {@link CustomUserInfoTokenServices#setAuthoritiesExtractor(AuthoritiesExtractor)} + *
  • {@link CustomUserInfoTokenServices#setRestTemplate(OAuth2RestOperations)} + *
  • {@link CustomUserInfoTokenServices#setTokenType(String)} + *
+ */ + @Test + @DisplayName("Test getters and setters") + void testGettersAndSetters() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Missing observers. + // Diffblue Cover was unable to create an assertion. + // Add getters for the following fields or make them package-private: + // CustomUserInfoTokenServices.authoritiesExtractor + // CustomUserInfoTokenServices.clientId + // CustomUserInfoTokenServices.logger + // CustomUserInfoTokenServices.restTemplate + // CustomUserInfoTokenServices.tokenType + // CustomUserInfoTokenServices.userInfoEndpointUrl + + // Arrange + CustomUserInfoTokenServices customUserInfoTokenServices = new CustomUserInfoTokenServices( + "https://example.org/example", "42"); + + // Act + customUserInfoTokenServices.setAuthoritiesExtractor(new FixedAuthoritiesExtractor()); + customUserInfoTokenServices.setRestTemplate(new OAuth2RestTemplate(new BaseOAuth2ProtectedResourceDetails())); + customUserInfoTokenServices.setTokenType("ABC123"); + } + + /** + * Test + * {@link CustomUserInfoTokenServices#CustomUserInfoTokenServices(String, String)}. + *

+ * Method under test: + * {@link CustomUserInfoTokenServices#CustomUserInfoTokenServices(String, String)} + */ + @Test + @DisplayName("Test new CustomUserInfoTokenServices(String, String)") + void testNewCustomUserInfoTokenServices() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Diffblue AI was unable to find a test + + // Arrange and Act + new CustomUserInfoTokenServices("https://example.org/example", "42"); + + } } diff --git a/auth-service/pom.xml b/auth-service/pom.xml index 21294f61..72821afe 100644 --- a/auth-service/pom.xml +++ b/auth-service/pom.xml @@ -62,7 +62,7 @@ org.jacoco org.jacoco.agent - 0.8.2 + 0.8.11 test runtime @@ -72,6 +72,24 @@ 4.12 test + + org.mockito + mockito-core + 4.1.0 + test + + + org.springframework + spring-core + 6.0.11 + compile + + + org.springframework.boot + spring-boot + 2.5.1 + compile + @@ -97,7 +115,7 @@ org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.11 diff --git a/auth-service/report.json b/auth-service/report.json deleted file mode 100644 index e94a7d9a..00000000 --- a/auth-service/report.json +++ /dev/null @@ -1,643 +0,0 @@ -{ - "meta" : { - "reportVersion" : "2.6" - }, - "run" : { - "version" : "2025.01.01-2348203-licensed", - "creationTimestamp" : "2025-01-13T16:34:47.76Z", - "command" : "dcover create --batch --report-file=report.json --coverage-reports --spring-integration-tests --verbose --exclude=com.piggymetrics.notification.service.NotificationServiceImpl. --working-directory=auth-service", - "totalTime" : 306.989, - "environmentDetectionTime" : 0.695, - "indexingTime" : 0.336, - "entryPointsTime" : 0.663, - "generationTime" : 219.33, - "timeToFirstTest" : 98.441, - "timeToLastTest" : 263.812, - "indexQueryTime" : 15.609, - "verificationTime" : 21.082, - "validationTime" : 18.929 - }, - "codes" : { - "E052" : "Missing dependency", - "R000" : "Success", - "R004" : "No meaningful assertions found", - "R013" : "No inputs found that don't throw a trivial exception", - "T000" : "Method eligible for test creation", - "T001" : "Trivial getter", - "T002" : "Trivial setter", - "T005" : "Trivial constructor", - "T006" : "Main method", - "T010" : "Abstract or interface method", - "T012" : "Synthetic method", - "V000" : "Validated successfully" - }, - "summary" : { - "classesCount" : 9, - "methodsCount" : 42, - "cumulativeDiffblueTestCount" : 13, - "cumulativeManualTestCount" : 9, - "completeTestCount" : 13, - "incompleteTestCount" : 0, - "skeletonTestCount" : 0, - "totalPhysicalLineCount" : 237, - "perMethodTestability" : { - "T000" : 25, - "T001" : 6, - "T002" : 2, - "T005" : 4, - "T006" : 1, - "T010" : 1, - "T012" : 3 - }, - "perMethodOutcome" : { - "E052" : 11, - "R000" : 17, - "R004" : 1, - "R013" : 2, - "T005" : 6, - "T006" : 1, - "T010" : 1, - "T012" : 3 - }, - "perTestOutcome" : { - "R000" : 13 - }, - "perTestValidation" : { - "V000" : 13 - } - }, - "classes" : { - "com.piggymetrics.auth.AuthApplication" : { - "methodsCount" : 2, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T005" : 1, - "T006" : 1 - }, - "perMethodOutcome" : { - "T005" : 1, - "T006" : 1 - } - }, - "com.piggymetrics.auth.config.OAuth2AuthorizationConfig" : { - "methodsCount" : 4, - "completeTestCount" : 3, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 4 - }, - "perMethodOutcome" : { - "R000" : 3, - "T005" : 1 - }, - "perTestOutcome" : { - "R000" : 3 - } - }, - "com.piggymetrics.auth.config.WebSecurityConfig" : { - "methodsCount" : 4, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 4 - }, - "perMethodOutcome" : { - "R004" : 1, - "R013" : 2, - "T005" : 1 - } - }, - "com.piggymetrics.auth.controller.UserController" : { - "methodsCount" : 3, - "completeTestCount" : 2, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 2, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 2, - "T005" : 1 - }, - "perTestOutcome" : { - "R000" : 2 - } - }, - "com.piggymetrics.auth.domain.User" : { - "methodsCount" : 10, - "completeTestCount" : 2, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T001" : 6, - "T002" : 2, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 10 - }, - "perTestOutcome" : { - "R000" : 2 - } - }, - "com.piggymetrics.auth.repository.UserRepository" : { - "methodsCount" : 11, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 11 - }, - "perMethodOutcome" : { - "E052" : 11 - } - }, - "com.piggymetrics.auth.service.UserService" : { - "methodsCount" : 1, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T010" : 1 - }, - "perMethodOutcome" : { - "T010" : 1 - } - }, - "com.piggymetrics.auth.service.UserServiceImpl" : { - "methodsCount" : 4, - "completeTestCount" : 3, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 2, - "T012" : 2 - }, - "perMethodOutcome" : { - "R000" : 1, - "T005" : 1, - "T012" : 2 - }, - "perTestOutcome" : { - "R000" : 3 - } - }, - "com.piggymetrics.auth.service.security.MongoUserDetailsService" : { - "methodsCount" : 3, - "completeTestCount" : 3, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T005" : 1, - "T012" : 1 - }, - "perMethodOutcome" : { - "R000" : 1, - "T005" : 1, - "T012" : 1 - }, - "perTestOutcome" : { - "R000" : 3 - } - } - }, - "methods" : { - "com.piggymetrics.auth.AuthApplication.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 13 - ] - }, - "com.piggymetrics.auth.AuthApplication.main:([Ljava/lang/String;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T006", - "perMethodOutcome" : "T006", - "lineNumbers" : [ - 16, - 17 - ] - }, - "com.piggymetrics.auth.config.OAuth2AuthorizationConfig.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 23, - 25, - 26 - ] - }, - "com.piggymetrics.auth.config.OAuth2AuthorizationConfig.configure:(Lorg/springframework/security/oauth2/config/annotation/configurers/ClientDetailsServiceConfigurer;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 59, - 60, - 61, - 62, - 64 - ] - }, - "com.piggymetrics.auth.config.OAuth2AuthorizationConfig.configure:(Lorg/springframework/security/oauth2/config/annotation/web/configurers/AuthorizationServerEndpointsConfigurer;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 68, - 69, - 70, - 71, - 72 - ] - }, - "com.piggymetrics.auth.config.OAuth2AuthorizationConfig.configure:(Lorg/springframework/security/oauth2/config/annotation/web/configurers/AuthorizationServerSecurityConfigurer;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 76, - 77, - 78, - 79, - 80 - ] - }, - "com.piggymetrics.auth.config.WebSecurityConfig.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 17 - ] - }, - "com.piggymetrics.auth.config.WebSecurityConfig.authenticationManagerBean:()Lorg/springframework/security/authentication/AuthenticationManager;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R004", - "lineNumbers" : [ - 41 - ] - }, - "com.piggymetrics.auth.config.WebSecurityConfig.configure:(Lorg/springframework/security/config/annotation/authentication/builders/AuthenticationManagerBuilder;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R013", - "lineNumbers" : [ - 34, - 35, - 36 - ] - }, - "com.piggymetrics.auth.config.WebSecurityConfig.configure:(Lorg/springframework/security/config/annotation/web/builders/HttpSecurity;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R013", - "lineNumbers" : [ - 25, - 26, - 27, - 28, - 30 - ] - }, - "com.piggymetrics.auth.controller.UserController.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 17 - ] - }, - "com.piggymetrics.auth.controller.UserController.createUser:(Lcom/piggymetrics/auth/domain/User;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 30, - 31 - ] - }, - "com.piggymetrics.auth.controller.UserController.getUser:(Ljava/security/Principal;)Ljava/security/Principal;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 24 - ] - }, - "com.piggymetrics.auth.domain.User.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 11 - ] - }, - "com.piggymetrics.auth.domain.User.getAuthorities:()Ljava/util/List;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 30 - ] - }, - "com.piggymetrics.auth.domain.User.getPassword:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 20 - ] - }, - "com.piggymetrics.auth.domain.User.getUsername:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 25 - ] - }, - "com.piggymetrics.auth.domain.User.isAccountNonExpired:()Z" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 43 - ] - }, - "com.piggymetrics.auth.domain.User.isAccountNonLocked:()Z" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 48 - ] - }, - "com.piggymetrics.auth.domain.User.isCredentialsNonExpired:()Z" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 53 - ] - }, - "com.piggymetrics.auth.domain.User.isEnabled:()Z" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 58 - ] - }, - "com.piggymetrics.auth.domain.User.setPassword:(Ljava/lang/String;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 38, - 39 - ] - }, - "com.piggymetrics.auth.domain.User.setUsername:(Ljava/lang/String;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 34, - 35 - ] - }, - "com.piggymetrics.auth.repository.UserRepository.count:()J" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.delete:(Ljava/lang/Object;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.deleteAll:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.deleteAll:(Ljava/lang/Iterable;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.deleteById:(Ljava/lang/Object;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.existsById:(Ljava/lang/Object;)Z" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.findAll:()Ljava/lang/Iterable;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.findAllById:(Ljava/lang/Iterable;)Ljava/lang/Iterable;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.findById:(Ljava/lang/Object;)Ljava/util/Optional;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.save:(Ljava/lang/Object;)Ljava/lang/Object;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.repository.UserRepository.saveAll:(Ljava/lang/Iterable;)Ljava/lang/Iterable;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.auth.service.UserService.create:(Lcom/piggymetrics/auth/domain/User;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.auth.service.UserServiceImpl.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 19 - ] - }, - "com.piggymetrics.auth.service.UserServiceImpl.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 15, - 17 - ] - }, - "com.piggymetrics.auth.service.UserServiceImpl.create:(Lcom/piggymetrics/auth/domain/User;)V" : { - "completeTestCount" : 3, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 3 - }, - "lineNumbers" : [ - 27, - 28, - 30, - 31, - 33, - 35, - 36 - ] - }, - "com.piggymetrics.auth.service.UserServiceImpl.lambda$create$0:(Lcom/piggymetrics/auth/domain/User;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 28 - ] - }, - "com.piggymetrics.auth.service.security.MongoUserDetailsService.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 11 - ] - }, - "com.piggymetrics.auth.service.security.MongoUserDetailsService.lambda$loadUserByUsername$0:(Ljava/lang/String;)Lorg/springframework/security/core/userdetails/UsernameNotFoundException;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 19 - ] - }, - "com.piggymetrics.auth.service.security.MongoUserDetailsService.loadUserByUsername:(Ljava/lang/String;)Lorg/springframework/security/core/userdetails/UserDetails;" : { - "completeTestCount" : 3, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 3 - }, - "lineNumbers" : [ - 19 - ] - } - } -} \ No newline at end of file diff --git a/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java b/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java deleted file mode 100644 index 9189fa43..00000000 --- a/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.piggymetrics.auth; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class AuthServiceApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/auth-service/src/test/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfigDiffblueTest.java b/auth-service/src/test/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfigDiffblueTest.java index 24dbbb1d..2982fc7c 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfigDiffblueTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfigDiffblueTest.java @@ -1,91 +1,233 @@ package com.piggymetrics.auth.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import com.piggymetrics.auth.repository.UserRepository; -import de.flapdoodle.embed.mongo.MongodExecutable; +import com.piggymetrics.auth.service.security.MongoUserDetailsService; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.core.env.Environment; +import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.oauth2.config.annotation.builders.ClientDetailsServiceBuilder; -import org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@SpringBootTest +@ContextConfiguration(classes = {OAuth2AuthorizationConfig.class, AuthenticationManager.class}) @RunWith(SpringJUnit4ClassRunner.class) public class OAuth2AuthorizationConfigDiffblueTest { - @MockBean - private MongodExecutable mongodExecutable; + @MockBean + private Environment environment; - @Autowired - private OAuth2AuthorizationConfig oAuth2AuthorizationConfig; + @MockBean + private MongoUserDetailsService mongoUserDetailsService; - @MockBean - private UserRepository userRepository; + @Autowired + private OAuth2AuthorizationConfig oAuth2AuthorizationConfig; - /** - * Test - * {@link OAuth2AuthorizationConfig#configure(ClientDetailsServiceConfigurer)} - * with {@code clients}. - *

- * Method under test: - * {@link OAuth2AuthorizationConfig#configure(ClientDetailsServiceConfigurer)} - */ - @Test - public void testConfigureWithClients() throws Exception { - // Arrange - ClientDetailsServiceConfigurer clients = new ClientDetailsServiceConfigurer(new ClientDetailsServiceBuilder<>()); + /** + * Test + * {@link OAuth2AuthorizationConfig#configure(ClientDetailsServiceConfigurer)} + * with {@code clients}. + *

+ * Method under test: + * {@link OAuth2AuthorizationConfig#configure(ClientDetailsServiceConfigurer)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConfigureWithClients() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. - // Act - oAuth2AuthorizationConfig.configure(clients); + // Arrange and Act + oAuth2AuthorizationConfig.configure(new ClientDetailsServiceConfigurer(new ClientDetailsServiceBuilder<>())); + } - // Assert - assertTrue(clients.and() instanceof InMemoryClientDetailsServiceBuilder); - } + /** + * Test + * {@link OAuth2AuthorizationConfig#configure(AuthorizationServerEndpointsConfigurer)} + * with {@code endpoints}. + *

+ * Method under test: + * {@link OAuth2AuthorizationConfig#configure(AuthorizationServerEndpointsConfigurer)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConfigureWithEndpoints() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. - /** - * Test - * {@link OAuth2AuthorizationConfig#configure(AuthorizationServerEndpointsConfigurer)} - * with {@code endpoints}. - *

- * Method under test: - * {@link OAuth2AuthorizationConfig#configure(AuthorizationServerEndpointsConfigurer)} - */ - @Test - public void testConfigureWithEndpoints() throws Exception { - // Arrange - AuthorizationServerEndpointsConfigurer endpoints = new AuthorizationServerEndpointsConfigurer(); + // Arrange and Act + oAuth2AuthorizationConfig.configure(new AuthorizationServerEndpointsConfigurer()); + } - // Act - oAuth2AuthorizationConfig.configure(endpoints); + /** + * Test + * {@link OAuth2AuthorizationConfig#configure(AuthorizationServerSecurityConfigurer)} + * with {@code oauthServer}. + *

+ * Method under test: + * {@link OAuth2AuthorizationConfig#configure(AuthorizationServerSecurityConfigurer)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConfigureWithOauthServer() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. - // Assert - assertTrue(endpoints.isUserDetailsServiceOverride()); - } - - /** - * Test - * {@link OAuth2AuthorizationConfig#configure(AuthorizationServerSecurityConfigurer)} - * with {@code oauthServer}. - *

- * Method under test: - * {@link OAuth2AuthorizationConfig#configure(AuthorizationServerSecurityConfigurer)} - */ - @Test - public void testConfigureWithOauthServer() throws Exception { - // Arrange - AuthorizationServerSecurityConfigurer oauthServer = new AuthorizationServerSecurityConfigurer(); - - // Act - oAuth2AuthorizationConfig.configure(oauthServer); - - // Assert - assertEquals("isAuthenticated()", oauthServer.getCheckTokenAccess()); - assertEquals("permitAll()", oauthServer.getTokenKeyAccess()); - } + // Arrange and Act + oAuth2AuthorizationConfig.configure(new AuthorizationServerSecurityConfigurer()); + } } diff --git a/auth-service/src/test/java/com/piggymetrics/auth/config/WebSecurityConfigDiffblueTest.java b/auth-service/src/test/java/com/piggymetrics/auth/config/WebSecurityConfigDiffblueTest.java new file mode 100644 index 00000000..52acdfbf --- /dev/null +++ b/auth-service/src/test/java/com/piggymetrics/auth/config/WebSecurityConfigDiffblueTest.java @@ -0,0 +1,239 @@ +package com.piggymetrics.auth.config; + +import com.piggymetrics.auth.service.security.MongoUserDetailsService; + +import java.util.HashMap; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.ApplicationContext; +import org.springframework.security.authentication.AuthenticationTrustResolver; +import org.springframework.security.config.annotation.ObjectPostProcessor; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.web.accept.ContentNegotiationStrategy; + +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +@ContextConfiguration(classes = {WebSecurityConfig.class, AuthenticationConfiguration.class, + ContentNegotiationStrategy.class, AuthenticationTrustResolver.class}) +@RunWith(SpringJUnit4ClassRunner.class) +public class WebSecurityConfigDiffblueTest { + @Autowired + private ApplicationContext applicationContext; + + @MockBean + private MongoUserDetailsService mongoUserDetailsService; + + @Autowired + private ObjectPostProcessor objectPostProcessor; + + @Autowired + private WebSecurityConfig webSecurityConfig; + + /** + * Test {@link WebSecurityConfig#configure(AuthenticationManagerBuilder)} with + * {@code auth}. + *

+ * Method under test: + * {@link WebSecurityConfig#configure(AuthenticationManagerBuilder)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConfigureWithAuth() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + webSecurityConfig.configure(new AuthenticationManagerBuilder(objectPostProcessor)); + } + + /** + * Test {@link WebSecurityConfig#configure(HttpSecurity)} with {@code http}. + *

+ * Method under test: {@link WebSecurityConfig#configure(HttpSecurity)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConfigureWithHttp() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + AuthenticationManagerBuilder authenticationBuilder = new AuthenticationManagerBuilder(objectPostProcessor); + + // Act + webSecurityConfig.configure(new HttpSecurity(objectPostProcessor, authenticationBuilder, new HashMap<>())); + } + + /** + * Test {@link WebSecurityConfig#authenticationManagerBean()}. + *

+ * Method under test: {@link WebSecurityConfig#authenticationManagerBean()} + */ + @Test + @Ignore("TODO: Complete this test") + public void testAuthenticationManagerBean() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + webSecurityConfig.authenticationManagerBean(); + } +} diff --git a/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerDiffblueTest.java b/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerDiffblueTest.java index e4096ef9..c47a3704 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerDiffblueTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerDiffblueTest.java @@ -1,71 +1,57 @@ package com.piggymetrics.auth.controller; -import static org.mockito.Mockito.doNothing; -import com.fasterxml.jackson.databind.ObjectMapper; +import static org.junit.Assert.assertEquals; + import com.piggymetrics.auth.domain.User; -import com.piggymetrics.auth.service.UserService; +import com.sun.security.auth.UserPrincipal; + import java.security.Principal; + +import org.junit.Ignore; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -@ContextConfiguration(classes = {UserController.class}) -@RunWith(SpringJUnit4ClassRunner.class) public class UserControllerDiffblueTest { - @Autowired - private UserController userController; - - @MockBean - private UserService userService; - - /** - * Test {@link UserController#getUser(Principal)}. - *

- * Method under test: {@link UserController#getUser(Principal)} - */ - @Test - public void testGetUser() throws Exception { - // Arrange - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/users/current"); - - // Act and Assert - MockMvcBuilders.standaloneSetup(userController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()); - } - - /** - * Test {@link UserController#createUser(User)}. - *

- * Method under test: {@link UserController#createUser(User)} - */ - @Test - public void testCreateUser() throws Exception { - // Arrange - doNothing().when(userService).create(Mockito.any()); - - User user = new User(); - user.setPassword("iloveyou"); - user.setUsername("janedoe"); - String content = (new ObjectMapper()).writeValueAsString(user); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/users") - .contentType(MediaType.APPLICATION_JSON) - .content(content); - - // Act and Assert - MockMvcBuilders.standaloneSetup(userController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()); - } + /** + * Test {@link UserController#getUser(Principal)}. + *

+ * Method under test: {@link UserController#getUser(Principal)} + */ + @Test + public void testGetUser() { + // Diffblue Cover was unable to create a Spring-specific test for this Spring method. + // Run dcover create --keep-partial-tests to gain insights into why + // a non-Spring test was created. + + // Arrange + UserController userController = new UserController(); + + // Act and Assert + assertEquals("principal", userController.getUser(new UserPrincipal("principal")).getName()); + } + + /** + * Test {@link UserController#createUser(User)}. + *

+ * Method under test: {@link UserController#createUser(User)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testCreateUser() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Unable to load class. + // Class: jakarta.servlet.ServletContext + // Please check that the class is available on your test runtime classpath. + // See https://diff.blue/R005 to resolve this issue. + + // Arrange + // TODO: Populate arranged inputs + UserController userController = null; + User user = null; + + // Act + userController.createUser(user); + + // Assert + // TODO: Add assertions on result + } } diff --git a/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java b/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java deleted file mode 100644 index bbff0c1b..00000000 --- a/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.piggymetrics.auth.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.piggymetrics.auth.domain.User; -import com.piggymetrics.auth.service.UserService; -import com.sun.security.auth.UserPrincipal; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import static org.mockito.MockitoAnnotations.initMocks; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class UserControllerTest { - - private static final ObjectMapper mapper = new ObjectMapper(); - - @InjectMocks - private UserController accountController; - - @Mock - private UserService userService; - - private MockMvc mockMvc; - - @Before - public void setup() { - initMocks(this); - this.mockMvc = MockMvcBuilders.standaloneSetup(accountController).build(); - } - - @Test - public void shouldCreateNewUser() throws Exception { - - final User user = new User(); - user.setUsername("test"); - user.setPassword("password"); - - String json = mapper.writeValueAsString(user); - - mockMvc.perform(post("/users").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()); - } - - @Test - public void shouldFailWhenUserIsNotValid() throws Exception { - - final User user = new User(); - user.setUsername("t"); - user.setPassword("p"); - - mockMvc.perform(post("/users")) - .andExpect(status().isBadRequest()); - } - - @Test - public void shouldReturnCurrentUser() throws Exception { - mockMvc.perform(get("/users/current").principal(new UserPrincipal("test"))) - .andExpect(jsonPath("$.name").value("test")) - .andExpect(status().isOk()); - } -} diff --git a/auth-service/src/test/java/com/piggymetrics/auth/domain/UserDiffblueTest.java b/auth-service/src/test/java/com/piggymetrics/auth/domain/UserDiffblueTest.java index 8c17bfdc..04aa0d97 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/domain/UserDiffblueTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/domain/UserDiffblueTest.java @@ -3,54 +3,94 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; + import org.junit.Test; public class UserDiffblueTest { - /** - * Test {@link User#getAuthorities()}. - *

- * Method under test: {@link User#getAuthorities()} - */ - @Test - public void testGetAuthorities() { - // Arrange, Act and Assert - assertNull((new User()).getAuthorities()); - } - - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link User} - *
  • {@link User#setPassword(String)} - *
  • {@link User#setUsername(String)} - *
  • {@link User#getPassword()} - *
  • {@link User#getUsername()} - *
  • {@link User#isAccountNonExpired()} - *
  • {@link User#isAccountNonLocked()} - *
  • {@link User#isCredentialsNonExpired()} - *
  • {@link User#isEnabled()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - User actualUser = new User(); - actualUser.setPassword("iloveyou"); - actualUser.setUsername("janedoe"); - String actualPassword = actualUser.getPassword(); - String actualUsername = actualUser.getUsername(); - boolean actualIsAccountNonExpiredResult = actualUser.isAccountNonExpired(); - boolean actualIsAccountNonLockedResult = actualUser.isAccountNonLocked(); - boolean actualIsCredentialsNonExpiredResult = actualUser.isCredentialsNonExpired(); - - // Assert - assertEquals("iloveyou", actualPassword); - assertEquals("janedoe", actualUsername); - assertTrue(actualIsAccountNonExpiredResult); - assertTrue(actualIsAccountNonLockedResult); - assertTrue(actualIsCredentialsNonExpiredResult); - assertTrue(actualUser.isEnabled()); - } + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link User#setPassword(String)} + *
  • {@link User#setUsername(String)} + *
  • {@link User#getPassword()} + *
  • {@link User#getUsername()} + *
  • {@link User#isAccountNonExpired()} + *
  • {@link User#isAccountNonLocked()} + *
  • {@link User#isCredentialsNonExpired()} + *
  • {@link User#isEnabled()} + *
+ */ + @Test + public void testGettersAndSetters2() { + // Arrange + User user = new User(); + + // Act + user.setPassword("abc"); + user.setUsername("Smith"); + String actualPassword = user.getPassword(); + String actualUsername = user.getUsername(); + boolean actualIsAccountNonExpiredResult = user.isAccountNonExpired(); + boolean actualIsAccountNonLockedResult = user.isAccountNonLocked(); + boolean actualIsCredentialsNonExpiredResult = user.isCredentialsNonExpired(); + + // Assert + assertEquals("Smith", actualUsername); + assertEquals("abc", actualPassword); + assertTrue(actualIsAccountNonExpiredResult); + assertTrue(actualIsAccountNonLockedResult); + assertTrue(actualIsCredentialsNonExpiredResult); + assertTrue(user.isEnabled()); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link User#setPassword(String)} + *
  • {@link User#setUsername(String)} + *
  • {@link User#getPassword()} + *
  • {@link User#getUsername()} + *
  • {@link User#isAccountNonExpired()} + *
  • {@link User#isAccountNonLocked()} + *
  • {@link User#isCredentialsNonExpired()} + *
  • {@link User#isEnabled()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + User user = new User(); + + // Act + user.setPassword("iloveyou"); + user.setUsername("janedoe"); + String actualPassword = user.getPassword(); + String actualUsername = user.getUsername(); + boolean actualIsAccountNonExpiredResult = user.isAccountNonExpired(); + boolean actualIsAccountNonLockedResult = user.isAccountNonLocked(); + boolean actualIsCredentialsNonExpiredResult = user.isCredentialsNonExpired(); + + // Assert + assertEquals("iloveyou", actualPassword); + assertEquals("janedoe", actualUsername); + assertTrue(actualIsAccountNonExpiredResult); + assertTrue(actualIsAccountNonLockedResult); + assertTrue(actualIsCredentialsNonExpiredResult); + assertTrue(user.isEnabled()); + } + + /** + * Test {@link User#getAuthorities()}. + *

+ * Method under test: {@link User#getAuthorities()} + */ + @Test + public void testGetAuthorities() { + // Arrange, Act and Assert + assertNull((new User()).getAuthorities()); + } } diff --git a/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java b/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java deleted file mode 100644 index a9c93838..00000000 --- a/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.piggymetrics.auth.repository; - -import com.piggymetrics.auth.domain.User; -import com.piggymetrics.auth.service.security.MongoUserDetailsService; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration; -import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Optional; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -@RunWith(SpringRunner.class) -@DataMongoTest -public class UserRepositoryTest { - - @Autowired - private UserRepository repository; - - @Test - public void shouldSaveAndFindUserByName() { - - User user = new User(); - user.setUsername("name"); - user.setPassword("password"); - repository.save(user); - - Optional found = repository.findById(user.getUsername()); - assertTrue(found.isPresent()); - assertEquals(user.getUsername(), found.get().getUsername()); - assertEquals(user.getPassword(), found.get().getPassword()); - } -} diff --git a/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceImplDiffblueTest.java b/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceImplDiffblueTest.java index 6f882b84..b40576ec 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceImplDiffblueTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceImplDiffblueTest.java @@ -1,113 +1,92 @@ package com.piggymetrics.auth.service; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import com.piggymetrics.auth.domain.User; import com.piggymetrics.auth.repository.UserRepository; -import java.util.Optional; -import org.junit.Rule; +import org.junit.Ignore; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.repository.CrudRepository; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration(classes = {UserServiceImpl.class}) @RunWith(SpringJUnit4ClassRunner.class) public class UserServiceImplDiffblueTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); + @MockBean + private UserRepository userRepository; - @MockBean - private UserRepository userRepository; + @Autowired + private UserServiceImpl userServiceImpl; - @Autowired - private UserServiceImpl userServiceImpl; + /** + * Test {@link UserServiceImpl#create(User)}. + *

+ * Method under test: {@link UserServiceImpl#create(User)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testCreate() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. - /** - * Test {@link UserServiceImpl#create(User)}. - *

- * Method under test: {@link UserServiceImpl#create(User)} - */ - @Test - public void testCreate() { - // Arrange - when(userRepository.findById(Mockito.any())) - .thenThrow(new IllegalArgumentException("new user has been created: {}")); + // Arrange + User user = new User(); + user.setPassword("abc"); + user.setUsername("Smith"); - User user = new User(); - user.setPassword("iloveyou"); - user.setUsername("janedoe"); + // Act + userServiceImpl.create(user); + } - // Act and Assert - thrown.expect(IllegalArgumentException.class); - userServiceImpl.create(user); - verify(userRepository).findById(eq("janedoe")); - } - - /** - * Test {@link UserServiceImpl#create(User)}. - *

    - *
  • Given {@link UserRepository} {@link CrudRepository#findById(Object)} - * return {@link Optional} with {@link User} (default constructor).
  • - *
- *

- * Method under test: {@link UserServiceImpl#create(User)} - */ - @Test - public void testCreate_givenUserRepositoryFindByIdReturnOptionalWithUser() { - // Arrange - User user = new User(); - user.setPassword("iloveyou"); - user.setUsername("janedoe"); - Optional ofResult = Optional.of(user); - when(userRepository.findById(Mockito.any())).thenReturn(ofResult); - - User user2 = new User(); - user2.setPassword("iloveyou"); - user2.setUsername("janedoe"); - - // Act and Assert - thrown.expect(IllegalArgumentException.class); - userServiceImpl.create(user2); - verify(userRepository).findById(eq("janedoe")); - } - - /** - * Test {@link UserServiceImpl#create(User)}. - *

    - *
  • Given {@link UserRepository} {@link CrudRepository#save(Object)} return - * {@link User} (default constructor).
  • - *
  • Then calls {@link CrudRepository#save(Object)}.
  • - *
- *

- * Method under test: {@link UserServiceImpl#create(User)} - */ - @Test - public void testCreate_givenUserRepositorySaveReturnUser_thenCallsSave() { - // Arrange - User user = new User(); - user.setPassword("iloveyou"); - user.setUsername("janedoe"); - when(userRepository.save(Mockito.any())).thenReturn(user); - Optional emptyResult = Optional.empty(); - when(userRepository.findById(Mockito.any())).thenReturn(emptyResult); - - User user2 = new User(); - user2.setPassword("iloveyou"); - user2.setUsername("janedoe"); - - // Act - userServiceImpl.create(user2); - - // Assert - verify(userRepository).findById(eq("janedoe")); - verify(userRepository).save(isA(User.class)); - } } diff --git a/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceTest.java b/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceTest.java deleted file mode 100644 index 8b22e763..00000000 --- a/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.piggymetrics.auth.service; - -import com.piggymetrics.auth.domain.User; -import com.piggymetrics.auth.repository.UserRepository; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -import java.util.Optional; - -import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; - -public class UserServiceTest { - - @InjectMocks - private UserServiceImpl userService; - - @Mock - private UserRepository repository; - - @Before - public void setup() { - initMocks(this); - } - - @Test - public void shouldCreateUser() { - - User user = new User(); - user.setUsername("name"); - user.setPassword("password"); - - userService.create(user); - verify(repository, times(1)).save(user); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailWhenUserAlreadyExists() { - - User user = new User(); - user.setUsername("name"); - user.setPassword("password"); - - when(repository.findById(user.getUsername())).thenReturn(Optional.of(new User())); - userService.create(user); - } -} diff --git a/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceDiffblueTest.java b/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceDiffblueTest.java index 7455ff5b..c4e260ca 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceDiffblueTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceDiffblueTest.java @@ -1,21 +1,11 @@ package com.piggymetrics.auth.service.security; -import static org.junit.Assert.assertSame; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import com.piggymetrics.auth.domain.User; import com.piggymetrics.auth.repository.UserRepository; -import java.util.Optional; -import org.junit.Rule; +import org.junit.Ignore; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.repository.CrudRepository; -import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -23,76 +13,75 @@ @ContextConfiguration(classes = {MongoUserDetailsService.class}) @RunWith(SpringJUnit4ClassRunner.class) public class MongoUserDetailsServiceDiffblueTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Autowired + private MongoUserDetailsService mongoUserDetailsService; - @Autowired - private MongoUserDetailsService mongoUserDetailsService; + @MockBean + private UserRepository userRepository; - @MockBean - private UserRepository userRepository; + /** + * Test {@link MongoUserDetailsService#loadUserByUsername(String)}. + *

+ * Method under test: {@link MongoUserDetailsService#loadUserByUsername(String)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testLoadUserByUsername() throws UsernameNotFoundException { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. - /** - * Test {@link MongoUserDetailsService#loadUserByUsername(String)}. - *

- * Method under test: {@link MongoUserDetailsService#loadUserByUsername(String)} - */ - @Test - public void testLoadUserByUsername() throws UsernameNotFoundException { - // Arrange - when(userRepository.findById(Mockito.any())).thenThrow(new UsernameNotFoundException("Msg")); + // Arrange and Act + mongoUserDetailsService.loadUserByUsername("Smith"); + } - // Act and Assert - thrown.expect(UsernameNotFoundException.class); - mongoUserDetailsService.loadUserByUsername("janedoe"); - verify(userRepository).findById(eq("janedoe")); - } - - /** - * Test {@link MongoUserDetailsService#loadUserByUsername(String)}. - *

    - *
  • Given {@link User} (default constructor) Password is - * {@code iloveyou}.
  • - *
  • Then return {@link User} (default constructor).
  • - *
- *

- * Method under test: {@link MongoUserDetailsService#loadUserByUsername(String)} - */ - @Test - public void testLoadUserByUsername_givenUserPasswordIsIloveyou_thenReturnUser() throws UsernameNotFoundException { - // Arrange - User user = new User(); - user.setPassword("iloveyou"); - user.setUsername("janedoe"); - Optional ofResult = Optional.of(user); - when(userRepository.findById(Mockito.any())).thenReturn(ofResult); - - // Act - UserDetails actualLoadUserByUsernameResult = mongoUserDetailsService.loadUserByUsername("janedoe"); - - // Assert - verify(userRepository).findById(eq("janedoe")); - assertSame(user, actualLoadUserByUsernameResult); - } - - /** - * Test {@link MongoUserDetailsService#loadUserByUsername(String)}. - *

    - *
  • Given {@link UserRepository} {@link CrudRepository#findById(Object)} - * return empty.
  • - *
- *

- * Method under test: {@link MongoUserDetailsService#loadUserByUsername(String)} - */ - @Test - public void testLoadUserByUsername_givenUserRepositoryFindByIdReturnEmpty() throws UsernameNotFoundException { - // Arrange - Optional emptyResult = Optional.empty(); - when(userRepository.findById(Mockito.any())).thenReturn(emptyResult); - - // Act and Assert - thrown.expect(UsernameNotFoundException.class); - mongoUserDetailsService.loadUserByUsername("janedoe"); - verify(userRepository).findById(eq("janedoe")); - } } diff --git a/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceTest.java b/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceTest.java deleted file mode 100644 index 80f71cee..00000000 --- a/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.piggymetrics.auth.service.security; - -import com.piggymetrics.auth.domain.User; -import com.piggymetrics.auth.repository.UserRepository; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UsernameNotFoundException; - -import java.util.Optional; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -public class MongoUserDetailsServiceTest { - - @InjectMocks - private MongoUserDetailsService service; - - @Mock - private UserRepository repository; - - @Before - public void setup() { - initMocks(this); - } - - @Test - public void shouldLoadByUsernameWhenUserExists() { - - final User user = new User(); - - when(repository.findById(any())).thenReturn(Optional.of(user)); - UserDetails loaded = service.loadUserByUsername("name"); - - assertEquals(user, loaded); - } - - @Test(expected = UsernameNotFoundException.class) - public void shouldFailToLoadByUsernameWhenUserNotExists() { - service.loadUserByUsername("name"); - } -} \ No newline at end of file diff --git a/combined-report.json b/combined-report.json deleted file mode 100644 index ae6588ba..00000000 --- a/combined-report.json +++ /dev/null @@ -1,104 +0,0 @@ -{ - "version" : "2025.01.01-2348203-licensed", - "totalTime" : 1714.3880000000001, - "environmentDetectionTime" : 5.387, - "indexingTime" : 3.357, - "entryPointsTime" : 5.112000000000001, - "generationTime" : 1127.228, - "timeToFirstTest" : 776.1339999999999, - "timeToLastTest" : 1434.031, - "verificationTime" : 102.903, - "validationTime" : 114.842, - "summary" : { - "classesCount" : 75, - "methodsCount" : 362, - "cumulativeDiffblueTestCount" : 85, - "cumulativeManualTestCount" : 57, - "completeTestCount" : 82, - "incompleteTestCount" : 0, - "skeletonTestCount" : 0, - "totalPhysicalLineCount" : 1927, - "perMethodTestability" : { - "T000" : 120, - "T001" : 61, - "T002" : 52, - "T003" : 17, - "T005" : 39, - "T006" : 9, - "T010" : 19, - "T012" : 35, - "T020" : 3, - "T033" : 7 - }, - "perMethodOutcome" : { - "E052" : 49, - "R000" : 168, - "R002" : 8, - "R004" : 6, - "R011" : 1, - "R013" : 9, - "T003" : 17, - "T005" : 34, - "T006" : 9, - "T010" : 19, - "T012" : 35, - "T033" : 7 - }, - "perTestOutcome" : { - "R000" : 82 - }, - "perTestValidation" : { - "V000" : 82 - } - }, - "coverageMetrics" : { - "branchCoveragePercent" : "36.17%", - "classesWithIncompleteInstructionCoverage" : [ - "com.piggymetrics.auth.AuthApplication", - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices", - "com.piggymetrics.statistics.StatisticsApplication", - "com.piggymetrics.statistics.repository.converter.DataPointIdReaderConverter", - "com.piggymetrics.statistics.service.ExchangeRatesServiceImpl", - "com.piggymetrics.notification.domain.Frequency", - "com.piggymetrics.notification.NotificationServiceApplication", - "com.piggymetrics.notification.controller.RecipientController", - "com.piggymetrics.notification.service.NotificationServiceImpl", - "com.piggymetrics.notification.service.EmailServiceImpl", - "com.piggymetrics.notification.service.RecipientServiceImpl", - "com.piggymetrics.account.controller.ErrorHandler", - "com.piggymetrics.account.service.AccountServiceImpl", - "com.piggymetrics.account.service.security.CustomUserInfoTokenServices", - "com.piggymetrics.account.client.StatisticsServiceClientFallback", - "com.piggymetrics.account.AccountApplication", - "com.piggymetrics.config.ConfigApplication" - ], - "complexCoveredLines" : 153, - "complexLineCoveragePercent" : "76.12%", - "complexityThreshold" : 10, - "coveredBranches" : 17, - "coveredComplexity" : 77, - "coveredLines" : 459, - "lineCoveragePercent" : "76.5%", - "totalBranches" : 47, - "totalComplexLines" : 201, - "totalComplexity" : 103, - "totalLines" : 600 - }, - "piTestMetrics" : { - "mutationsKilled" : 94, - "mutationsKilledPercent" : "45.85%", - "mutationsNoCoverage" : 85, - "mutationsSurvived" : 26, - "mutationsTotal" : 205 - }, - "testDiffStatSummary" : { - "files" : 0, - "insertions" : 0, - "deletions" : 0 - }, - "diffblueTestDiffStatSummary" : { - "files" : 0, - "insertions" : 0, - "deletions" : 0 - } -} \ No newline at end of file diff --git a/config/pom.xml b/config/pom.xml index 71fb54f5..15b57aaa 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -26,7 +26,7 @@ org.jacoco org.jacoco.agent - 0.8.2 + 0.8.11 test runtime @@ -46,6 +46,24 @@ spring-test test + + org.mockito + mockito-core + 4.1.0 + test + + + org.springframework + spring-core + 6.0.11 + compile + + + org.springframework.boot + spring-boot + 2.5.1 + compile + @@ -71,7 +89,7 @@ org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.11 diff --git a/config/report.json b/config/report.json deleted file mode 100644 index 2d884728..00000000 --- a/config/report.json +++ /dev/null @@ -1,119 +0,0 @@ -{ - "meta" : { - "reportVersion" : "2.6" - }, - "run" : { - "version" : "2025.01.01-2348203-licensed", - "creationTimestamp" : "2025-01-13T16:27:21.091Z", - "command" : "dcover create --batch --report-file=report.json --coverage-reports --spring-integration-tests --verbose --exclude=com.piggymetrics.notification.service.NotificationServiceImpl. --working-directory=config", - "totalTime" : 86.294, - "environmentDetectionTime" : 0.508, - "indexingTime" : 0.361, - "entryPointsTime" : 0.485, - "generationTime" : 61.748, - "timeToFirstTest" : 86.4, - "timeToLastTest" : 80.709, - "indexQueryTime" : 10.522, - "verificationTime" : 0.0, - "validationTime" : 0.0 - }, - "codes" : { - "R013" : "No inputs found that don't throw a trivial exception", - "T000" : "Method eligible for test creation", - "T005" : "Trivial constructor", - "T006" : "Main method" - }, - "summary" : { - "classesCount" : 2, - "methodsCount" : 4, - "cumulativeDiffblueTestCount" : 1, - "cumulativeManualTestCount" : 0, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "skeletonTestCount" : 0, - "totalPhysicalLineCount" : 29, - "perMethodTestability" : { - "T000" : 2, - "T005" : 1, - "T006" : 1 - }, - "perMethodOutcome" : { - "R013" : 1, - "T005" : 2, - "T006" : 1 - } - }, - "classes" : { - "com.piggymetrics.config.ConfigApplication" : { - "methodsCount" : 2, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T005" : 1, - "T006" : 1 - }, - "perMethodOutcome" : { - "T005" : 1, - "T006" : 1 - } - }, - "com.piggymetrics.config.SecurityConfig" : { - "methodsCount" : 2, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 2 - }, - "perMethodOutcome" : { - "R013" : 1, - "T005" : 1 - } - } - }, - "methods" : { - "com.piggymetrics.config.ConfigApplication.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 9 - ] - }, - "com.piggymetrics.config.ConfigApplication.main:([Ljava/lang/String;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T006", - "perMethodOutcome" : "T006", - "lineNumbers" : [ - 12, - 13 - ] - }, - "com.piggymetrics.config.SecurityConfig.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 11 - ] - }, - "com.piggymetrics.config.SecurityConfig.configure:(Lorg/springframework/security/config/annotation/web/builders/HttpSecurity;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R013", - "lineNumbers" : [ - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 23 - ] - } - } -} \ No newline at end of file diff --git a/config/src/test/java/com/piggymetrics/config/SecurityConfigDiffblueTest.java b/config/src/test/java/com/piggymetrics/config/SecurityConfigDiffblueTest.java new file mode 100644 index 00000000..fa09a64b --- /dev/null +++ b/config/src/test/java/com/piggymetrics/config/SecurityConfigDiffblueTest.java @@ -0,0 +1,99 @@ +package com.piggymetrics.config; + +import java.util.HashMap; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.security.authentication.AuthenticationTrustResolver; +import org.springframework.security.config.annotation.ObjectPostProcessor; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.web.accept.ContentNegotiationStrategy; + +@ContextConfiguration(classes = {SecurityConfig.class, AuthenticationConfiguration.class, + ContentNegotiationStrategy.class, AuthenticationTrustResolver.class}) +@RunWith(SpringJUnit4ClassRunner.class) +public class SecurityConfigDiffblueTest { + @Autowired + private ApplicationContext applicationContext; + + @Autowired + private ObjectPostProcessor objectPostProcessor; + + @Autowired + private SecurityConfig securityConfig; + + /** + * Test {@link SecurityConfig#configure(HttpSecurity)} with {@code http}. + *

+ * Method under test: {@link SecurityConfig#configure(HttpSecurity)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConfigureWithHttp() throws Exception { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + AuthenticationManagerBuilder authenticationBuilder = new AuthenticationManagerBuilder(objectPostProcessor); + + // Act + securityConfig.configure(new HttpSecurity(objectPostProcessor, authenticationBuilder, new HashMap<>())); + } +} diff --git a/gateway/pom.xml b/gateway/pom.xml index c62aa85a..55dd160f 100644 --- a/gateway/pom.xml +++ b/gateway/pom.xml @@ -42,7 +42,7 @@ org.jacoco org.jacoco.agent - 0.8.2 + 0.8.11 test runtime @@ -52,6 +52,24 @@ 4.12 test + + org.mockito + mockito-core + 4.1.0 + test + + + org.springframework + spring-core + 6.0.11 + compile + + + org.springframework.boot + spring-boot + 2.5.1 + compile + @@ -77,7 +95,7 @@ org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.11 diff --git a/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java b/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java deleted file mode 100644 index 13d17592..00000000 --- a/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.piggymetrics.gateway; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class GatewayApplicationTests { - - @Test - public void contextLoads() { - } - - @Test - public void fire() { - - } - -} diff --git a/gateway/report.json b/monitoring/.diffblue/reports/report.json similarity index 55% rename from gateway/report.json rename to monitoring/.diffblue/reports/report.json index d54bbb75..976c5db9 100644 --- a/gateway/report.json +++ b/monitoring/.diffblue/reports/report.json @@ -3,17 +3,17 @@ "reportVersion" : "2.6" }, "run" : { - "version" : "2025.01.01-2348203-licensed", - "creationTimestamp" : "2025-01-13T16:32:52.924Z", - "command" : "dcover create --batch --report-file=report.json --coverage-reports --spring-integration-tests --verbose --exclude=com.piggymetrics.notification.service.NotificationServiceImpl. --working-directory=gateway", - "totalTime" : 55.827, - "environmentDetectionTime" : 0.41, - "indexingTime" : 0.473, - "entryPointsTime" : 0.379, - "generationTime" : 21.583, - "timeToFirstTest" : 55.931, - "timeToLastTest" : 42.947, - "indexQueryTime" : 9.32, + "version" : "2024.10.22-TG-22184-ExtraLogging-b801b56-licensed", + "creationTimestamp" : "2025-01-25T18:19:09.1971473Z", + "command" : "dcover create ", + "totalTime" : 96.94, + "environmentDetectionTime" : 0.326, + "indexingTime" : 0.248, + "entryPointsTime" : 0.298, + "generationTime" : 35.063, + "timeToFirstTest" : 97.073, + "timeToLastTest" : 62.082, + "indexQueryTime" : 5.0360000000000005, "verificationTime" : 0.0, "validationTime" : 0.0 }, @@ -24,12 +24,12 @@ "summary" : { "classesCount" : 1, "methodsCount" : 2, - "cumulativeDiffblueTestCount" : 1, - "cumulativeManualTestCount" : 2, + "cumulativeDiffblueTestCount" : 0, + "cumulativeManualTestCount" : 0, "completeTestCount" : 0, "incompleteTestCount" : 0, "skeletonTestCount" : 0, - "totalPhysicalLineCount" : 13, + "totalPhysicalLineCount" : 0, "perMethodTestability" : { "T005" : 1, "T006" : 1 @@ -40,7 +40,7 @@ } }, "classes" : { - "com.piggymetrics.gateway.GatewayApplication" : { + "com.piggymetrics.monitoring.MonitoringApplication" : { "methodsCount" : 2, "completeTestCount" : 0, "incompleteTestCount" : 0, @@ -55,23 +55,23 @@ } }, "methods" : { - "com.piggymetrics.gateway.GatewayApplication.:()V" : { + "com.piggymetrics.monitoring.MonitoringApplication.:()V" : { "completeTestCount" : 0, "incompleteTestCount" : 0, "perMethodTestability" : "T005", "perMethodOutcome" : "T005", "lineNumbers" : [ - 11 + 9 ] }, - "com.piggymetrics.gateway.GatewayApplication.main:([Ljava/lang/String;)V" : { + "com.piggymetrics.monitoring.MonitoringApplication.main:([Ljava/lang/String;)V" : { "completeTestCount" : 0, "incompleteTestCount" : 0, "perMethodTestability" : "T006", "perMethodOutcome" : "T006", "lineNumbers" : [ - 14, - 15 + 12, + 13 ] } } diff --git a/monitoring/pom.xml b/monitoring/pom.xml index d3b90109..e0a4e0ab 100644 --- a/monitoring/pom.xml +++ b/monitoring/pom.xml @@ -30,7 +30,7 @@ org.jacoco org.jacoco.agent - 0.8.2 + 0.8.11 test runtime @@ -40,6 +40,25 @@ 4.12 test + + org.mockito + mockito-core + 4.1.0 + test + + + org.springframework + spring-core + 6.0.11 + compile + + + org.springframework.boot + spring-boot + 2.5.1 + compile + + @@ -65,7 +84,7 @@ org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.11 diff --git a/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java b/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java deleted file mode 100644 index b71493e7..00000000 --- a/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.piggymetrics.monitoring; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class MonitoringApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/notification-service/pom.xml b/notification-service/pom.xml index 1f324f04..24528659 100644 --- a/notification-service/pom.xml +++ b/notification-service/pom.xml @@ -14,6 +14,10 @@ + + io.projectreactor + reactor-test + org.springframework.cloud spring-cloud-starter-oauth2 @@ -83,7 +87,7 @@ org.jacoco org.jacoco.agent - 0.8.2 + 0.8.11 test runtime @@ -93,6 +97,24 @@ 4.12 test + + org.mockito + mockito-core + 4.1.0 + test + + + org.springframework + spring-core + 6.0.11 + compile + + + org.springframework.boot + spring-boot + 2.5.1 + compile + @@ -118,7 +140,7 @@ org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.11 diff --git a/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationDiffblueTest.java new file mode 100644 index 00000000..34a77147 --- /dev/null +++ b/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationDiffblueTest.java @@ -0,0 +1,83 @@ +package com.piggymetrics.notification; + +import com.piggymetrics.notification.NotificationServiceApplication.CustomConversionsConfig; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@ContextConfiguration(classes = {NotificationServiceApplication.CustomConversionsConfig.class}) +@RunWith(SpringJUnit4ClassRunner.class) +public class NotificationServiceApplicationDiffblueTest { + @Autowired + private NotificationServiceApplication.CustomConversionsConfig customConversionsConfig; + + /** + * Test CustomConversionsConfig + * {@link CustomConversionsConfig#customConversions()}. + *

+ * Method under test: + * {@link NotificationServiceApplication.CustomConversionsConfig#customConversions()} + */ + @Test + @Ignore("TODO: Complete this test") + public void testCustomConversionsConfigCustomConversions() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + customConversionsConfig.customConversions(); + } +} diff --git a/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java b/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java deleted file mode 100644 index ab77ed0f..00000000 --- a/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.piggymetrics.notification; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class NotificationServiceApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/notification-service/src/test/java/com/piggymetrics/notification/config/ResourceServerConfigDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/config/ResourceServerConfigDiffblueTest.java deleted file mode 100644 index c012d23c..00000000 --- a/notification-service/src/test/java/com/piggymetrics/notification/config/ResourceServerConfigDiffblueTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.piggymetrics.notification.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import com.piggymetrics.notification.repository.RecipientRepository; -import de.flapdoodle.embed.mongo.MongodExecutable; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; -import org.springframework.http.client.InterceptingClientHttpRequestFactory; -import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; -import org.springframework.security.oauth2.client.OAuth2RestTemplate; -import org.springframework.security.oauth2.client.http.OAuth2ErrorHandler; -import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; -import org.springframework.security.oauth2.common.AuthenticationScheme; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.web.util.DefaultUriBuilderFactory; - -@SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) -public class ResourceServerConfigDiffblueTest { - @MockBean - private MongodExecutable mongodExecutable; - - @MockBean - private RecipientRepository recipientRepository; - - @Autowired - private ResourceServerConfig resourceServerConfig; - - /** - * Test {@link ResourceServerConfig#clientCredentialsResourceDetails()}. - *

- * Method under test: - * {@link ResourceServerConfig#clientCredentialsResourceDetails()} - */ - @Test - public void testClientCredentialsResourceDetails() { - // Arrange and Act - ClientCredentialsResourceDetails actualClientCredentialsResourceDetailsResult = resourceServerConfig - .clientCredentialsResourceDetails(); - - // Assert - assertEquals("access_token", actualClientCredentialsResourceDetailsResult.getTokenName()); - assertEquals("client_credentials", actualClientCredentialsResourceDetailsResult.getGrantType()); - assertNull(actualClientCredentialsResourceDetailsResult.getAccessTokenUri()); - assertNull(actualClientCredentialsResourceDetailsResult.getClientId()); - assertNull(actualClientCredentialsResourceDetailsResult.getClientSecret()); - assertNull(actualClientCredentialsResourceDetailsResult.getId()); - assertNull(actualClientCredentialsResourceDetailsResult.getScope()); - assertEquals(AuthenticationScheme.header, actualClientCredentialsResourceDetailsResult.getAuthenticationScheme()); - assertEquals(AuthenticationScheme.header, - actualClientCredentialsResourceDetailsResult.getClientAuthenticationScheme()); - assertFalse(actualClientCredentialsResourceDetailsResult.isAuthenticationRequired()); - assertFalse(actualClientCredentialsResourceDetailsResult.isScoped()); - assertTrue(actualClientCredentialsResourceDetailsResult.isClientOnly()); - } - - /** - * Test {@link ResourceServerConfig#oauth2FeignRequestInterceptor()}. - *

- * Method under test: - * {@link ResourceServerConfig#oauth2FeignRequestInterceptor()} - */ - @Test - public void testOauth2FeignRequestInterceptor() { - // Arrange, Act and Assert - assertTrue(resourceServerConfig.oauth2FeignRequestInterceptor() instanceof OAuth2FeignRequestInterceptor); - } - - /** - * Test {@link ResourceServerConfig#clientCredentialsRestTemplate()}. - *

- * Method under test: - * {@link ResourceServerConfig#clientCredentialsRestTemplate()} - */ - @Test - public void testClientCredentialsRestTemplate() { - // Arrange and Act - OAuth2RestTemplate actualClientCredentialsRestTemplateResult = resourceServerConfig.clientCredentialsRestTemplate(); - - // Assert - assertTrue( - actualClientCredentialsRestTemplateResult.getRequestFactory() instanceof InterceptingClientHttpRequestFactory); - assertTrue( - actualClientCredentialsRestTemplateResult.getOAuth2ClientContext() instanceof DefaultOAuth2ClientContext); - assertTrue(actualClientCredentialsRestTemplateResult.getErrorHandler() instanceof OAuth2ErrorHandler); - assertTrue(actualClientCredentialsRestTemplateResult.getResource() instanceof ClientCredentialsResourceDetails); - assertTrue(actualClientCredentialsRestTemplateResult.getUriTemplateHandler() instanceof DefaultUriBuilderFactory); - assertEquals(1, actualClientCredentialsRestTemplateResult.getInterceptors().size()); - assertEquals(7, actualClientCredentialsRestTemplateResult.getMessageConverters().size()); - } -} diff --git a/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerDiffblueTest.java index baf1e502..7b527e7c 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerDiffblueTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerDiffblueTest.java @@ -1,57 +1,67 @@ package com.piggymetrics.notification.controller; -import static org.mockito.Mockito.when; import com.piggymetrics.notification.domain.Recipient; -import com.piggymetrics.notification.service.RecipientService; -import com.sun.security.auth.UserPrincipal; + import java.security.Principal; -import java.util.HashMap; + +import org.junit.Ignore; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -@ContextConfiguration(classes = {RecipientController.class}) -@RunWith(SpringJUnit4ClassRunner.class) + public class RecipientControllerDiffblueTest { - @Autowired - private RecipientController recipientController; - - @MockBean - private RecipientService recipientService; - - /** - * Test {@link RecipientController#getCurrentNotificationsSettings(Principal)}. - *

- * Method under test: - * {@link RecipientController#getCurrentNotificationsSettings(Principal)} - */ - @Test - public void testGetCurrentNotificationsSettings() throws Exception { - // Arrange - Recipient recipient = new Recipient(); - recipient.setAccountName("Dr Jane Doe"); - recipient.setEmail("jane.doe@example.org"); - recipient.setScheduledNotifications(new HashMap<>()); - when(recipientService.findByAccountName(Mockito.any())).thenReturn(recipient); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/recipients/current"); - requestBuilder.principal(new UserPrincipal("principal")); - - // Act and Assert - MockMvcBuilders.standaloneSetup(recipientController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"accountName\":\"Dr Jane Doe\",\"email\":\"jane.doe@example.org\",\"scheduledNotifications\":{}}")); - } + /** + * Test {@link RecipientController#getCurrentNotificationsSettings(Principal)}. + *

+ * Method under test: + * {@link RecipientController#getCurrentNotificationsSettings(Principal)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testGetCurrentNotificationsSettings() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Unable to load class. + // Class: jakarta.servlet.ServletContext + // Please check that the class is available on your test runtime classpath. + // See https://diff.blue/R005 to resolve this issue. + + // Arrange + // TODO: Populate arranged inputs + RecipientController recipientController = null; + Principal principal = null; + + // Act + Object actualCurrentNotificationsSettings = recipientController.getCurrentNotificationsSettings(principal); + + // Assert + // TODO: Add assertions on result + } + + /** + * Test + * {@link RecipientController#saveCurrentNotificationsSettings(Principal, Recipient)}. + *

+ * Method under test: + * {@link RecipientController#saveCurrentNotificationsSettings(Principal, Recipient)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testSaveCurrentNotificationsSettings() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Unable to load class. + // Class: jakarta.servlet.ServletContext + // Please check that the class is available on your test runtime classpath. + // See https://diff.blue/R005 to resolve this issue. + + // Arrange + // TODO: Populate arranged inputs + RecipientController recipientController = null; + Principal principal = null; + Recipient recipient = null; + + // Act + Object actualSaveCurrentNotificationsSettingsResult = recipientController + .saveCurrentNotificationsSettings(principal, recipient); + + // Assert + // TODO: Add assertions on result + } } diff --git a/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java b/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java deleted file mode 100644 index c1433ca3..00000000 --- a/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.piggymetrics.notification.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.ImmutableMap; -import com.piggymetrics.notification.domain.Frequency; -import com.piggymetrics.notification.domain.NotificationSettings; -import com.piggymetrics.notification.domain.NotificationType; -import com.piggymetrics.notification.domain.Recipient; -import com.piggymetrics.notification.service.RecipientService; -import com.sun.security.auth.UserPrincipal; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class RecipientControllerTest { - - private static final ObjectMapper mapper = new ObjectMapper(); - - @InjectMocks - private RecipientController recipientController; - - @Mock - private RecipientService recipientService; - - private MockMvc mockMvc; - - @Before - public void setup() { - initMocks(this); - this.mockMvc = MockMvcBuilders.standaloneSetup(recipientController).build(); - } - - @Test - public void shouldSaveCurrentRecipientSettings() throws Exception { - - Recipient recipient = getStubRecipient(); - String json = mapper.writeValueAsString(recipient); - - mockMvc.perform(put("/recipients/current").principal(new UserPrincipal(recipient.getAccountName())).contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()); - } - - @Test - public void shouldGetCurrentRecipientSettings() throws Exception { - - Recipient recipient = getStubRecipient(); - when(recipientService.findByAccountName(recipient.getAccountName())).thenReturn(recipient); - - mockMvc.perform(get("/recipients/current").principal(new UserPrincipal(recipient.getAccountName()))) - .andExpect(jsonPath("$.accountName").value(recipient.getAccountName())) - .andExpect(status().isOk()); - } - - private Recipient getStubRecipient() { - - NotificationSettings remind = new NotificationSettings(); - remind.setActive(true); - remind.setFrequency(Frequency.WEEKLY); - remind.setLastNotified(null); - - NotificationSettings backup = new NotificationSettings(); - backup.setActive(false); - backup.setFrequency(Frequency.MONTHLY); - backup.setLastNotified(null); - - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - recipient.setEmail("test@test.com"); - recipient.setScheduledNotifications(ImmutableMap.of( - NotificationType.BACKUP, backup, - NotificationType.REMIND, remind - )); - - return recipient; - } -} \ No newline at end of file diff --git a/notification-service/src/test/java/com/piggymetrics/notification/domain/FrequencyDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/domain/FrequencyDiffblueTest.java deleted file mode 100644 index 6468d680..00000000 --- a/notification-service/src/test/java/com/piggymetrics/notification/domain/FrequencyDiffblueTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.piggymetrics.notification.domain; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; - -public class FrequencyDiffblueTest { - /** - * Test {@link Frequency#getDays()}. - *

- * Method under test: {@link Frequency#getDays()} - */ - @Test - public void testGetDays() { - // Arrange, Act and Assert - assertEquals(7, Frequency.valueOf("WEEKLY").getDays()); - } - - /** - * Test {@link Frequency#withDays(int)}. - *

    - *
  • When seven.
  • - *
  • Then return {@code WEEKLY}.
  • - *
- *

- * Method under test: {@link Frequency#withDays(int)} - */ - @Test - public void testWithDays_whenSeven_thenReturnWeekly() { - // Arrange, Act and Assert - assertEquals(Frequency.WEEKLY, Frequency.withDays(7)); - } -} diff --git a/notification-service/src/test/java/com/piggymetrics/notification/domain/NotificationSettingsDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/domain/NotificationSettingsDiffblueTest.java index 34338b69..a21aa5e8 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/domain/NotificationSettingsDiffblueTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/domain/NotificationSettingsDiffblueTest.java @@ -3,40 +3,43 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; + import java.time.LocalDate; import java.time.ZoneOffset; import java.util.Date; + import org.junit.Test; public class NotificationSettingsDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link NotificationSettings} - *
  • {@link NotificationSettings#setActive(Boolean)} - *
  • {@link NotificationSettings#setFrequency(Frequency)} - *
  • {@link NotificationSettings#setLastNotified(Date)} - *
  • {@link NotificationSettings#getActive()} - *
  • {@link NotificationSettings#getFrequency()} - *
  • {@link NotificationSettings#getLastNotified()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - NotificationSettings actualNotificationSettings = new NotificationSettings(); - actualNotificationSettings.setActive(true); - actualNotificationSettings.setFrequency(Frequency.WEEKLY); - Date lastNotified = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); - actualNotificationSettings.setLastNotified(lastNotified); - Boolean actualActive = actualNotificationSettings.getActive(); - Frequency actualFrequency = actualNotificationSettings.getFrequency(); + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link NotificationSettings#setActive(Boolean)} + *
  • {@link NotificationSettings#setFrequency(Frequency)} + *
  • {@link NotificationSettings#setLastNotified(Date)} + *
  • {@link NotificationSettings#getActive()} + *
  • {@link NotificationSettings#getFrequency()} + *
  • {@link NotificationSettings#getLastNotified()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + NotificationSettings notificationSettings = new NotificationSettings(); + + // Act + notificationSettings.setActive(true); + notificationSettings.setFrequency(Frequency.WEEKLY); + Date lastNotified = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + notificationSettings.setLastNotified(lastNotified); + Boolean actualActive = notificationSettings.getActive(); + Frequency actualFrequency = notificationSettings.getFrequency(); - // Assert - assertEquals(Frequency.WEEKLY, actualFrequency); - assertTrue(actualActive); - assertSame(lastNotified, actualNotificationSettings.getLastNotified()); - } + // Assert + assertEquals(Frequency.WEEKLY, actualFrequency); + assertTrue(actualActive); + assertSame(lastNotified, notificationSettings.getLastNotified()); + } } diff --git a/notification-service/src/test/java/com/piggymetrics/notification/domain/NotificationTypeDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/domain/NotificationTypeDiffblueTest.java deleted file mode 100644 index 33ecc0f4..00000000 --- a/notification-service/src/test/java/com/piggymetrics/notification/domain/NotificationTypeDiffblueTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.piggymetrics.notification.domain; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; - -public class NotificationTypeDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • {@link NotificationType#getAttachment()} - *
  • {@link NotificationType#getSubject()} - *
  • {@link NotificationType#getText()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange - NotificationType valueOfResult = NotificationType.valueOf("BACKUP"); - - // Act - String actualAttachment = valueOfResult.getAttachment(); - String actualSubject = valueOfResult.getSubject(); - - // Assert - assertEquals("backup.email.attachment", actualAttachment); - assertEquals("backup.email.subject", actualSubject); - assertEquals("backup.email.text", valueOfResult.getText()); - } -} diff --git a/notification-service/src/test/java/com/piggymetrics/notification/domain/RecipientDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/domain/RecipientDiffblueTest.java index 5144bcb9..6e1a620e 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/domain/RecipientDiffblueTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/domain/RecipientDiffblueTest.java @@ -3,45 +3,84 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; + import java.util.HashMap; import java.util.Map; + import org.junit.Test; public class RecipientDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link Recipient} - *
  • {@link Recipient#setAccountName(String)} - *
  • {@link Recipient#setEmail(String)} - *
  • {@link Recipient#setScheduledNotifications(Map)} - *
  • {@link Recipient#toString()} - *
  • {@link Recipient#getAccountName()} - *
  • {@link Recipient#getEmail()} - *
  • {@link Recipient#getScheduledNotifications()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - Recipient actualRecipient = new Recipient(); - actualRecipient.setAccountName("Dr Jane Doe"); - actualRecipient.setEmail("jane.doe@example.org"); - HashMap scheduledNotifications = new HashMap<>(); - actualRecipient.setScheduledNotifications(scheduledNotifications); - String actualToStringResult = actualRecipient.toString(); - String actualAccountName = actualRecipient.getAccountName(); - String actualEmail = actualRecipient.getEmail(); - Map actualScheduledNotifications = actualRecipient - .getScheduledNotifications(); - - // Assert - assertEquals("Dr Jane Doe", actualAccountName); - assertEquals("Recipient{accountName='Dr Jane Doe', email='jane.doe@example.org'}", actualToStringResult); - assertEquals("jane.doe@example.org", actualEmail); - assertTrue(actualScheduledNotifications.isEmpty()); - assertSame(scheduledNotifications, actualScheduledNotifications); - } + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Recipient#setAccountName(String)} + *
  • {@link Recipient#setEmail(String)} + *
  • {@link Recipient#setScheduledNotifications(Map)} + *
  • {@link Recipient#toString()} + *
  • {@link Recipient#getAccountName()} + *
  • {@link Recipient#getEmail()} + *
  • {@link Recipient#getScheduledNotifications()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + Recipient recipient = new Recipient(); + + // Act + recipient.setAccountName("Dr Jane Doe"); + recipient.setEmail("jane.doe@example.org"); + HashMap scheduledNotifications = new HashMap<>(); + recipient.setScheduledNotifications(scheduledNotifications); + String actualToStringResult = recipient.toString(); + String actualAccountName = recipient.getAccountName(); + String actualEmail = recipient.getEmail(); + Map actualScheduledNotifications = recipient.getScheduledNotifications(); + + // Assert + assertEquals("Dr Jane Doe", actualAccountName); + assertEquals("Recipient{accountName='Dr Jane Doe', email='jane.doe@example.org'}", actualToStringResult); + assertEquals("jane.doe@example.org", actualEmail); + assertTrue(actualScheduledNotifications.isEmpty()); + assertSame(scheduledNotifications, actualScheduledNotifications); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Recipient#setAccountName(String)} + *
  • {@link Recipient#setEmail(String)} + *
  • {@link Recipient#setScheduledNotifications(Map)} + *
  • {@link Recipient#toString()} + *
  • {@link Recipient#getAccountName()} + *
  • {@link Recipient#getEmail()} + *
  • {@link Recipient#getScheduledNotifications()} + *
+ */ + @Test + public void testGettersAndSetters2() { + // Arrange + Recipient recipient = new Recipient(); + + // Act + recipient.setAccountName("Smith"); + recipient.setEmail("jane.doe@example.org"); + HashMap scheduledNotifications = new HashMap<>(); + recipient.setScheduledNotifications(scheduledNotifications); + String actualToStringResult = recipient.toString(); + String actualAccountName = recipient.getAccountName(); + String actualEmail = recipient.getEmail(); + Map actualScheduledNotifications = recipient.getScheduledNotifications(); + + // Assert + assertEquals("Recipient{accountName='Smith', email='jane.doe@example.org'}", actualToStringResult); + assertEquals("Smith", actualAccountName); + assertEquals("jane.doe@example.org", actualEmail); + assertTrue(actualScheduledNotifications.isEmpty()); + assertSame(scheduledNotifications, actualScheduledNotifications); + } } diff --git a/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java b/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java deleted file mode 100644 index 0293fa6c..00000000 --- a/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.piggymetrics.notification.repository; - -import com.google.common.collect.ImmutableMap; -import com.piggymetrics.notification.domain.Frequency; -import com.piggymetrics.notification.domain.NotificationSettings; -import com.piggymetrics.notification.domain.NotificationType; -import com.piggymetrics.notification.domain.Recipient; -import org.apache.commons.lang.time.DateUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Date; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -@RunWith(SpringRunner.class) -@DataMongoTest -public class RecipientRepositoryTest { - - @Autowired - private RecipientRepository repository; - - @Test - public void shouldFindByAccountName() { - - NotificationSettings remind = new NotificationSettings(); - remind.setActive(true); - remind.setFrequency(Frequency.WEEKLY); - remind.setLastNotified(new Date(0)); - - NotificationSettings backup = new NotificationSettings(); - backup.setActive(false); - backup.setFrequency(Frequency.MONTHLY); - backup.setLastNotified(new Date()); - - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - recipient.setEmail("test@test.com"); - recipient.setScheduledNotifications(ImmutableMap.of( - NotificationType.BACKUP, backup, - NotificationType.REMIND, remind - )); - - repository.save(recipient); - - Recipient found = repository.findByAccountName(recipient.getAccountName()); - assertEquals(recipient.getAccountName(), found.getAccountName()); - assertEquals(recipient.getEmail(), found.getEmail()); - - assertEquals(recipient.getScheduledNotifications().get(NotificationType.BACKUP).getActive(), - found.getScheduledNotifications().get(NotificationType.BACKUP).getActive()); - assertEquals(recipient.getScheduledNotifications().get(NotificationType.BACKUP).getFrequency(), - found.getScheduledNotifications().get(NotificationType.BACKUP).getFrequency()); - assertEquals(recipient.getScheduledNotifications().get(NotificationType.BACKUP).getLastNotified(), - found.getScheduledNotifications().get(NotificationType.BACKUP).getLastNotified()); - - assertEquals(recipient.getScheduledNotifications().get(NotificationType.REMIND).getActive(), - found.getScheduledNotifications().get(NotificationType.REMIND).getActive()); - assertEquals(recipient.getScheduledNotifications().get(NotificationType.REMIND).getFrequency(), - found.getScheduledNotifications().get(NotificationType.REMIND).getFrequency()); - assertEquals(recipient.getScheduledNotifications().get(NotificationType.REMIND).getLastNotified(), - found.getScheduledNotifications().get(NotificationType.REMIND).getLastNotified()); - } - - @Test - public void shouldFindReadyForRemindWhenFrequencyIsWeeklyAndLastNotifiedWas8DaysAgo() { - - NotificationSettings remind = new NotificationSettings(); - remind.setActive(true); - remind.setFrequency(Frequency.WEEKLY); - remind.setLastNotified(DateUtils.addDays(new Date(), -8)); - - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - recipient.setEmail("test@test.com"); - recipient.setScheduledNotifications(ImmutableMap.of( - NotificationType.REMIND, remind - )); - - repository.save(recipient); - - List found = repository.findReadyForRemind(); - assertFalse(found.isEmpty()); - } - - @Test - public void shouldNotFindReadyForRemindWhenFrequencyIsWeeklyAndLastNotifiedWasYesterday() { - - NotificationSettings remind = new NotificationSettings(); - remind.setActive(true); - remind.setFrequency(Frequency.WEEKLY); - remind.setLastNotified(DateUtils.addDays(new Date(), -1)); - - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - recipient.setEmail("test@test.com"); - recipient.setScheduledNotifications(ImmutableMap.of( - NotificationType.REMIND, remind - )); - - repository.save(recipient); - - List found = repository.findReadyForRemind(); - assertTrue(found.isEmpty()); - } - - @Test - public void shouldNotFindReadyForRemindWhenNotificationIsNotActive() { - - NotificationSettings remind = new NotificationSettings(); - remind.setActive(false); - remind.setFrequency(Frequency.WEEKLY); - remind.setLastNotified(DateUtils.addDays(new Date(), -30)); - - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - recipient.setEmail("test@test.com"); - recipient.setScheduledNotifications(ImmutableMap.of( - NotificationType.REMIND, remind - )); - - repository.save(recipient); - - List found = repository.findReadyForRemind(); - assertTrue(found.isEmpty()); - } - - @Test - public void shouldNotFindReadyForBackupWhenFrequencyIsQuaterly() { - - NotificationSettings remind = new NotificationSettings(); - remind.setActive(true); - remind.setFrequency(Frequency.QUARTERLY); - remind.setLastNotified(DateUtils.addDays(new Date(), -91)); - - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - recipient.setEmail("test@test.com"); - recipient.setScheduledNotifications(ImmutableMap.of( - NotificationType.BACKUP, remind - )); - - repository.save(recipient); - - List found = repository.findReadyForBackup(); - assertFalse(found.isEmpty()); - } -} \ No newline at end of file diff --git a/notification-service/src/test/java/com/piggymetrics/notification/repository/converter/FrequencyReaderConverterDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/repository/converter/FrequencyReaderConverterDiffblueTest.java index 7843e7fb..f6098069 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/repository/converter/FrequencyReaderConverterDiffblueTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/repository/converter/FrequencyReaderConverterDiffblueTest.java @@ -1,7 +1,9 @@ package com.piggymetrics.notification.repository.converter; import static org.junit.Assert.assertEquals; + import com.piggymetrics.notification.domain.Frequency; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -11,21 +13,90 @@ @ContextConfiguration(classes = {FrequencyReaderConverter.class}) @RunWith(SpringJUnit4ClassRunner.class) public class FrequencyReaderConverterDiffblueTest { - @Autowired - private FrequencyReaderConverter frequencyReaderConverter; + @Autowired + private FrequencyReaderConverter frequencyReaderConverter; + + /** + * Test {@link FrequencyReaderConverter#convert(Integer)} with {@code Integer}. + *

+ * Method under test: {@link FrequencyReaderConverter#convert(Integer)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConvertWithInteger() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + frequencyReaderConverter.convert(1); + } + + /** + * Test {@link FrequencyReaderConverter#convert(Integer)} with {@code Integer}. + *

    + *
  • When seven.
  • + *
  • Then return {@code WEEKLY}.
  • + *
+ *

+ * Method under test: {@link FrequencyReaderConverter#convert(Integer)} + */ + @Test + public void testConvertWithInteger_whenSeven_thenReturnWeekly() { + // Diffblue Cover was unable to create a Spring-specific test for this Spring method. + // Run dcover create --keep-partial-tests to gain insights into why + // a non-Spring test was created. - /** - * Test {@link FrequencyReaderConverter#convert(Integer)} with {@code Integer}. - *

    - *
  • When seven.
  • - *
  • Then return {@code WEEKLY}.
  • - *
- *

- * Method under test: {@link FrequencyReaderConverter#convert(Integer)} - */ - @Test - public void testConvertWithInteger_whenSeven_thenReturnWeekly() { - // Arrange, Act and Assert - assertEquals(Frequency.WEEKLY, frequencyReaderConverter.convert(7)); - } + // Arrange, Act and Assert + assertEquals(Frequency.WEEKLY, (new FrequencyReaderConverter()).convert(7)); + } } diff --git a/notification-service/src/test/java/com/piggymetrics/notification/repository/converter/FrequencyWriterConverterDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/repository/converter/FrequencyWriterConverterDiffblueTest.java index 7489cf89..f743689e 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/repository/converter/FrequencyWriterConverterDiffblueTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/repository/converter/FrequencyWriterConverterDiffblueTest.java @@ -1,7 +1,9 @@ package com.piggymetrics.notification.repository.converter; import static org.junit.Assert.assertEquals; + import com.piggymetrics.notification.domain.Frequency; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -11,18 +13,88 @@ @ContextConfiguration(classes = {FrequencyWriterConverter.class}) @RunWith(SpringJUnit4ClassRunner.class) public class FrequencyWriterConverterDiffblueTest { - @Autowired - private FrequencyWriterConverter frequencyWriterConverter; + @Autowired + private FrequencyWriterConverter frequencyWriterConverter; + + /** + * Test {@link FrequencyWriterConverter#convert(Frequency)} with + * {@code Frequency}. + *

+ * Method under test: {@link FrequencyWriterConverter#convert(Frequency)} + */ + @Test + public void testConvertWithFrequency() { + // Diffblue Cover was unable to create a Spring-specific test for this Spring method. + // Run dcover create --keep-partial-tests to gain insights into why + // a non-Spring test was created. + + // Arrange, Act and Assert + assertEquals(7, (new FrequencyWriterConverter()).convert(Frequency.WEEKLY).intValue()); + } + + /** + * Test {@link FrequencyWriterConverter#convert(Frequency)} with + * {@code Frequency}. + *

+ * Method under test: {@link FrequencyWriterConverter#convert(Frequency)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConvertWithFrequency2() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. - /** - * Test {@link FrequencyWriterConverter#convert(Frequency)} with - * {@code Frequency}. - *

- * Method under test: {@link FrequencyWriterConverter#convert(Frequency)} - */ - @Test - public void testConvertWithFrequency() { - // Arrange, Act and Assert - assertEquals(7, frequencyWriterConverter.convert(Frequency.WEEKLY).intValue()); - } + // Arrange and Act + frequencyWriterConverter.convert(Frequency.WEEKLY); + } } diff --git a/notification-service/src/test/java/com/piggymetrics/notification/service/EmailServiceImplDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/service/EmailServiceImplDiffblueTest.java new file mode 100644 index 00000000..8d3fc7f1 --- /dev/null +++ b/notification-service/src/test/java/com/piggymetrics/notification/service/EmailServiceImplDiffblueTest.java @@ -0,0 +1,104 @@ +package com.piggymetrics.notification.service; + +import com.piggymetrics.notification.domain.NotificationType; +import com.piggymetrics.notification.domain.Recipient; + +import java.io.IOException; +import java.util.HashMap; +import javax.mail.MessagingException; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.core.env.Environment; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@ContextConfiguration(classes = {EmailServiceImpl.class}) +@RunWith(SpringJUnit4ClassRunner.class) +public class EmailServiceImplDiffblueTest { + @Autowired + private EmailServiceImpl emailServiceImpl; + + @MockBean + private Environment environment; + + @MockBean + private JavaMailSender javaMailSender; + + /** + * Test {@link EmailServiceImpl#send(NotificationType, Recipient, String)}. + *

+ * Method under test: + * {@link EmailServiceImpl#send(NotificationType, Recipient, String)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testSend() throws IOException, MessagingException { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + Recipient recipient = new Recipient(); + recipient.setAccountName("Smith"); + recipient.setEmail("jane.doe@example.org"); + recipient.setScheduledNotifications(new HashMap<>()); + + // Act + emailServiceImpl.send(NotificationType.BACKUP, recipient, "Attachment"); + } + +} diff --git a/notification-service/src/test/java/com/piggymetrics/notification/service/EmailServiceImplTest.java b/notification-service/src/test/java/com/piggymetrics/notification/service/EmailServiceImplTest.java deleted file mode 100644 index 8909b952..00000000 --- a/notification-service/src/test/java/com/piggymetrics/notification/service/EmailServiceImplTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.piggymetrics.notification.service; - -import com.piggymetrics.notification.domain.NotificationType; -import com.piggymetrics.notification.domain.Recipient; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.core.env.Environment; -import org.springframework.mail.javamail.JavaMailSender; - -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.internet.MimeMessage; -import java.io.IOException; -import java.util.Properties; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -public class EmailServiceImplTest { - - @InjectMocks - private EmailServiceImpl emailService; - - @Mock - private JavaMailSender mailSender; - - @Mock - private Environment env; - - @Captor - private ArgumentCaptor captor; - - @Before - public void setup() { - initMocks(this); - when(mailSender.createMimeMessage()) - .thenReturn(new MimeMessage(Session.getDefaultInstance(new Properties()))); - } - - @Test - public void shouldSendBackupEmail() throws MessagingException, IOException { - - final String subject = "subject"; - final String text = "text"; - final String attachment = "attachment.json"; - - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - recipient.setEmail("test@test.com"); - - when(env.getProperty(NotificationType.BACKUP.getSubject())).thenReturn(subject); - when(env.getProperty(NotificationType.BACKUP.getText())).thenReturn(text); - when(env.getProperty(NotificationType.BACKUP.getAttachment())).thenReturn(attachment); - - emailService.send(NotificationType.BACKUP, recipient, "{\"name\":\"test\""); - - verify(mailSender).send(captor.capture()); - - MimeMessage message = captor.getValue(); - assertEquals(subject, message.getSubject()); - // TODO check other fields - } - - @Test - public void shouldSendRemindEmail() throws MessagingException, IOException { - - final String subject = "subject"; - final String text = "text"; - - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - recipient.setEmail("test@test.com"); - - when(env.getProperty(NotificationType.REMIND.getSubject())).thenReturn(subject); - when(env.getProperty(NotificationType.REMIND.getText())).thenReturn(text); - - emailService.send(NotificationType.REMIND, recipient, null); - - verify(mailSender).send(captor.capture()); - - MimeMessage message = captor.getValue(); - assertEquals(subject, message.getSubject()); - // TODO check other fields - } -} \ No newline at end of file diff --git a/notification-service/src/test/java/com/piggymetrics/notification/service/NotificationServiceImplDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/service/NotificationServiceImplDiffblueTest.java new file mode 100644 index 00000000..9a5d8b32 --- /dev/null +++ b/notification-service/src/test/java/com/piggymetrics/notification/service/NotificationServiceImplDiffblueTest.java @@ -0,0 +1,156 @@ +package com.piggymetrics.notification.service; + +import com.piggymetrics.notification.client.AccountServiceClient; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@ContextConfiguration(classes = {NotificationServiceImpl.class}) +@RunWith(SpringJUnit4ClassRunner.class) +public class NotificationServiceImplDiffblueTest { + @MockBean + private AccountServiceClient accountServiceClient; + + @MockBean + private EmailService emailService; + + @Autowired + private NotificationServiceImpl notificationServiceImpl; + + @MockBean + private RecipientService recipientService; + + /** + * Test {@link NotificationServiceImpl#sendBackupNotifications()}. + *

+ * Method under test: {@link NotificationServiceImpl#sendBackupNotifications()} + */ + @Test + @Ignore("TODO: Complete this test") + public void testSendBackupNotifications() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + notificationServiceImpl.sendBackupNotifications(); + } + + /** + * Test {@link NotificationServiceImpl#sendRemindNotifications()}. + *

+ * Method under test: {@link NotificationServiceImpl#sendRemindNotifications()} + */ + @Test + @Ignore("TODO: Complete this test") + public void testSendRemindNotifications() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + notificationServiceImpl.sendRemindNotifications(); + } +} diff --git a/notification-service/src/test/java/com/piggymetrics/notification/service/NotificationServiceImplTest.java b/notification-service/src/test/java/com/piggymetrics/notification/service/NotificationServiceImplTest.java deleted file mode 100644 index 07276792..00000000 --- a/notification-service/src/test/java/com/piggymetrics/notification/service/NotificationServiceImplTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.piggymetrics.notification.service; - -import com.google.common.collect.ImmutableList; -import com.piggymetrics.notification.client.AccountServiceClient; -import com.piggymetrics.notification.domain.NotificationType; -import com.piggymetrics.notification.domain.Recipient; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -import javax.mail.MessagingException; -import java.io.IOException; - -import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; - -public class NotificationServiceImplTest { - - @InjectMocks - private NotificationServiceImpl notificationService; - - @Mock - private RecipientService recipientService; - - @Mock - private AccountServiceClient client; - - @Mock - private EmailService emailService; - - @Before - public void setup() { - initMocks(this); - } - - @Test - public void shouldSendBackupNotificationsEvenWhenErrorsOccursForSomeRecipients() throws IOException, MessagingException, InterruptedException { - - final String attachment = "json"; - - Recipient withError = new Recipient(); - withError.setAccountName("with-error"); - - Recipient withNoError = new Recipient(); - withNoError.setAccountName("with-no-error"); - - when(client.getAccount(withError.getAccountName())).thenThrow(new RuntimeException()); - when(client.getAccount(withNoError.getAccountName())).thenReturn(attachment); - - when(recipientService.findReadyToNotify(NotificationType.BACKUP)).thenReturn(ImmutableList.of(withNoError, withError)); - - notificationService.sendBackupNotifications(); - - // TODO test concurrent code in a right way - - verify(emailService, timeout(100)).send(NotificationType.BACKUP, withNoError, attachment); - verify(recipientService, timeout(100)).markNotified(NotificationType.BACKUP, withNoError); - - verify(recipientService, never()).markNotified(NotificationType.BACKUP, withError); - } - - @Test - public void shouldSendRemindNotificationsEvenWhenErrorsOccursForSomeRecipients() throws IOException, MessagingException, InterruptedException { - - final String attachment = "json"; - - Recipient withError = new Recipient(); - withError.setAccountName("with-error"); - - Recipient withNoError = new Recipient(); - withNoError.setAccountName("with-no-error"); - - when(recipientService.findReadyToNotify(NotificationType.REMIND)).thenReturn(ImmutableList.of(withNoError, withError)); - doThrow(new RuntimeException()).when(emailService).send(NotificationType.REMIND, withError, null); - - notificationService.sendRemindNotifications(); - - // TODO test concurrent code in a right way - - verify(emailService, timeout(100)).send(NotificationType.REMIND, withNoError, null); - verify(recipientService, timeout(100)).markNotified(NotificationType.REMIND, withNoError); - - verify(recipientService, never()).markNotified(NotificationType.REMIND, withError); - } -} \ No newline at end of file diff --git a/notification-service/src/test/java/com/piggymetrics/notification/service/RecipientServiceImplDiffblueTest.java b/notification-service/src/test/java/com/piggymetrics/notification/service/RecipientServiceImplDiffblueTest.java index cdbadf09..4e7e26ab 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/service/RecipientServiceImplDiffblueTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/service/RecipientServiceImplDiffblueTest.java @@ -1,414 +1,300 @@ package com.piggymetrics.notification.service; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import com.piggymetrics.notification.domain.Frequency; -import com.piggymetrics.notification.domain.NotificationSettings; import com.piggymetrics.notification.domain.NotificationType; import com.piggymetrics.notification.domain.Recipient; import com.piggymetrics.notification.repository.RecipientRepository; -import java.time.LocalDate; -import java.time.ZoneOffset; -import java.util.ArrayList; -import java.util.Date; + import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.Rule; + +import org.junit.Ignore; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.repository.CrudRepository; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration(classes = {RecipientServiceImpl.class}) @RunWith(SpringJUnit4ClassRunner.class) public class RecipientServiceImplDiffblueTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @MockBean - private RecipientRepository recipientRepository; - - @Autowired - private RecipientServiceImpl recipientServiceImpl; - - /** - * Test {@link RecipientServiceImpl#findByAccountName(String)}. - *

    - *
  • Given {@link Recipient} (default constructor) AccountName is - * {@code Dr Jane Doe}.
  • - *
  • Then return {@link Recipient} (default constructor).
  • - *
- *

- * Method under test: {@link RecipientServiceImpl#findByAccountName(String)} - */ - @Test - public void testFindByAccountName_givenRecipientAccountNameIsDrJaneDoe_thenReturnRecipient() { - // Arrange - Recipient recipient = new Recipient(); - recipient.setAccountName("Dr Jane Doe"); - recipient.setEmail("jane.doe@example.org"); - recipient.setScheduledNotifications(new HashMap<>()); - when(recipientRepository.findByAccountName(Mockito.any())).thenReturn(recipient); - - // Act - Recipient actualFindByAccountNameResult = recipientServiceImpl.findByAccountName("Dr Jane Doe"); - - // Assert - verify(recipientRepository).findByAccountName(eq("Dr Jane Doe")); - assertSame(recipient, actualFindByAccountNameResult); - } - - /** - * Test {@link RecipientServiceImpl#findByAccountName(String)}. - *

    - *
  • Then throw {@link IllegalArgumentException}.
  • - *
- *

- * Method under test: {@link RecipientServiceImpl#findByAccountName(String)} - */ - @Test - public void testFindByAccountName_thenThrowIllegalArgumentException() { - // Arrange - when(recipientRepository.findByAccountName(Mockito.any())).thenThrow(new IllegalArgumentException("foo")); - - // Act and Assert - thrown.expect(IllegalArgumentException.class); - recipientServiceImpl.findByAccountName("Dr Jane Doe"); - verify(recipientRepository).findByAccountName(eq("Dr Jane Doe")); - } - - /** - * Test {@link RecipientServiceImpl#save(String, Recipient)}. - *

    - *
  • Given {@link HashMap#HashMap()}.
  • - *
  • Then return {@link Recipient} (default constructor).
  • - *
- *

- * Method under test: {@link RecipientServiceImpl#save(String, Recipient)} - */ - @Test - public void testSave_givenHashMap_thenReturnRecipient() { - // Arrange - Recipient recipient = new Recipient(); - recipient.setAccountName("Dr Jane Doe"); - recipient.setEmail("jane.doe@example.org"); - recipient.setScheduledNotifications(new HashMap<>()); - when(recipientRepository.save(Mockito.any())).thenReturn(recipient); - - Recipient recipient2 = new Recipient(); - recipient2.setAccountName("Dr Jane Doe"); - recipient2.setEmail("jane.doe@example.org"); - recipient2.setScheduledNotifications(new HashMap<>()); - - // Act - Recipient actualSaveResult = recipientServiceImpl.save("Dr Jane Doe", recipient2); - - // Assert - verify(recipientRepository).save(isA(Recipient.class)); - assertSame(recipient2, actualSaveResult); - } - - /** - * Test {@link RecipientServiceImpl#save(String, Recipient)}. - *

    - *
  • Given {@link NotificationSettings} (default constructor) LastNotified is - * {@code null}.
  • - *
- *

- * Method under test: {@link RecipientServiceImpl#save(String, Recipient)} - */ - @Test - public void testSave_givenNotificationSettingsLastNotifiedIsNull() { - // Arrange - Recipient recipient = new Recipient(); - recipient.setAccountName("Dr Jane Doe"); - recipient.setEmail("jane.doe@example.org"); - recipient.setScheduledNotifications(new HashMap<>()); - when(recipientRepository.save(Mockito.any())).thenReturn(recipient); - - NotificationSettings notificationSettings = new NotificationSettings(); - notificationSettings.setActive(true); - notificationSettings.setFrequency(Frequency.WEEKLY); - notificationSettings.setLastNotified(null); - - HashMap scheduledNotifications = new HashMap<>(); - scheduledNotifications.put(NotificationType.BACKUP, notificationSettings); - - Recipient recipient2 = new Recipient(); - recipient2.setAccountName("Dr Jane Doe"); - recipient2.setEmail("jane.doe@example.org"); - recipient2.setScheduledNotifications(scheduledNotifications); - - // Act - Recipient actualSaveResult = recipientServiceImpl.save("Dr Jane Doe", recipient2); - - // Assert - verify(recipientRepository).save(isA(Recipient.class)); - assertSame(scheduledNotifications, actualSaveResult.getScheduledNotifications()); - } - - /** - * Test {@link RecipientServiceImpl#save(String, Recipient)}. - *

    - *
  • Then return ScheduledNotifications is {@link HashMap#HashMap()}.
  • - *
- *

- * Method under test: {@link RecipientServiceImpl#save(String, Recipient)} - */ - @Test - public void testSave_thenReturnScheduledNotificationsIsHashMap() { - // Arrange - Recipient recipient = new Recipient(); - recipient.setAccountName("Dr Jane Doe"); - recipient.setEmail("jane.doe@example.org"); - recipient.setScheduledNotifications(new HashMap<>()); - when(recipientRepository.save(Mockito.any())).thenReturn(recipient); - - NotificationSettings notificationSettings = new NotificationSettings(); - notificationSettings.setActive(true); - notificationSettings.setFrequency(Frequency.WEEKLY); - notificationSettings - .setLastNotified(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); - - HashMap scheduledNotifications = new HashMap<>(); - scheduledNotifications.put(NotificationType.BACKUP, notificationSettings); - - Recipient recipient2 = new Recipient(); - recipient2.setAccountName("Dr Jane Doe"); - recipient2.setEmail("jane.doe@example.org"); - recipient2.setScheduledNotifications(scheduledNotifications); - - // Act - Recipient actualSaveResult = recipientServiceImpl.save("Dr Jane Doe", recipient2); - - // Assert - verify(recipientRepository).save(isA(Recipient.class)); - assertSame(scheduledNotifications, actualSaveResult.getScheduledNotifications()); - } - - /** - * Test {@link RecipientServiceImpl#save(String, Recipient)}. - *

    - *
  • Then return ScheduledNotifications size is two.
  • - *
- *

- * Method under test: {@link RecipientServiceImpl#save(String, Recipient)} - */ - @Test - public void testSave_thenReturnScheduledNotificationsSizeIsTwo() { - // Arrange - Recipient recipient = new Recipient(); - recipient.setAccountName("Dr Jane Doe"); - recipient.setEmail("jane.doe@example.org"); - recipient.setScheduledNotifications(new HashMap<>()); - when(recipientRepository.save(Mockito.any())).thenReturn(recipient); - - NotificationSettings notificationSettings = new NotificationSettings(); - notificationSettings.setActive(true); - notificationSettings.setFrequency(Frequency.WEEKLY); - notificationSettings - .setLastNotified(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); - - NotificationSettings notificationSettings2 = new NotificationSettings(); - notificationSettings2.setActive(false); - notificationSettings2.setFrequency(Frequency.MONTHLY); - notificationSettings2 - .setLastNotified(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); - - HashMap scheduledNotifications = new HashMap<>(); - scheduledNotifications.put(NotificationType.REMIND, notificationSettings2); - scheduledNotifications.put(NotificationType.BACKUP, notificationSettings); - - Recipient recipient2 = new Recipient(); - recipient2.setAccountName("Dr Jane Doe"); - recipient2.setEmail("jane.doe@example.org"); - recipient2.setScheduledNotifications(scheduledNotifications); - - // Act - Recipient actualSaveResult = recipientServiceImpl.save("Dr Jane Doe", recipient2); - - // Assert - verify(recipientRepository).save(isA(Recipient.class)); - Map scheduledNotifications2 = actualSaveResult.getScheduledNotifications(); - assertEquals(2, scheduledNotifications2.size()); - assertTrue(scheduledNotifications2.containsKey(NotificationType.BACKUP)); - assertSame(notificationSettings2, scheduledNotifications2.get(NotificationType.REMIND)); - } - - /** - * Test {@link RecipientServiceImpl#save(String, Recipient)}. - *

    - *
  • Then throw {@link IllegalArgumentException}.
  • - *
- *

- * Method under test: {@link RecipientServiceImpl#save(String, Recipient)} - */ - @Test - public void testSave_thenThrowIllegalArgumentException() { - // Arrange - when(recipientRepository.save(Mockito.any())) - .thenThrow(new IllegalArgumentException("recipient {} settings has been updated")); - - Recipient recipient = new Recipient(); - recipient.setAccountName("Dr Jane Doe"); - recipient.setEmail("jane.doe@example.org"); - recipient.setScheduledNotifications(new HashMap<>()); - - // Act and Assert - thrown.expect(IllegalArgumentException.class); - recipientServiceImpl.save("Dr Jane Doe", recipient); - verify(recipientRepository).save(isA(Recipient.class)); - } - - /** - * Test {@link RecipientServiceImpl#findReadyToNotify(NotificationType)}. - *

    - *
  • Given {@link RecipientRepository} - * {@link RecipientRepository#findReadyForRemind()} return - * {@link ArrayList#ArrayList()}.
  • - *
- *

- * Method under test: - * {@link RecipientServiceImpl#findReadyToNotify(NotificationType)} - */ - @Test - public void testFindReadyToNotify_givenRecipientRepositoryFindReadyForRemindReturnArrayList() { - // Arrange - when(recipientRepository.findReadyForRemind()).thenReturn(new ArrayList<>()); - - // Act - List actualFindReadyToNotifyResult = recipientServiceImpl.findReadyToNotify(NotificationType.REMIND); - - // Assert - verify(recipientRepository).findReadyForRemind(); - assertTrue(actualFindReadyToNotifyResult.isEmpty()); - } - - /** - * Test {@link RecipientServiceImpl#findReadyToNotify(NotificationType)}. - *

    - *
  • Then calls {@link RecipientRepository#findReadyForBackup()}.
  • - *
- *

- * Method under test: - * {@link RecipientServiceImpl#findReadyToNotify(NotificationType)} - */ - @Test - public void testFindReadyToNotify_thenCallsFindReadyForBackup() { - // Arrange - when(recipientRepository.findReadyForBackup()).thenReturn(new ArrayList<>()); - - // Act - List actualFindReadyToNotifyResult = recipientServiceImpl.findReadyToNotify(NotificationType.BACKUP); - - // Assert - verify(recipientRepository).findReadyForBackup(); - assertTrue(actualFindReadyToNotifyResult.isEmpty()); - } - - /** - * Test {@link RecipientServiceImpl#findReadyToNotify(NotificationType)}. - *

    - *
  • Then throw {@link IllegalArgumentException}.
  • - *
- *

- * Method under test: - * {@link RecipientServiceImpl#findReadyToNotify(NotificationType)} - */ - @Test - public void testFindReadyToNotify_thenThrowIllegalArgumentException() { - // Arrange - when(recipientRepository.findReadyForRemind()).thenThrow(new IllegalArgumentException("foo")); - - // Act and Assert - thrown.expect(IllegalArgumentException.class); - recipientServiceImpl.findReadyToNotify(NotificationType.REMIND); - verify(recipientRepository).findReadyForRemind(); - } - - /** - * Test {@link RecipientServiceImpl#markNotified(NotificationType, Recipient)}. - *

    - *
  • Given {@link Recipient} (default constructor) AccountName is - * {@code Dr Jane Doe}.
  • - *
  • Then calls {@link CrudRepository#save(Object)}.
  • - *
- *

- * Method under test: - * {@link RecipientServiceImpl#markNotified(NotificationType, Recipient)} - */ - @Test - public void testMarkNotified_givenRecipientAccountNameIsDrJaneDoe_thenCallsSave() { - // Arrange - Recipient recipient = new Recipient(); - recipient.setAccountName("Dr Jane Doe"); - recipient.setEmail("jane.doe@example.org"); - recipient.setScheduledNotifications(new HashMap<>()); - when(recipientRepository.save(Mockito.any())).thenReturn(recipient); - - NotificationSettings notificationSettings = new NotificationSettings(); - notificationSettings.setActive(true); - notificationSettings.setFrequency(Frequency.WEEKLY); - notificationSettings - .setLastNotified(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); - - HashMap scheduledNotifications = new HashMap<>(); - scheduledNotifications.put(NotificationType.BACKUP, notificationSettings); - - Recipient recipient2 = new Recipient(); - recipient2.setAccountName("Dr Jane Doe"); - recipient2.setEmail("jane.doe@example.org"); - recipient2.setScheduledNotifications(scheduledNotifications); - - // Act - recipientServiceImpl.markNotified(NotificationType.BACKUP, recipient2); - - // Assert - verify(recipientRepository).save(isA(Recipient.class)); - } - - /** - * Test {@link RecipientServiceImpl#markNotified(NotificationType, Recipient)}. - *

    - *
  • Then throw {@link IllegalArgumentException}.
  • - *
- *

- * Method under test: - * {@link RecipientServiceImpl#markNotified(NotificationType, Recipient)} - */ - @Test - public void testMarkNotified_thenThrowIllegalArgumentException() { - // Arrange - when(recipientRepository.save(Mockito.any())).thenThrow(new IllegalArgumentException("foo")); - - NotificationSettings notificationSettings = new NotificationSettings(); - notificationSettings.setActive(true); - notificationSettings.setFrequency(Frequency.WEEKLY); - notificationSettings - .setLastNotified(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); - - HashMap scheduledNotifications = new HashMap<>(); - scheduledNotifications.put(NotificationType.BACKUP, notificationSettings); - - Recipient recipient = new Recipient(); - recipient.setAccountName("Dr Jane Doe"); - recipient.setEmail("jane.doe@example.org"); - recipient.setScheduledNotifications(scheduledNotifications); + @MockBean + private RecipientRepository recipientRepository; + + @Autowired + private RecipientServiceImpl recipientServiceImpl; + + /** + * Test {@link RecipientServiceImpl#findByAccountName(String)}. + *

+ * Method under test: {@link RecipientServiceImpl#findByAccountName(String)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testFindByAccountName() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + recipientServiceImpl.findByAccountName("Smith"); + } + + /** + * Test {@link RecipientServiceImpl#save(String, Recipient)}. + *

+ * Method under test: {@link RecipientServiceImpl#save(String, Recipient)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testSave() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + Recipient recipient = new Recipient(); + recipient.setAccountName("Smith"); + recipient.setEmail("jane.doe@example.org"); + recipient.setScheduledNotifications(new HashMap<>()); + + // Act + recipientServiceImpl.save("Smith", recipient); + } + + /** + * /** Test {@link RecipientServiceImpl#findReadyToNotify(NotificationType)}. + *

+ * Method under test: + * {@link RecipientServiceImpl#findReadyToNotify(NotificationType)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testFindReadyToNotify() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + recipientServiceImpl.findReadyToNotify(NotificationType.BACKUP); + } + + /** + * Test {@link RecipientServiceImpl#markNotified(NotificationType, Recipient)}. + *

+ * Method under test: + * {@link RecipientServiceImpl#markNotified(NotificationType, Recipient)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testMarkNotified() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + Recipient recipient = new Recipient(); + recipient.setAccountName("Smith"); + recipient.setEmail("jane.doe@example.org"); + recipient.setScheduledNotifications(new HashMap<>()); + + // Act + recipientServiceImpl.markNotified(NotificationType.BACKUP, recipient); + } - // Act and Assert - thrown.expect(IllegalArgumentException.class); - recipientServiceImpl.markNotified(NotificationType.BACKUP, recipient); - verify(recipientRepository).save(isA(Recipient.class)); - } } diff --git a/notification-service/src/test/java/com/piggymetrics/notification/service/RecipientServiceImplTest.java b/notification-service/src/test/java/com/piggymetrics/notification/service/RecipientServiceImplTest.java deleted file mode 100644 index a93f29a2..00000000 --- a/notification-service/src/test/java/com/piggymetrics/notification/service/RecipientServiceImplTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.piggymetrics.notification.service; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.piggymetrics.notification.domain.Frequency; -import com.piggymetrics.notification.domain.NotificationSettings; -import com.piggymetrics.notification.domain.NotificationType; -import com.piggymetrics.notification.domain.Recipient; -import com.piggymetrics.notification.repository.RecipientRepository; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -import java.util.Date; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -public class RecipientServiceImplTest { - - @InjectMocks - private RecipientServiceImpl recipientService; - - @Mock - private RecipientRepository repository; - - @Before - public void setup() { - initMocks(this); - } - - @Test - public void shouldFindByAccountName() { - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - - when(repository.findByAccountName(recipient.getAccountName())).thenReturn(recipient); - Recipient found = recipientService.findByAccountName(recipient.getAccountName()); - - assertEquals(recipient, found); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailToFindRecipientWhenAccountNameIsEmpty() { - recipientService.findByAccountName(""); - } - - @Test - public void shouldSaveRecipient() { - - NotificationSettings remind = new NotificationSettings(); - remind.setActive(true); - remind.setFrequency(Frequency.WEEKLY); - remind.setLastNotified(null); - - NotificationSettings backup = new NotificationSettings(); - backup.setActive(false); - backup.setFrequency(Frequency.MONTHLY); - backup.setLastNotified(new Date()); - - Recipient recipient = new Recipient(); - recipient.setEmail("test@test.com"); - recipient.setScheduledNotifications(ImmutableMap.of( - NotificationType.BACKUP, backup, - NotificationType.REMIND, remind - )); - - Recipient saved = recipientService.save("test", recipient); - - verify(repository).save(recipient); - assertNotNull(saved.getScheduledNotifications().get(NotificationType.REMIND).getLastNotified()); - assertEquals("test", saved.getAccountName()); - } - - @Test - public void shouldFindReadyToNotifyWhenNotificationTypeIsBackup() { - final List recipients = ImmutableList.of(new Recipient()); - when(repository.findReadyForBackup()).thenReturn(recipients); - - List found = recipientService.findReadyToNotify(NotificationType.BACKUP); - assertEquals(recipients, found); - } - - @Test - public void shouldFindReadyToNotifyWhenNotificationTypeIsRemind() { - final List recipients = ImmutableList.of(new Recipient()); - when(repository.findReadyForRemind()).thenReturn(recipients); - - List found = recipientService.findReadyToNotify(NotificationType.REMIND); - assertEquals(recipients, found); - } - - @Test - public void shouldMarkAsNotified() { - - NotificationSettings remind = new NotificationSettings(); - remind.setActive(true); - remind.setFrequency(Frequency.WEEKLY); - remind.setLastNotified(null); - - Recipient recipient = new Recipient(); - recipient.setAccountName("test"); - recipient.setEmail("test@test.com"); - recipient.setScheduledNotifications(ImmutableMap.of( - NotificationType.REMIND, remind - )); - - recipientService.markNotified(NotificationType.REMIND, recipient); - assertNotNull(recipient.getScheduledNotifications().get(NotificationType.REMIND).getLastNotified()); - verify(repository).save(recipient); - } -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 486561db..a3d38e46 100644 --- a/pom.xml +++ b/pom.xml @@ -30,9 +30,14 @@ pom import + + org.aspectj + aspectjweaver + 1.9.7 + - + config monitoring diff --git a/turbine-stream-service/report.json b/registry/.diffblue/reports/report.json similarity index 54% rename from turbine-stream-service/report.json rename to registry/.diffblue/reports/report.json index 006e553e..e6b9fa1c 100644 --- a/turbine-stream-service/report.json +++ b/registry/.diffblue/reports/report.json @@ -3,17 +3,17 @@ "reportVersion" : "2.6" }, "run" : { - "version" : "2025.01.01-2348203-licensed", - "creationTimestamp" : "2025-01-13T17:02:34.067Z", - "command" : "dcover create --batch --report-file=report.json --coverage-reports --spring-integration-tests --verbose --exclude=com.piggymetrics.notification.service.NotificationServiceImpl. --working-directory=turbine-stream-service", - "totalTime" : 54.293, - "environmentDetectionTime" : 0.487, - "indexingTime" : 0.379, - "entryPointsTime" : 0.45, - "generationTime" : 19.906, - "timeToFirstTest" : 54.401, - "timeToLastTest" : 42.104, - "indexQueryTime" : 9.689, + "version" : "2024.10.22-TG-22184-ExtraLogging-b801b56-licensed", + "creationTimestamp" : "2025-01-25T18:19:09.1971473Z", + "command" : "dcover create ", + "totalTime" : 127.696, + "environmentDetectionTime" : 0.314, + "indexingTime" : 0.251, + "entryPointsTime" : 0.298, + "generationTime" : 48.673, + "timeToFirstTest" : 127.805, + "timeToLastTest" : 62.082, + "indexQueryTime" : 5.563, "verificationTime" : 0.0, "validationTime" : 0.0 }, @@ -24,12 +24,12 @@ "summary" : { "classesCount" : 1, "methodsCount" : 2, - "cumulativeDiffblueTestCount" : 1, - "cumulativeManualTestCount" : 1, + "cumulativeDiffblueTestCount" : 0, + "cumulativeManualTestCount" : 0, "completeTestCount" : 0, "incompleteTestCount" : 0, "skeletonTestCount" : 0, - "totalPhysicalLineCount" : 13, + "totalPhysicalLineCount" : 0, "perMethodTestability" : { "T005" : 1, "T006" : 1 @@ -40,7 +40,7 @@ } }, "classes" : { - "com.piggymetrics.turbine.TurbineStreamServiceApplication" : { + "com.piggymetrics.registry.RegistryApplication" : { "methodsCount" : 2, "completeTestCount" : 0, "incompleteTestCount" : 0, @@ -55,23 +55,23 @@ } }, "methods" : { - "com.piggymetrics.turbine.TurbineStreamServiceApplication.:()V" : { + "com.piggymetrics.registry.RegistryApplication.:()V" : { "completeTestCount" : 0, "incompleteTestCount" : 0, "perMethodTestability" : "T005", "perMethodOutcome" : "T005", "lineNumbers" : [ - 11 + 9 ] }, - "com.piggymetrics.turbine.TurbineStreamServiceApplication.main:([Ljava/lang/String;)V" : { + "com.piggymetrics.registry.RegistryApplication.main:([Ljava/lang/String;)V" : { "completeTestCount" : 0, "incompleteTestCount" : 0, "perMethodTestability" : "T006", "perMethodOutcome" : "T006", "lineNumbers" : [ - 14, - 15 + 12, + 13 ] } } diff --git a/registry/pom.xml b/registry/pom.xml index 4119a2a7..7958b5a8 100644 --- a/registry/pom.xml +++ b/registry/pom.xml @@ -30,7 +30,7 @@ org.jacoco org.jacoco.agent - 0.8.2 + 0.8.11 test runtime @@ -40,6 +40,24 @@ 4.12 test + + org.mockito + mockito-core + 4.1.0 + test + + + org.springframework + spring-core + 6.0.11 + compile + + + org.springframework.boot + spring-boot + 2.5.1 + compile + @@ -65,7 +83,7 @@ org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.11 diff --git a/registry/src/test/java/DummyJunitDiffblueTest.java b/registry/src/test/java/DummyJunitDiffblueTest.java new file mode 100644 index 00000000..438639e0 --- /dev/null +++ b/registry/src/test/java/DummyJunitDiffblueTest.java @@ -0,0 +1,18 @@ +package org.example.junit4; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class DummyJunitDiffblueTest { + + @Test + public void testEquality() { + // The following line will fail to compile if the project uses the groovy compiler for java + // sources + final String[] array = {"foo", "bar", "baz"}; + for (int i = 0; i < array.length; i++) { + assertEquals(array[i], array[i]); + } + } +} \ No newline at end of file diff --git a/statistics-service/pom.xml b/statistics-service/pom.xml index 004b1456..e18addb3 100644 --- a/statistics-service/pom.xml +++ b/statistics-service/pom.xml @@ -63,6 +63,10 @@ guava 19.0 + + io.projectreactor + reactor-test + org.springframework.boot @@ -84,7 +88,7 @@ org.jacoco org.jacoco.agent - 0.8.2 + 0.8.11 test runtime @@ -94,6 +98,24 @@ 4.12 test + + org.mockito + mockito-core + 4.1.0 + test + + + org.springframework + spring-core + 6.0.11 + compile + + + org.springframework.boot + spring-boot + 2.5.1 + compile + @@ -119,7 +141,7 @@ org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.11 diff --git a/statistics-service/report.json b/statistics-service/report.json deleted file mode 100644 index 971fbabb..00000000 --- a/statistics-service/report.json +++ /dev/null @@ -1,1855 +0,0 @@ -{ - "meta" : { - "reportVersion" : "2.6" - }, - "run" : { - "version" : "2025.01.01-2348203-licensed", - "creationTimestamp" : "2025-01-13T16:49:19.124Z", - "command" : "dcover create --batch --report-file=report.json --coverage-reports --spring-integration-tests --verbose --exclude=com.piggymetrics.notification.service.NotificationServiceImpl. --working-directory=statistics-service", - "totalTime" : 333.365, - "environmentDetectionTime" : 0.871, - "indexingTime" : 0.328, - "entryPointsTime" : 0.833, - "generationTime" : 225.093, - "timeToFirstTest" : 109.814, - "timeToLastTest" : 277.75, - "indexQueryTime" : 16.041, - "verificationTime" : 27.241, - "validationTime" : 24.041 - }, - "codes" : { - "E052" : "Missing dependency", - "R000" : "Success", - "R002" : "Missing observers", - "R004" : "No meaningful assertions found", - "R011" : "Sandboxing policy violation", - "R013" : "No inputs found that don't throw a trivial exception", - "T000" : "Method eligible for test creation", - "T001" : "Trivial getter", - "T002" : "Trivial setter", - "T003" : "Private method", - "T005" : "Trivial constructor", - "T006" : "Main method", - "T010" : "Abstract or interface method", - "T012" : "Synthetic method", - "T020" : "Other trivial method", - "V000" : "Validated successfully" - }, - "summary" : { - "classesCount" : 24, - "methodsCount" : 125, - "cumulativeDiffblueTestCount" : 29, - "cumulativeManualTestCount" : 14, - "completeTestCount" : 29, - "incompleteTestCount" : 0, - "skeletonTestCount" : 0, - "totalPhysicalLineCount" : 678, - "perMethodTestability" : { - "T000" : 32, - "T001" : 26, - "T002" : 23, - "T003" : 9, - "T005" : 14, - "T006" : 1, - "T010" : 5, - "T012" : 13, - "T020" : 2 - }, - "perMethodOutcome" : { - "E052" : 12, - "R000" : 68, - "R002" : 3, - "R004" : 2, - "R011" : 1, - "R013" : 2, - "T003" : 9, - "T005" : 9, - "T006" : 1, - "T010" : 5, - "T012" : 13 - }, - "perTestOutcome" : { - "R000" : 29 - }, - "perTestValidation" : { - "V000" : 29 - } - }, - "classes" : { - "com.piggymetrics.statistics.StatisticsApplication" : { - "methodsCount" : 2, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T005" : 1, - "T006" : 1 - }, - "perMethodOutcome" : { - "T005" : 1, - "T006" : 1 - } - }, - "com.piggymetrics.statistics.StatisticsApplication$CustomConversionsConfig" : { - "methodsCount" : 2, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T005" : 1 - }, - "perMethodOutcome" : { - "R004" : 1, - "T005" : 1 - } - }, - "com.piggymetrics.statistics.client.ExchangeRatesClient" : { - "methodsCount" : 1, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T010" : 1 - }, - "perMethodOutcome" : { - "T010" : 1 - } - }, - "com.piggymetrics.statistics.client.ExchangeRatesClientFallback" : { - "methodsCount" : 2, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 1, - "T005" : 1 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.statistics.config.ResourceServerConfig" : { - "methodsCount" : 2, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 1, - "T005" : 1 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.statistics.controller.StatisticsController" : { - "methodsCount" : 4, - "completeTestCount" : 3, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 3, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 3, - "T005" : 1 - }, - "perTestOutcome" : { - "R000" : 3 - } - }, - "com.piggymetrics.statistics.domain.Account" : { - "methodsCount" : 7, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 3, - "T002" : 3, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 7 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.statistics.domain.Currency" : { - "methodsCount" : 5, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 1, - "T003" : 1, - "T012" : 3 - }, - "perMethodOutcome" : { - "R000" : 1, - "T003" : 1, - "T012" : 3 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.statistics.domain.ExchangeRatesContainer" : { - "methodsCount" : 8, - "completeTestCount" : 2, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T001" : 3, - "T002" : 3, - "T020" : 1 - }, - "perMethodOutcome" : { - "R000" : 8 - }, - "perTestOutcome" : { - "R000" : 2 - } - }, - "com.piggymetrics.statistics.domain.Item" : { - "methodsCount" : 9, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 4, - "T002" : 4, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 9 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.statistics.domain.Saving" : { - "methodsCount" : 11, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 5, - "T002" : 5, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 11 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.statistics.domain.TimePeriod" : { - "methodsCount" : 6, - "completeTestCount" : 2, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T001" : 1, - "T003" : 1, - "T012" : 3 - }, - "perMethodOutcome" : { - "R000" : 2, - "T003" : 1, - "T012" : 3 - }, - "perTestOutcome" : { - "R000" : 2 - } - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint" : { - "methodsCount" : 11, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 5, - "T002" : 5, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 11 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.statistics.domain.timeseries.DataPointId" : { - "methodsCount" : 4, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T001" : 2, - "T005" : 1, - "T020" : 1 - }, - "perMethodOutcome" : { - "R000" : 4 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.statistics.domain.timeseries.ItemMetric" : { - "methodsCount" : 5, - "completeTestCount" : 6, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 2, - "T001" : 2, - "T005" : 1 - }, - "perMethodOutcome" : { - "R000" : 5 - }, - "perTestOutcome" : { - "R000" : 6 - } - }, - "com.piggymetrics.statistics.domain.timeseries.StatisticMetric" : { - "methodsCount" : 4, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T003" : 1, - "T012" : 3 - }, - "perMethodOutcome" : { - "T003" : 1, - "T012" : 3 - } - }, - "com.piggymetrics.statistics.repository.DataPointRepository" : { - "methodsCount" : 12, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 12 - }, - "perMethodOutcome" : { - "E052" : 12 - } - }, - "com.piggymetrics.statistics.repository.converter.DataPointIdReaderConverter" : { - "methodsCount" : 3, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T005" : 1, - "T012" : 1 - }, - "perMethodOutcome" : { - "R013" : 1, - "T005" : 1, - "T012" : 1 - } - }, - "com.piggymetrics.statistics.repository.converter.DataPointIdWriterConverter" : { - "methodsCount" : 3, - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 1, - "T005" : 1, - "T012" : 1 - }, - "perMethodOutcome" : { - "R000" : 1, - "T005" : 1, - "T012" : 1 - }, - "perTestOutcome" : { - "R000" : 1 - } - }, - "com.piggymetrics.statistics.service.ExchangeRatesService" : { - "methodsCount" : 2, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T010" : 2 - }, - "perMethodOutcome" : { - "T010" : 2 - } - }, - "com.piggymetrics.statistics.service.ExchangeRatesServiceImpl" : { - "methodsCount" : 4, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 2, - "T005" : 1, - "T012" : 1 - }, - "perMethodOutcome" : { - "R011" : 1, - "R013" : 1, - "T005" : 1, - "T012" : 1 - } - }, - "com.piggymetrics.statistics.service.StatisticsService" : { - "methodsCount" : 2, - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T010" : 2 - }, - "perMethodOutcome" : { - "T010" : 2 - } - }, - "com.piggymetrics.statistics.service.StatisticsServiceImpl" : { - "methodsCount" : 5, - "completeTestCount" : 5, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 3, - "T003" : 2 - }, - "perMethodOutcome" : { - "R000" : 2, - "T003" : 2, - "T005" : 1 - }, - "perTestOutcome" : { - "R000" : 5 - } - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices" : { - "methodsCount" : 11, - "completeTestCount" : 2, - "incompleteTestCount" : 0, - "perMethodTestability" : { - "T000" : 3, - "T002" : 3, - "T003" : 4, - "T012" : 1 - }, - "perMethodOutcome" : { - "R000" : 2, - "R002" : 3, - "R004" : 1, - "T003" : 4, - "T012" : 1 - }, - "perTestOutcome" : { - "R000" : 2 - } - } - }, - "methods" : { - "com.piggymetrics.statistics.StatisticsApplication$CustomConversionsConfig.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 33 - ] - }, - "com.piggymetrics.statistics.StatisticsApplication$CustomConversionsConfig.customConversions:()Lorg/springframework/data/mongodb/core/convert/CustomConversions;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R004", - "lineNumbers" : [ - 37 - ] - }, - "com.piggymetrics.statistics.StatisticsApplication.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 26 - ] - }, - "com.piggymetrics.statistics.StatisticsApplication.main:([Ljava/lang/String;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T006", - "perMethodOutcome" : "T006", - "lineNumbers" : [ - 29, - 30 - ] - }, - "com.piggymetrics.statistics.client.ExchangeRatesClient.getRates:(Lcom/piggymetrics/statistics/domain/Currency;)Lcom/piggymetrics/statistics/domain/ExchangeRatesContainer;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.statistics.client.ExchangeRatesClientFallback.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 10 - ] - }, - "com.piggymetrics.statistics.client.ExchangeRatesClientFallback.getRates:(Lcom/piggymetrics/statistics/domain/Currency;)Lcom/piggymetrics/statistics/domain/ExchangeRatesContainer;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 14, - 15, - 16, - 17 - ] - }, - "com.piggymetrics.statistics.config.ResourceServerConfig.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 17 - ] - }, - "com.piggymetrics.statistics.config.ResourceServerConfig.tokenServices:()Lorg/springframework/security/oauth2/provider/token/ResourceServerTokenServices;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 23 - ] - }, - "com.piggymetrics.statistics.controller.StatisticsController.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 15 - ] - }, - "com.piggymetrics.statistics.controller.StatisticsController.getCurrentAccountStatistics:(Ljava/security/Principal;)Ljava/util/List;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 22 - ] - }, - "com.piggymetrics.statistics.controller.StatisticsController.getStatisticsByAccountName:(Ljava/lang/String;)Ljava/util/List;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 28 - ] - }, - "com.piggymetrics.statistics.controller.StatisticsController.saveAccountStatistics:(Ljava/lang/String;Lcom/piggymetrics/statistics/domain/Account;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 34, - 35 - ] - }, - "com.piggymetrics.statistics.domain.Account.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 12 - ] - }, - "com.piggymetrics.statistics.domain.Account.getExpenses:()Ljava/util/List;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 35 - ] - }, - "com.piggymetrics.statistics.domain.Account.getIncomes:()Ljava/util/List;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 27 - ] - }, - "com.piggymetrics.statistics.domain.Account.getSaving:()Lcom/piggymetrics/statistics/domain/Saving;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 43 - ] - }, - "com.piggymetrics.statistics.domain.Account.setExpenses:(Ljava/util/List;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 39, - 40 - ] - }, - "com.piggymetrics.statistics.domain.Account.setIncomes:(Ljava/util/List;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 31, - 32 - ] - }, - "com.piggymetrics.statistics.domain.Account.setSaving:(Lcom/piggymetrics/statistics/domain/Saving;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 47, - 48 - ] - }, - "com.piggymetrics.statistics.domain.Currency.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 5, - 3 - ] - }, - "com.piggymetrics.statistics.domain.Currency.:(Ljava/lang/String;I)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.statistics.domain.Currency.getBase:()Lcom/piggymetrics/statistics/domain/Currency;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 8 - ] - }, - "com.piggymetrics.statistics.domain.Currency.valueOf:(Ljava/lang/String;)Lcom/piggymetrics/statistics/domain/Currency;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.statistics.domain.Currency.values:()[Lcom/piggymetrics/statistics/domain/Currency;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.statistics.domain.ExchangeRatesContainer.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 10, - 12 - ] - }, - "com.piggymetrics.statistics.domain.ExchangeRatesContainer.getBase:()Lcom/piggymetrics/statistics/domain/Currency;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 27 - ] - }, - "com.piggymetrics.statistics.domain.ExchangeRatesContainer.getDate:()Ljava/time/LocalDate;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 19 - ] - }, - "com.piggymetrics.statistics.domain.ExchangeRatesContainer.getRates:()Ljava/util/Map;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 35 - ] - }, - "com.piggymetrics.statistics.domain.ExchangeRatesContainer.setBase:(Lcom/piggymetrics/statistics/domain/Currency;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 31, - 32 - ] - }, - "com.piggymetrics.statistics.domain.ExchangeRatesContainer.setDate:(Ljava/time/LocalDate;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 23, - 24 - ] - }, - "com.piggymetrics.statistics.domain.ExchangeRatesContainer.setRates:(Ljava/util/Map;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 39, - 40 - ] - }, - "com.piggymetrics.statistics.domain.ExchangeRatesContainer.toString:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T020", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 44 - ] - }, - "com.piggymetrics.statistics.domain.Item.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 8 - ] - }, - "com.piggymetrics.statistics.domain.Item.getAmount:()Ljava/math/BigDecimal;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 32 - ] - }, - "com.piggymetrics.statistics.domain.Item.getCurrency:()Lcom/piggymetrics/statistics/domain/Currency;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 40 - ] - }, - "com.piggymetrics.statistics.domain.Item.getPeriod:()Lcom/piggymetrics/statistics/domain/TimePeriod;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 48 - ] - }, - "com.piggymetrics.statistics.domain.Item.getTitle:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 24 - ] - }, - "com.piggymetrics.statistics.domain.Item.setAmount:(Ljava/math/BigDecimal;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 36, - 37 - ] - }, - "com.piggymetrics.statistics.domain.Item.setCurrency:(Lcom/piggymetrics/statistics/domain/Currency;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 44, - 45 - ] - }, - "com.piggymetrics.statistics.domain.Item.setPeriod:(Lcom/piggymetrics/statistics/domain/TimePeriod;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 52, - 53 - ] - }, - "com.piggymetrics.statistics.domain.Item.setTitle:(Ljava/lang/String;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 28, - 29 - ] - }, - "com.piggymetrics.statistics.domain.Saving.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 6 - ] - }, - "com.piggymetrics.statistics.domain.Saving.getAmount:()Ljava/math/BigDecimal;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 24 - ] - }, - "com.piggymetrics.statistics.domain.Saving.getCapitalization:()Ljava/lang/Boolean;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 56 - ] - }, - "com.piggymetrics.statistics.domain.Saving.getCurrency:()Lcom/piggymetrics/statistics/domain/Currency;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 32 - ] - }, - "com.piggymetrics.statistics.domain.Saving.getDeposit:()Ljava/lang/Boolean;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 48 - ] - }, - "com.piggymetrics.statistics.domain.Saving.getInterest:()Ljava/math/BigDecimal;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 40 - ] - }, - "com.piggymetrics.statistics.domain.Saving.setAmount:(Ljava/math/BigDecimal;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 28, - 29 - ] - }, - "com.piggymetrics.statistics.domain.Saving.setCapitalization:(Ljava/lang/Boolean;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 60, - 61 - ] - }, - "com.piggymetrics.statistics.domain.Saving.setCurrency:(Lcom/piggymetrics/statistics/domain/Currency;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 36, - 37 - ] - }, - "com.piggymetrics.statistics.domain.Saving.setDeposit:(Ljava/lang/Boolean;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 52, - 53 - ] - }, - "com.piggymetrics.statistics.domain.Saving.setInterest:(Ljava/math/BigDecimal;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 44, - 45 - ] - }, - "com.piggymetrics.statistics.domain.TimePeriod.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 7, - 5 - ] - }, - "com.piggymetrics.statistics.domain.TimePeriod.:(Ljava/lang/String;ID)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 11, - 12, - 13 - ] - }, - "com.piggymetrics.statistics.domain.TimePeriod.getBase:()Lcom/piggymetrics/statistics/domain/TimePeriod;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 20 - ] - }, - "com.piggymetrics.statistics.domain.TimePeriod.getBaseRatio:()Ljava/math/BigDecimal;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 16 - ] - }, - "com.piggymetrics.statistics.domain.TimePeriod.valueOf:(Ljava/lang/String;)Lcom/piggymetrics/statistics/domain/TimePeriod;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 5 - ] - }, - "com.piggymetrics.statistics.domain.TimePeriod.values:()[Lcom/piggymetrics/statistics/domain/TimePeriod;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 5 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.:()V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 16 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.getExpenses:()Ljava/util/Set;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 46 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.getId:()Lcom/piggymetrics/statistics/domain/timeseries/DataPointId;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 30 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.getIncomes:()Ljava/util/Set;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 38 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.getRates:()Ljava/util/Map;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 62 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.getStatistics:()Ljava/util/Map;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 54 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.setExpenses:(Ljava/util/Set;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 50, - 51 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.setId:(Lcom/piggymetrics/statistics/domain/timeseries/DataPointId;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 34, - 35 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.setIncomes:(Ljava/util/Set;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 42, - 43 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.setRates:(Ljava/util/Map;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 66, - 67 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPoint.setStatistics:(Ljava/util/Map;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 58, - 59 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPointId.:(Ljava/lang/String;Ljava/util/Date;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 14, - 15, - 16, - 17 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPointId.getAccount:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 20 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPointId.getDate:()Ljava/util/Date;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 24 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.DataPointId.toString:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T020", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 29 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.ItemMetric.:(Ljava/lang/String;Ljava/math/BigDecimal;)V" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 18, - 19, - 20, - 21 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.ItemMetric.equals:(Ljava/lang/Object;)Z" : { - "completeTestCount" : 5, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 5 - }, - "lineNumbers" : [ - 33, - 34, - 36, - 38 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.ItemMetric.getAmount:()Ljava/math/BigDecimal;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 28 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.ItemMetric.getTitle:()Ljava/lang/String;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T001", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 24 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.ItemMetric.hashCode:()I" : { - "completeTestCount" : 5, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 5 - }, - "lineNumbers" : [ - 44 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.StatisticMetric.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 5, - 3 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.StatisticMetric.:(Ljava/lang/String;I)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.StatisticMetric.valueOf:(Ljava/lang/String;)Lcom/piggymetrics/statistics/domain/timeseries/StatisticMetric;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.statistics.domain.timeseries.StatisticMetric.values:()[Lcom/piggymetrics/statistics/domain/timeseries/StatisticMetric;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 3 - ] - }, - "com.piggymetrics.statistics.repository.DataPointRepository.count:()J" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.delete:(Ljava/lang/Object;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.deleteAll:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.deleteAll:(Ljava/lang/Iterable;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.deleteById:(Ljava/lang/Object;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.existsById:(Ljava/lang/Object;)Z" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.findAll:()Ljava/lang/Iterable;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.findAllById:(Ljava/lang/Iterable;)Ljava/lang/Iterable;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.findById:(Ljava/lang/Object;)Ljava/util/Optional;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.findByIdAccount:(Ljava/lang/String;)Ljava/util/List;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.save:(Ljava/lang/Object;)Ljava/lang/Object;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.DataPointRepository.saveAll:(Ljava/lang/Iterable;)Ljava/lang/Iterable;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "E052" - }, - "com.piggymetrics.statistics.repository.converter.DataPointIdReaderConverter.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 11 - ] - }, - "com.piggymetrics.statistics.repository.converter.DataPointIdReaderConverter.convert:(Lcom/mongodb/DBObject;)Lcom/piggymetrics/statistics/domain/timeseries/DataPointId;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R013", - "lineNumbers" : [ - 16, - 17, - 19 - ] - }, - "com.piggymetrics.statistics.repository.converter.DataPointIdReaderConverter.convert:(Ljava/lang/Object;)Ljava/lang/Object;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 10 - ] - }, - "com.piggymetrics.statistics.repository.converter.DataPointIdWriterConverter.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 10 - ] - }, - "com.piggymetrics.statistics.repository.converter.DataPointIdWriterConverter.convert:(Lcom/piggymetrics/statistics/domain/timeseries/DataPointId;)Lcom/mongodb/DBObject;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 17, - 19, - 20, - 22 - ] - }, - "com.piggymetrics.statistics.repository.converter.DataPointIdWriterConverter.convert:(Ljava/lang/Object;)Ljava/lang/Object;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 9 - ] - }, - "com.piggymetrics.statistics.service.ExchangeRatesService.convert:(Lcom/piggymetrics/statistics/domain/Currency;Lcom/piggymetrics/statistics/domain/Currency;Ljava/math/BigDecimal;)Ljava/math/BigDecimal;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.statistics.service.ExchangeRatesService.getCurrentRates:()Ljava/util/Map;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.statistics.service.ExchangeRatesServiceImpl.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 21 - ] - }, - "com.piggymetrics.statistics.service.ExchangeRatesServiceImpl.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T005", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 19 - ] - }, - "com.piggymetrics.statistics.service.ExchangeRatesServiceImpl.convert:(Lcom/piggymetrics/statistics/domain/Currency;Lcom/piggymetrics/statistics/domain/Currency;Ljava/math/BigDecimal;)Ljava/math/BigDecimal;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R013", - "lineNumbers" : [ - 52, - 54, - 55, - 57 - ] - }, - "com.piggymetrics.statistics.service.ExchangeRatesServiceImpl.getCurrentRates:()Ljava/util/Map;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R011", - "lineNumbers" : [ - 34, - 35, - 36, - 39, - 40, - 41, - 39 - ] - }, - "com.piggymetrics.statistics.service.StatisticsService.findByAccountName:(Ljava/lang/String;)Ljava/util/List;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.statistics.service.StatisticsService.save:(Ljava/lang/String;Lcom/piggymetrics/statistics/domain/Account;)Lcom/piggymetrics/statistics/domain/timeseries/DataPoint;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T010", - "perMethodOutcome" : "T010" - }, - "com.piggymetrics.statistics.service.StatisticsServiceImpl.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "T005", - "lineNumbers" : [ - 28, - 30 - ] - }, - "com.piggymetrics.statistics.service.StatisticsServiceImpl.createItemMetric:(Lcom/piggymetrics/statistics/domain/Item;)Lcom/piggymetrics/statistics/domain/timeseries/ItemMetric;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 105, - 106, - 107, - 109 - ] - }, - "com.piggymetrics.statistics.service.StatisticsServiceImpl.createStatisticMetrics:(Ljava/util/Set;Ljava/util/Set;Lcom/piggymetrics/statistics/domain/Saving;)Ljava/util/Map;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 82, - 84, - 85, - 86, - 88, - 89, - 90, - 92 - ] - }, - "com.piggymetrics.statistics.service.StatisticsServiceImpl.findByAccountName:(Ljava/lang/String;)Ljava/util/List;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 43, - 44 - ] - }, - "com.piggymetrics.statistics.service.StatisticsServiceImpl.save:(Ljava/lang/String;Lcom/piggymetrics/statistics/domain/Account;)Lcom/piggymetrics/statistics/domain/timeseries/DataPoint;" : { - "completeTestCount" : 4, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 4 - }, - "lineNumbers" : [ - 53, - 54, - 56, - 58, - 59, - 60, - 62, - 63, - 64, - 66, - 68, - 69, - 70, - 71, - 72, - 73, - 75, - 77 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.:()V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T012", - "perMethodOutcome" : "T012", - "lineNumbers" : [ - 33 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.:(Ljava/lang/String;Ljava/lang/String;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R004", - "lineNumbers" : [ - 46, - 31, - 42, - 44, - 47, - 48, - 49 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.extractAuthentication:(Ljava/util/Map;)Lorg/springframework/security/oauth2/provider/OAuth2Authentication;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 75, - 76, - 77, - 78, - 79, - 81, - 82 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.getMap:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/Map;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 113, - 115, - 116, - 117, - 118, - 119, - 121, - 122, - 123, - 124, - 126, - 127, - 129, - 131, - 132, - 133, - 132, - 134 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.getPrincipal:(Ljava/util/Map;)Ljava/lang/Object;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 86, - 87, - 88, - 86, - 91 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.getRequest:(Ljava/util/Map;)Lorg/springframework/security/oauth2/provider/OAuth2Request;" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T003", - "perMethodOutcome" : "T003", - "lineNumbers" : [ - 96, - 98, - 99, - 100, - 102 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.loadAuthentication:(Ljava/lang/String;)Lorg/springframework/security/oauth2/provider/OAuth2Authentication;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 66, - 67, - 68, - 69, - 71 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.readAccessToken:(Ljava/lang/String;)Lorg/springframework/security/oauth2/common/OAuth2AccessToken;" : { - "completeTestCount" : 1, - "incompleteTestCount" : 0, - "perMethodTestability" : "T000", - "perMethodOutcome" : "R000", - "perTestOutcome" : { - "R000" : 1 - }, - "lineNumbers" : [ - 108 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.setAuthoritiesExtractor:(Lorg/springframework/boot/autoconfigure/security/oauth2/resource/AuthoritiesExtractor;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R002", - "lineNumbers" : [ - 60, - 61 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.setRestTemplate:(Lorg/springframework/security/oauth2/client/OAuth2RestOperations;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R002", - "lineNumbers" : [ - 56, - 57 - ] - }, - "com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices.setTokenType:(Ljava/lang/String;)V" : { - "completeTestCount" : 0, - "incompleteTestCount" : 0, - "perMethodTestability" : "T002", - "perMethodOutcome" : "R002", - "lineNumbers" : [ - 52, - 53 - ] - } - } -} \ No newline at end of file diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsApplicationDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsApplicationDiffblueTest.java new file mode 100644 index 00000000..56f5c064 --- /dev/null +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsApplicationDiffblueTest.java @@ -0,0 +1,83 @@ +package com.piggymetrics.statistics; + +import com.piggymetrics.statistics.StatisticsApplication.CustomConversionsConfig; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@ContextConfiguration(classes = {StatisticsApplication.CustomConversionsConfig.class}) +@RunWith(SpringJUnit4ClassRunner.class) +public class StatisticsApplicationDiffblueTest { + @Autowired + private StatisticsApplication.CustomConversionsConfig customConversionsConfig; + + /** + * Test CustomConversionsConfig + * {@link CustomConversionsConfig#customConversions()}. + *

+ * Method under test: + * {@link StatisticsApplication.CustomConversionsConfig#customConversions()} + */ + @Test + @Ignore("TODO: Complete this test") + public void testCustomConversionsConfigCustomConversions() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + customConversionsConfig.customConversions(); + } +} diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java b/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java deleted file mode 100644 index d3c52e0d..00000000 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.piggymetrics.statistics; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class StatisticsServiceApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientFallbackDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientFallbackDiffblueTest.java index 6778d430..50ca59eb 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientFallbackDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientFallbackDiffblueTest.java @@ -2,8 +2,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; + import com.piggymetrics.statistics.domain.Currency; import com.piggymetrics.statistics.domain.ExchangeRatesContainer; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -13,21 +15,90 @@ @ContextConfiguration(classes = {ExchangeRatesClientFallback.class}) @RunWith(SpringJUnit4ClassRunner.class) public class ExchangeRatesClientFallbackDiffblueTest { - @Autowired - private ExchangeRatesClientFallback exchangeRatesClientFallback; - - /** - * Test {@link ExchangeRatesClientFallback#getRates(Currency)}. - *

- * Method under test: {@link ExchangeRatesClientFallback#getRates(Currency)} - */ - @Test - public void testGetRates() { - // Arrange and Act - ExchangeRatesContainer actualRates = exchangeRatesClientFallback.getRates(Currency.USD); - - // Assert - assertEquals(Currency.USD, actualRates.getBase()); - assertTrue(actualRates.getRates().isEmpty()); - } + @Autowired + private ExchangeRatesClientFallback exchangeRatesClientFallback; + + /** + * Test {@link ExchangeRatesClientFallback#getRates(Currency)}. + *

+ * Method under test: {@link ExchangeRatesClientFallback#getRates(Currency)} + */ + @Test + public void testGetRates() { + // Diffblue Cover was unable to create a Spring-specific test for this Spring method. + // Run dcover create --keep-partial-tests to gain insights into why + // a non-Spring test was created. + + // Arrange and Act + ExchangeRatesContainer actualRates = (new ExchangeRatesClientFallback()).getRates(Currency.USD); + + // Assert + assertEquals(Currency.USD, actualRates.getBase()); + assertTrue(actualRates.getRates().isEmpty()); + } + + /** + * Test {@link ExchangeRatesClientFallback#getRates(Currency)}. + *

+ * Method under test: {@link ExchangeRatesClientFallback#getRates(Currency)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testGetRates2() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + exchangeRatesClientFallback.getRates(Currency.USD); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java deleted file mode 100644 index bd4dc511..00000000 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.piggymetrics.statistics.client; - -import com.piggymetrics.statistics.domain.Currency; -import com.piggymetrics.statistics.domain.ExchangeRatesContainer; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.time.LocalDate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class ExchangeRatesClientTest { - - @Autowired - private ExchangeRatesClient client; - - @Test - public void shouldRetrieveExchangeRates() { - - ExchangeRatesContainer container = client.getRates(Currency.getBase()); - - assertEquals(container.getDate(), LocalDate.now()); - assertEquals(container.getBase(), Currency.getBase()); - - assertNotNull(container.getRates()); - assertNotNull(container.getRates().get(Currency.USD.name())); - assertNotNull(container.getRates().get(Currency.EUR.name())); - assertNotNull(container.getRates().get(Currency.RUB.name())); - } - - @Test - public void shouldRetrieveExchangeRatesForSpecifiedCurrency() { - - Currency requestedCurrency = Currency.EUR; - ExchangeRatesContainer container = client.getRates(Currency.getBase()); - - assertEquals(container.getDate(), LocalDate.now()); - assertEquals(container.getBase(), Currency.getBase()); - - assertNotNull(container.getRates()); - assertNotNull(container.getRates().get(requestedCurrency.name())); - } -} \ No newline at end of file diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/config/ResourceServerConfigDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/config/ResourceServerConfigDiffblueTest.java index 10b34405..e82bce65 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/config/ResourceServerConfigDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/config/ResourceServerConfigDiffblueTest.java @@ -1,40 +1,84 @@ package com.piggymetrics.statistics.config; -import static org.junit.Assert.assertTrue; -import com.piggymetrics.statistics.repository.DataPointRepository; -import com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices; -import de.flapdoodle.embed.mongo.MongodExecutable; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@SpringBootTest +@ContextConfiguration(classes = {ResourceServerConfig.class, ResourceServerProperties.class}) @RunWith(SpringJUnit4ClassRunner.class) public class ResourceServerConfigDiffblueTest { - @MockBean - private DataPointRepository dataPointRepository; + @Autowired + private ResourceServerConfig resourceServerConfig; - @MockBean - private MongodExecutable mongodExecutable; + @Autowired + private ResourceServerProperties resourceServerProperties; - @Autowired - private ResourceServerConfig resourceServerConfig; + /** + * Test {@link ResourceServerConfig#tokenServices()}. + *

+ * Method under test: {@link ResourceServerConfig#tokenServices()} + */ + @Test + @Ignore("TODO: Complete this test") + public void testTokenServices() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. - @Autowired - private ResourceServerProperties resourceServerProperties; - - /** - * Test {@link ResourceServerConfig#tokenServices()}. - *

- * Method under test: {@link ResourceServerConfig#tokenServices()} - */ - @Test - public void testTokenServices() { - // Arrange, Act and Assert - assertTrue(resourceServerConfig.tokenServices() instanceof CustomUserInfoTokenServices); - } + // Arrange and Act + resourceServerConfig.tokenServices(); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerDiffblueTest.java index 0c4b59a2..1813e3dd 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerDiffblueTest.java @@ -1,125 +1,94 @@ package com.piggymetrics.statistics.controller; -import static org.mockito.Mockito.when; -import com.fasterxml.jackson.databind.ObjectMapper; import com.piggymetrics.statistics.domain.Account; -import com.piggymetrics.statistics.domain.Currency; -import com.piggymetrics.statistics.domain.Saving; import com.piggymetrics.statistics.domain.timeseries.DataPoint; -import com.piggymetrics.statistics.domain.timeseries.DataPointId; -import com.piggymetrics.statistics.service.StatisticsService; -import com.sun.security.auth.UserPrincipal; -import java.math.BigDecimal; + import java.security.Principal; -import java.time.LocalDate; -import java.time.ZoneOffset; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; +import java.util.List; + +import org.junit.Ignore; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -@ContextConfiguration(classes = {StatisticsController.class}) -@RunWith(SpringJUnit4ClassRunner.class) public class StatisticsControllerDiffblueTest { - @Autowired - private StatisticsController statisticsController; + /** + * Test {@link StatisticsController#getCurrentAccountStatistics(Principal)}. + *

+ * Method under test: + * {@link StatisticsController#getCurrentAccountStatistics(Principal)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testGetCurrentAccountStatistics() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Unable to load class. + // Class: jakarta.servlet.ServletContext + // Please check that the class is available on your test runtime classpath. + // See https://diff.blue/R005 to resolve this issue. + + // Arrange + // TODO: Populate arranged inputs + StatisticsController statisticsController = null; + Principal principal = null; + + // Act + List actualCurrentAccountStatistics = statisticsController.getCurrentAccountStatistics(principal); - @MockBean - private StatisticsService statisticsService; + // Assert + // TODO: Add assertions on result + } - /** - * Test {@link StatisticsController#getCurrentAccountStatistics(Principal)}. - *

- * Method under test: - * {@link StatisticsController#getCurrentAccountStatistics(Principal)} - */ - @Test - public void testGetCurrentAccountStatistics() throws Exception { - // Arrange - when(statisticsService.findByAccountName(Mockito.any())).thenReturn(new ArrayList<>()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/current"); - requestBuilder.principal(new UserPrincipal("principal")); + /** + * Test {@link StatisticsController#getStatisticsByAccountName(String)}. + *

+ * Method under test: + * {@link StatisticsController#getStatisticsByAccountName(String)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testGetStatisticsByAccountName() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Unable to load class. + // Class: jakarta.servlet.ServletContext + // Please check that the class is available on your test runtime classpath. + // See https://diff.blue/R005 to resolve this issue. - // Act and Assert - MockMvcBuilders.standaloneSetup(statisticsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) - .andExpect(MockMvcResultMatchers.content().string("[]")); - } + // Arrange + // TODO: Populate arranged inputs + StatisticsController statisticsController = null; + String accountName = ""; - /** - * Test {@link StatisticsController#getStatisticsByAccountName(String)}. - *

- * Method under test: - * {@link StatisticsController#getStatisticsByAccountName(String)} - */ - @Test - public void testGetStatisticsByAccountName() throws Exception { - // Arrange - when(statisticsService.findByAccountName(Mockito.any())).thenReturn(new ArrayList<>()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/{accountName}", "Dr Jane Doe"); + // Act + List actualStatisticsByAccountName = statisticsController.getStatisticsByAccountName(accountName); - // Act and Assert - MockMvcBuilders.standaloneSetup(statisticsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) - .andExpect(MockMvcResultMatchers.content().string("[]")); - } + // Assert + // TODO: Add assertions on result + } - /** - * Test {@link StatisticsController#saveAccountStatistics(String, Account)}. - *

- * Method under test: - * {@link StatisticsController#saveAccountStatistics(String, Account)} - */ - @Test - public void testSaveAccountStatistics() throws Exception { - // Arrange - DataPoint dataPoint = new DataPoint(); - dataPoint.setExpenses(new HashSet<>()); - dataPoint.setId( - new DataPointId("3", Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()))); - dataPoint.setIncomes(new HashSet<>()); - dataPoint.setRates(new HashMap<>()); - dataPoint.setStatistics(new HashMap<>()); - when(statisticsService.save(Mockito.any(), Mockito.any())).thenReturn(dataPoint); + /** + * Test {@link StatisticsController#saveAccountStatistics(String, Account)}. + *

+ * Method under test: + * {@link StatisticsController#saveAccountStatistics(String, Account)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testSaveAccountStatistics() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Unable to load class. + // Class: jakarta.servlet.ServletContext + // Please check that the class is available on your test runtime classpath. + // See https://diff.blue/R005 to resolve this issue. - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); + // Arrange + // TODO: Populate arranged inputs + StatisticsController statisticsController = null; + String accountName = ""; + Account account = null; - Account account = new Account(); - account.setExpenses(new ArrayList<>()); - account.setIncomes(new ArrayList<>()); - account.setSaving(saving); - String content = (new ObjectMapper()).writeValueAsString(account); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/{accountName}", "Dr Jane Doe") - .contentType(MediaType.APPLICATION_JSON) - .content(content); + // Act + statisticsController.saveAccountStatistics(accountName, account); - // Act and Assert - MockMvcBuilders.standaloneSetup(statisticsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()); - } + // Assert + // TODO: Add assertions on result + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java deleted file mode 100644 index 6040a217..00000000 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.piggymetrics.statistics.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.ImmutableList; -import com.piggymetrics.statistics.domain.Account; -import com.piggymetrics.statistics.domain.Currency; -import com.piggymetrics.statistics.domain.Item; -import com.piggymetrics.statistics.domain.Saving; -import com.piggymetrics.statistics.domain.TimePeriod; -import com.piggymetrics.statistics.domain.timeseries.DataPoint; -import com.piggymetrics.statistics.domain.timeseries.DataPointId; -import com.piggymetrics.statistics.service.StatisticsService; -import com.sun.security.auth.UserPrincipal; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import java.math.BigDecimal; -import java.util.Date; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.mockito.internal.verification.VerificationModeFactory.times; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class StatisticsControllerTest { - - private static final ObjectMapper mapper = new ObjectMapper(); - - @InjectMocks - private StatisticsController statisticsController; - - @Mock - private StatisticsService statisticsService; - - private MockMvc mockMvc; - - @Before - public void setup() { - initMocks(this); - this.mockMvc = MockMvcBuilders.standaloneSetup(statisticsController).build(); - } - - @Test - public void shouldGetStatisticsByAccountName() throws Exception { - - final DataPoint dataPoint = new DataPoint(); - dataPoint.setId(new DataPointId("test", new Date())); - - when(statisticsService.findByAccountName(dataPoint.getId().getAccount())) - .thenReturn(ImmutableList.of(dataPoint)); - - mockMvc.perform(get("/test").principal(new UserPrincipal(dataPoint.getId().getAccount()))) - .andExpect(jsonPath("$[0].id.account").value(dataPoint.getId().getAccount())) - .andExpect(status().isOk()); - } - - @Test - public void shouldGetCurrentAccountStatistics() throws Exception { - - final DataPoint dataPoint = new DataPoint(); - dataPoint.setId(new DataPointId("test", new Date())); - - when(statisticsService.findByAccountName(dataPoint.getId().getAccount())) - .thenReturn(ImmutableList.of(dataPoint)); - - mockMvc.perform(get("/current").principal(new UserPrincipal(dataPoint.getId().getAccount()))) - .andExpect(jsonPath("$[0].id.account").value(dataPoint.getId().getAccount())) - .andExpect(status().isOk()); - } - - @Test - public void shouldSaveAccountStatistics() throws Exception { - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal(1500)); - saving.setCurrency(Currency.USD); - saving.setInterest(new BigDecimal("3.32")); - saving.setDeposit(true); - saving.setCapitalization(false); - - Item grocery = new Item(); - grocery.setTitle("Grocery"); - grocery.setAmount(new BigDecimal(10)); - grocery.setCurrency(Currency.USD); - grocery.setPeriod(TimePeriod.DAY); - - Item salary = new Item(); - salary.setTitle("Salary"); - salary.setAmount(new BigDecimal(9100)); - salary.setCurrency(Currency.USD); - salary.setPeriod(TimePeriod.MONTH); - - final Account account = new Account(); - account.setSaving(saving); - account.setExpenses(ImmutableList.of(grocery)); - account.setIncomes(ImmutableList.of(salary)); - - String json = mapper.writeValueAsString(account); - - mockMvc.perform(put("/test").contentType(MediaType.APPLICATION_JSON).content(json)) - .andExpect(status().isOk()); - - verify(statisticsService, times(1)).save(anyString(), any(Account.class)); - } -} \ No newline at end of file diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/AccountDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/AccountDiffblueTest.java index 7043f581..301dc25c 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/AccountDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/AccountDiffblueTest.java @@ -2,50 +2,95 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; + import org.junit.Test; public class AccountDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link Account} - *
  • {@link Account#setExpenses(List)} - *
  • {@link Account#setIncomes(List)} - *
  • {@link Account#setSaving(Saving)} - *
  • {@link Account#getExpenses()} - *
  • {@link Account#getIncomes()} - *
  • {@link Account#getSaving()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - Account actualAccount = new Account(); - ArrayList expenses = new ArrayList<>(); - actualAccount.setExpenses(expenses); - ArrayList incomes = new ArrayList<>(); - actualAccount.setIncomes(incomes); - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - actualAccount.setSaving(saving); - List actualExpenses = actualAccount.getExpenses(); - List actualIncomes = actualAccount.getIncomes(); - Saving actualSaving = actualAccount.getSaving(); - - // Assert - assertTrue(actualExpenses.isEmpty()); - assertTrue(actualIncomes.isEmpty()); - assertSame(saving, actualSaving); - assertSame(expenses, actualExpenses); - assertSame(incomes, actualIncomes); - } + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Account#setExpenses(List)} + *
  • {@link Account#setIncomes(List)} + *
  • {@link Account#setSaving(Saving)} + *
  • {@link Account#getExpenses()} + *
  • {@link Account#getIncomes()} + *
  • {@link Account#getSaving()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + Account account = new Account(); + ArrayList expenses = new ArrayList<>(); + + // Act + account.setExpenses(expenses); + ArrayList incomes = new ArrayList<>(); + account.setIncomes(incomes); + Saving saving = new Saving(); + saving.setAmount(new BigDecimal("2.3")); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + saving.setInterest(new BigDecimal("2.3")); + account.setSaving(saving); + List actualExpenses = account.getExpenses(); + List actualIncomes = account.getIncomes(); + Saving actualSaving = account.getSaving(); + + // Assert + assertTrue(actualExpenses.isEmpty()); + assertTrue(actualIncomes.isEmpty()); + assertSame(saving, actualSaving); + assertSame(expenses, actualExpenses); + assertSame(incomes, actualIncomes); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Account#setExpenses(List)} + *
  • {@link Account#setIncomes(List)} + *
  • {@link Account#setSaving(Saving)} + *
  • {@link Account#getExpenses()} + *
  • {@link Account#getIncomes()} + *
  • {@link Account#getSaving()} + *
+ */ + @Test + public void testGettersAndSetters2() { + // Arrange + Account account = new Account(); + ArrayList expenses = new ArrayList<>(); + + // Act + account.setExpenses(expenses); + ArrayList incomes = new ArrayList<>(); + account.setIncomes(incomes); + Saving saving = new Saving(); + saving.setAmount(new BigDecimal("2.6")); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + saving.setInterest(new BigDecimal("2.6")); + account.setSaving(saving); + List actualExpenses = account.getExpenses(); + List actualIncomes = account.getIncomes(); + Saving actualSaving = account.getSaving(); + + // Assert + assertTrue(actualExpenses.isEmpty()); + assertTrue(actualIncomes.isEmpty()); + assertSame(saving, actualSaving); + assertSame(expenses, actualExpenses); + assertSame(incomes, actualIncomes); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/CurrencyDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/CurrencyDiffblueTest.java deleted file mode 100644 index ec9af9fa..00000000 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/CurrencyDiffblueTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.piggymetrics.statistics.domain; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; - -public class CurrencyDiffblueTest { - /** - * Test {@link Currency#getBase()}. - *

- * Method under test: {@link Currency#getBase()} - */ - @Test - public void testGetBase() { - // Arrange, Act and Assert - assertEquals(Currency.USD, Currency.valueOf("USD").getBase()); - } -} diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/ExchangeRatesContainerDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/ExchangeRatesContainerDiffblueTest.java index b612a59b..cab11431 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/ExchangeRatesContainerDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/ExchangeRatesContainerDiffblueTest.java @@ -1,68 +1,53 @@ package com.piggymetrics.statistics.domain; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; + import java.math.BigDecimal; import java.time.LocalDate; import java.util.HashMap; import java.util.Map; + import org.junit.Test; public class ExchangeRatesContainerDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • {@link ExchangeRatesContainer#setBase(Currency)} - *
  • {@link ExchangeRatesContainer#setDate(LocalDate)} - *
  • {@link ExchangeRatesContainer#setRates(Map)} - *
  • {@link ExchangeRatesContainer#toString()} - *
  • {@link ExchangeRatesContainer#getBase()} - *
  • {@link ExchangeRatesContainer#getDate()} - *
  • {@link ExchangeRatesContainer#getRates()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange - ExchangeRatesContainer exchangeRatesContainer = new ExchangeRatesContainer(); - - // Act - exchangeRatesContainer.setBase(Currency.USD); - LocalDate date = LocalDate.of(1970, 1, 1); - exchangeRatesContainer.setDate(date); - HashMap rates = new HashMap<>(); - exchangeRatesContainer.setRates(rates); - String actualToStringResult = exchangeRatesContainer.toString(); - Currency actualBase = exchangeRatesContainer.getBase(); - LocalDate actualDate = exchangeRatesContainer.getDate(); - Map actualRates = exchangeRatesContainer.getRates(); - - // Assert - assertEquals("1970-01-01", actualDate.toString()); - assertEquals("RateList{date=1970-01-01, base=USD, rates={}}", actualToStringResult); - assertEquals(Currency.USD, actualBase); - assertTrue(actualRates.isEmpty()); - assertSame(rates, actualRates); - assertSame(date, actualDate); - } + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link ExchangeRatesContainer#setBase(Currency)} + *
  • {@link ExchangeRatesContainer#setDate(LocalDate)} + *
  • {@link ExchangeRatesContainer#setRates(Map)} + *
  • {@link ExchangeRatesContainer#toString()} + *
  • {@link ExchangeRatesContainer#getBase()} + *
  • {@link ExchangeRatesContainer#getDate()} + *
  • {@link ExchangeRatesContainer#getRates()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + ExchangeRatesContainer exchangeRatesContainer = new ExchangeRatesContainer(); - /** - * Test new {@link ExchangeRatesContainer} (default constructor). - *

- * Method under test: default or parameterless constructor of - * {@link ExchangeRatesContainer} - */ - @Test - public void testNewExchangeRatesContainer() { - // Arrange and Act - ExchangeRatesContainer actualExchangeRatesContainer = new ExchangeRatesContainer(); + // Act + exchangeRatesContainer.setBase(Currency.USD); + LocalDate date = LocalDate.of(1970, 1, 1); + exchangeRatesContainer.setDate(date); + HashMap rates = new HashMap<>(); + exchangeRatesContainer.setRates(rates); + String actualToStringResult = exchangeRatesContainer.toString(); + Currency actualBase = exchangeRatesContainer.getBase(); + LocalDate actualDate = exchangeRatesContainer.getDate(); + Map actualRates = exchangeRatesContainer.getRates(); - // Assert - assertNull(actualExchangeRatesContainer.getBase()); - assertNull(actualExchangeRatesContainer.getRates()); - } + // Assert + assertEquals("1970-01-01", actualDate.toString()); + assertEquals("RateList{date=1970-01-01, base=USD, rates={}}", actualToStringResult); + assertEquals(Currency.USD, actualBase); + assertTrue(actualRates.isEmpty()); + assertSame(rates, actualRates); + assertSame(date, actualDate); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/ItemDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/ItemDiffblueTest.java index b2dd654a..27f177cb 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/ItemDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/ItemDiffblueTest.java @@ -2,44 +2,85 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; + import java.math.BigDecimal; + import org.junit.Test; public class ItemDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link Item} - *
  • {@link Item#setAmount(BigDecimal)} - *
  • {@link Item#setCurrency(Currency)} - *
  • {@link Item#setPeriod(TimePeriod)} - *
  • {@link Item#setTitle(String)} - *
  • {@link Item#getAmount()} - *
  • {@link Item#getCurrency()} - *
  • {@link Item#getPeriod()} - *
  • {@link Item#getTitle()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - Item actualItem = new Item(); - BigDecimal amount = new BigDecimal("2.3"); - actualItem.setAmount(amount); - actualItem.setCurrency(Currency.USD); - actualItem.setPeriod(TimePeriod.YEAR); - actualItem.setTitle("Dr"); - BigDecimal actualAmount = actualItem.getAmount(); - Currency actualCurrency = actualItem.getCurrency(); - TimePeriod actualPeriod = actualItem.getPeriod(); - - // Assert - assertEquals("Dr", actualItem.getTitle()); - assertEquals(Currency.USD, actualCurrency); - assertEquals(TimePeriod.YEAR, actualPeriod); - assertEquals(new BigDecimal("2.3"), actualAmount); - assertSame(amount, actualAmount); - } + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Item#setAmount(BigDecimal)} + *
  • {@link Item#setCurrency(Currency)} + *
  • {@link Item#setPeriod(TimePeriod)} + *
  • {@link Item#setTitle(String)} + *
  • {@link Item#getAmount()} + *
  • {@link Item#getCurrency()} + *
  • {@link Item#getPeriod()} + *
  • {@link Item#getTitle()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + Item item = new Item(); + BigDecimal amount = new BigDecimal("2.3"); + + // Act + item.setAmount(amount); + item.setCurrency(Currency.USD); + item.setPeriod(TimePeriod.YEAR); + item.setTitle("Dr"); + BigDecimal actualAmount = item.getAmount(); + Currency actualCurrency = item.getCurrency(); + TimePeriod actualPeriod = item.getPeriod(); + + // Assert + assertEquals("Dr", item.getTitle()); + assertEquals(Currency.USD, actualCurrency); + assertEquals(TimePeriod.YEAR, actualPeriod); + assertEquals(new BigDecimal("2.3"), actualAmount); + assertSame(amount, actualAmount); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Item#setAmount(BigDecimal)} + *
  • {@link Item#setCurrency(Currency)} + *
  • {@link Item#setPeriod(TimePeriod)} + *
  • {@link Item#setTitle(String)} + *
  • {@link Item#getAmount()} + *
  • {@link Item#getCurrency()} + *
  • {@link Item#getPeriod()} + *
  • {@link Item#getTitle()} + *
+ */ + @Test + public void testGettersAndSetters2() { + // Arrange + Item item = new Item(); + BigDecimal amount = new BigDecimal("2.6"); + + // Act + item.setAmount(amount); + item.setCurrency(Currency.USD); + item.setPeriod(TimePeriod.YEAR); + item.setTitle("Mr"); + BigDecimal actualAmount = item.getAmount(); + Currency actualCurrency = item.getCurrency(); + TimePeriod actualPeriod = item.getPeriod(); + + // Assert + assertEquals("Mr", item.getTitle()); + assertEquals(Currency.USD, actualCurrency); + assertEquals(TimePeriod.YEAR, actualPeriod); + assertEquals(new BigDecimal("2.6"), actualAmount); + assertSame(amount, actualAmount); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/SavingDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/SavingDiffblueTest.java index 5c16212f..e261615a 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/SavingDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/SavingDiffblueTest.java @@ -3,52 +3,101 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; + import java.math.BigDecimal; + import org.junit.Test; public class SavingDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link Saving} - *
  • {@link Saving#setAmount(BigDecimal)} - *
  • {@link Saving#setCapitalization(Boolean)} - *
  • {@link Saving#setCurrency(Currency)} - *
  • {@link Saving#setDeposit(Boolean)} - *
  • {@link Saving#setInterest(BigDecimal)} - *
  • {@link Saving#getAmount()} - *
  • {@link Saving#getCapitalization()} - *
  • {@link Saving#getCurrency()} - *
  • {@link Saving#getDeposit()} - *
  • {@link Saving#getInterest()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - Saving actualSaving = new Saving(); - BigDecimal amount = new BigDecimal("2.3"); - actualSaving.setAmount(amount); - actualSaving.setCapitalization(true); - actualSaving.setCurrency(Currency.USD); - actualSaving.setDeposit(true); - BigDecimal interest = new BigDecimal("2.3"); - actualSaving.setInterest(interest); - BigDecimal actualAmount = actualSaving.getAmount(); - Boolean actualCapitalization = actualSaving.getCapitalization(); - Currency actualCurrency = actualSaving.getCurrency(); - Boolean actualDeposit = actualSaving.getDeposit(); - BigDecimal actualInterest = actualSaving.getInterest(); - - // Assert - assertEquals(Currency.USD, actualCurrency); - assertTrue(actualCapitalization); - assertTrue(actualDeposit); - assertEquals(new BigDecimal("2.3"), actualAmount); - assertEquals(new BigDecimal("2.3"), actualInterest); - assertSame(amount, actualAmount); - assertSame(interest, actualInterest); - } + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Saving#setAmount(BigDecimal)} + *
  • {@link Saving#setCapitalization(Boolean)} + *
  • {@link Saving#setCurrency(Currency)} + *
  • {@link Saving#setDeposit(Boolean)} + *
  • {@link Saving#setInterest(BigDecimal)} + *
  • {@link Saving#getAmount()} + *
  • {@link Saving#getCapitalization()} + *
  • {@link Saving#getCurrency()} + *
  • {@link Saving#getDeposit()} + *
  • {@link Saving#getInterest()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + Saving saving = new Saving(); + BigDecimal amount = new BigDecimal("2.3"); + + // Act + saving.setAmount(amount); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + BigDecimal interest = new BigDecimal("2.3"); + saving.setInterest(interest); + BigDecimal actualAmount = saving.getAmount(); + Boolean actualCapitalization = saving.getCapitalization(); + Currency actualCurrency = saving.getCurrency(); + Boolean actualDeposit = saving.getDeposit(); + BigDecimal actualInterest = saving.getInterest(); + + // Assert + assertEquals(Currency.USD, actualCurrency); + assertTrue(actualCapitalization); + assertTrue(actualDeposit); + assertEquals(new BigDecimal("2.3"), actualAmount); + assertEquals(new BigDecimal("2.3"), actualInterest); + assertSame(amount, actualAmount); + assertSame(interest, actualInterest); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link Saving#setAmount(BigDecimal)} + *
  • {@link Saving#setCapitalization(Boolean)} + *
  • {@link Saving#setCurrency(Currency)} + *
  • {@link Saving#setDeposit(Boolean)} + *
  • {@link Saving#setInterest(BigDecimal)} + *
  • {@link Saving#getAmount()} + *
  • {@link Saving#getCapitalization()} + *
  • {@link Saving#getCurrency()} + *
  • {@link Saving#getDeposit()} + *
  • {@link Saving#getInterest()} + *
+ */ + @Test + public void testGettersAndSetters2() { + // Arrange + Saving saving = new Saving(); + BigDecimal amount = new BigDecimal("2.6"); + + // Act + saving.setAmount(amount); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + BigDecimal interest = new BigDecimal("2.6"); + saving.setInterest(interest); + BigDecimal actualAmount = saving.getAmount(); + Boolean actualCapitalization = saving.getCapitalization(); + Currency actualCurrency = saving.getCurrency(); + Boolean actualDeposit = saving.getDeposit(); + BigDecimal actualInterest = saving.getInterest(); + + // Assert + assertEquals(Currency.USD, actualCurrency); + assertTrue(actualCapitalization); + assertTrue(actualDeposit); + assertEquals(new BigDecimal("2.6"), actualAmount); + assertEquals(new BigDecimal("2.6"), actualInterest); + assertSame(amount, actualAmount); + assertSame(interest, actualInterest); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/TimePeriodDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/TimePeriodDiffblueTest.java deleted file mode 100644 index 06d0a8db..00000000 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/TimePeriodDiffblueTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.piggymetrics.statistics.domain; - -import static org.junit.Assert.assertEquals; -import java.math.BigDecimal; -import org.junit.Test; - -public class TimePeriodDiffblueTest { - /** - * Test {@link TimePeriod#getBase()}. - *

- * Method under test: {@link TimePeriod#getBase()} - */ - @Test - public void testGetBase() { - // Arrange, Act and Assert - assertEquals(TimePeriod.DAY, TimePeriod.valueOf("YEAR").getBase()); - } - - /** - * Test {@link TimePeriod#getBaseRatio()}. - *

- * Method under test: {@link TimePeriod#getBaseRatio()} - */ - @Test - public void testGetBaseRatio() { - // Arrange and Act - BigDecimal actualBaseRatio = TimePeriod.YEAR.getBaseRatio(); - - // Assert - assertEquals(new BigDecimal("365.24250000000000682121026329696178436279296875"), actualBaseRatio); - } -} diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/DataPointDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/DataPointDiffblueTest.java index 7370b8f1..e5d0b616 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/DataPointDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/DataPointDiffblueTest.java @@ -2,7 +2,9 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; + import com.piggymetrics.statistics.domain.Currency; + import java.math.BigDecimal; import java.time.LocalDate; import java.time.ZoneOffset; @@ -11,58 +13,60 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; + import org.junit.Test; public class DataPointDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • default or parameterless constructor of {@link DataPoint} - *
  • {@link DataPoint#setExpenses(Set)} - *
  • {@link DataPoint#setId(DataPointId)} - *
  • {@link DataPoint#setIncomes(Set)} - *
  • {@link DataPoint#setRates(Map)} - *
  • {@link DataPoint#setStatistics(Map)} - *
  • {@link DataPoint#getExpenses()} - *
  • {@link DataPoint#getId()} - *
  • {@link DataPoint#getIncomes()} - *
  • {@link DataPoint#getRates()} - *
  • {@link DataPoint#getStatistics()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange and Act - DataPoint actualDataPoint = new DataPoint(); - HashSet expenses = new HashSet<>(); - actualDataPoint.setExpenses(expenses); - DataPointId id = new DataPointId("3", - Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link DataPoint#setExpenses(Set)} + *
  • {@link DataPoint#setId(DataPointId)} + *
  • {@link DataPoint#setIncomes(Set)} + *
  • {@link DataPoint#setRates(Map)} + *
  • {@link DataPoint#setStatistics(Map)} + *
  • {@link DataPoint#getExpenses()} + *
  • {@link DataPoint#getId()} + *
  • {@link DataPoint#getIncomes()} + *
  • {@link DataPoint#getRates()} + *
  • {@link DataPoint#getStatistics()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + DataPoint dataPoint = new DataPoint(); + HashSet expenses = new HashSet<>(); + + // Act + dataPoint.setExpenses(expenses); + DataPointId id = new DataPointId("3", + Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant())); - actualDataPoint.setId(id); - HashSet incomes = new HashSet<>(); - actualDataPoint.setIncomes(incomes); - HashMap rates = new HashMap<>(); - actualDataPoint.setRates(rates); - HashMap statistics = new HashMap<>(); - actualDataPoint.setStatistics(statistics); - Set actualExpenses = actualDataPoint.getExpenses(); - DataPointId actualId = actualDataPoint.getId(); - Set actualIncomes = actualDataPoint.getIncomes(); - Map actualRates = actualDataPoint.getRates(); - Map actualStatistics = actualDataPoint.getStatistics(); + dataPoint.setId(id); + HashSet incomes = new HashSet<>(); + dataPoint.setIncomes(incomes); + HashMap rates = new HashMap<>(); + dataPoint.setRates(rates); + HashMap statistics = new HashMap<>(); + dataPoint.setStatistics(statistics); + Set actualExpenses = dataPoint.getExpenses(); + DataPointId actualId = dataPoint.getId(); + Set actualIncomes = dataPoint.getIncomes(); + Map actualRates = dataPoint.getRates(); + Map actualStatistics = dataPoint.getStatistics(); - // Assert - assertTrue(actualRates.isEmpty()); - assertTrue(actualStatistics.isEmpty()); - assertTrue(actualExpenses.isEmpty()); - assertTrue(actualIncomes.isEmpty()); - assertSame(id, actualId); - assertSame(rates, actualRates); - assertSame(statistics, actualStatistics); - assertSame(expenses, actualExpenses); - assertSame(incomes, actualIncomes); - } + // Assert + assertTrue(actualRates.isEmpty()); + assertTrue(actualStatistics.isEmpty()); + assertTrue(actualExpenses.isEmpty()); + assertTrue(actualIncomes.isEmpty()); + assertSame(id, actualId); + assertSame(rates, actualRates); + assertSame(statistics, actualStatistics); + assertSame(expenses, actualExpenses); + assertSame(incomes, actualIncomes); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/DataPointIdDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/DataPointIdDiffblueTest.java index 69a9343d..50855dc1 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/DataPointIdDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/DataPointIdDiffblueTest.java @@ -2,35 +2,37 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; + import java.time.LocalDate; import java.time.ZoneOffset; import java.util.Date; + import org.junit.Test; public class DataPointIdDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • {@link DataPointId#DataPointId(String, Date)} - *
  • {@link DataPointId#toString()} - *
  • {@link DataPointId#getAccount()} - *
  • {@link DataPointId#getDate()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange - Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link DataPointId#DataPointId(String, Date)} + *
  • {@link DataPointId#toString()} + *
  • {@link DataPointId#getAccount()} + *
  • {@link DataPointId#getDate()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); - // Act - DataPointId actualDataPointId = new DataPointId("3", date); - actualDataPointId.toString(); - String actualAccount = actualDataPointId.getAccount(); + // Act + DataPointId actualDataPointId = new DataPointId("3", date); + actualDataPointId.toString(); + String actualAccount = actualDataPointId.getAccount(); - // Assert - assertEquals("3", actualAccount); - assertSame(date, actualDataPointId.getDate()); - } + // Assert + assertEquals("3", actualAccount); + assertSame(date, actualDataPointId.getDate()); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/ItemMetricDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/ItemMetricDiffblueTest.java index 9aaaa6a8..3ef89043 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/ItemMetricDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/domain/timeseries/ItemMetricDiffblueTest.java @@ -3,129 +3,166 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertSame; + import java.math.BigDecimal; + +import org.junit.Ignore; +import org.junit.Rule; + import org.junit.Test; +import org.junit.rules.ExpectedException; public class ItemMetricDiffblueTest { - /** - * Test getters and setters. - *

- * Methods under test: - *

    - *
  • {@link ItemMetric#ItemMetric(String, BigDecimal)} - *
  • {@link ItemMetric#getAmount()} - *
  • {@link ItemMetric#getTitle()} - *
- */ - @Test - public void testGettersAndSetters() { - // Arrange - BigDecimal amount = new BigDecimal("2.3"); - - // Act - ItemMetric actualItemMetric = new ItemMetric("Dr", amount); - BigDecimal actualAmount = actualItemMetric.getAmount(); - - // Assert - assertEquals("Dr", actualItemMetric.getTitle()); - assertEquals(new BigDecimal("2.3"), actualAmount); - assertSame(amount, actualAmount); - } - - /** - * Test {@link ItemMetric#equals(Object)}, and {@link ItemMetric#hashCode()}. - *
    - *
  • When other is equal.
  • - *
  • Then return equal.
  • - *
- *

- * Methods under test: - *

    - *
  • {@link ItemMetric#equals(Object)} - *
  • {@link ItemMetric#hashCode()} - *
- */ - @Test - public void testEqualsAndHashCode_whenOtherIsEqual_thenReturnEqual() { - // Arrange - ItemMetric itemMetric = new ItemMetric("Dr", new BigDecimal("2.3")); - ItemMetric itemMetric2 = new ItemMetric("Dr", new BigDecimal("2.3")); - - // Act and Assert - assertEquals(itemMetric, itemMetric2); - int expectedHashCodeResult = itemMetric.hashCode(); - assertEquals(expectedHashCodeResult, itemMetric2.hashCode()); - } - - /** - * Test {@link ItemMetric#equals(Object)}, and {@link ItemMetric#hashCode()}. - *
    - *
  • When other is same.
  • - *
  • Then return equal.
  • - *
- *

- * Methods under test: - *

    - *
  • {@link ItemMetric#equals(Object)} - *
  • {@link ItemMetric#hashCode()} - *
- */ - @Test - public void testEqualsAndHashCode_whenOtherIsSame_thenReturnEqual() { - // Arrange - ItemMetric itemMetric = new ItemMetric("Dr", new BigDecimal("2.3")); - - // Act and Assert - assertEquals(itemMetric, itemMetric); - int expectedHashCodeResult = itemMetric.hashCode(); - assertEquals(expectedHashCodeResult, itemMetric.hashCode()); - } - - /** - * Test {@link ItemMetric#equals(Object)}. - *
    - *
  • When other is different.
  • - *
  • Then return not equal.
  • - *
- *

- * Method under test: {@link ItemMetric#equals(Object)} - */ - @Test - public void testEquals_whenOtherIsDifferent_thenReturnNotEqual() { - // Arrange - ItemMetric itemMetric = new ItemMetric("Mr", new BigDecimal("2.3")); - - // Act and Assert - assertNotEquals(itemMetric, new ItemMetric("Dr", new BigDecimal("2.3"))); - } - - /** - * Test {@link ItemMetric#equals(Object)}. - *

    - *
  • When other is {@code null}.
  • - *
  • Then return not equal.
  • - *
- *

- * Method under test: {@link ItemMetric#equals(Object)} - */ - @Test - public void testEquals_whenOtherIsNull_thenReturnNotEqual() { - // Arrange, Act and Assert - assertNotEquals(new ItemMetric("Dr", new BigDecimal("2.3")), null); - } - - /** - * Test {@link ItemMetric#equals(Object)}. - *

    - *
  • When other is wrong type.
  • - *
  • Then return not equal.
  • - *
- *

- * Method under test: {@link ItemMetric#equals(Object)} - */ - @Test - public void testEquals_whenOtherIsWrongType_thenReturnNotEqual() { - // Arrange, Act and Assert - assertNotEquals(new ItemMetric("Dr", new BigDecimal("2.3")), "Different type to ItemMetric"); - } + @Rule + public ExpectedException thrown = ExpectedException.none(); + + /** + * Test {@link ItemMetric#equals(Object)}, and {@link ItemMetric#hashCode()}. + *

    + *
  • When other is same.
  • + *
  • Then return equal.
  • + *
+ *

+ * Methods under test: + *

    + *
  • {@link ItemMetric#equals(Object)} + *
  • {@link ItemMetric#hashCode()} + *
+ */ + @Test + public void testEqualsAndHashCode_whenOtherIsSame_thenReturnEqual() { + // Arrange + ItemMetric itemMetric = new ItemMetric("Mr", new BigDecimal("2.6")); + + // Act and Assert + assertEquals(itemMetric, itemMetric); + int expectedHashCodeResult = itemMetric.hashCode(); + assertEquals(expectedHashCodeResult, itemMetric.hashCode()); + } + + /** + * Test {@link ItemMetric#equals(Object)}. + *
    + *
  • When other is different.
  • + *
  • Then return not equal.
  • + *
+ *

+ * Method under test: {@link ItemMetric#equals(Object)} + */ + @Test + public void testEquals_whenOtherIsDifferent_thenReturnNotEqual() { + // Arrange + ItemMetric itemMetric = new ItemMetric("Dr", new BigDecimal("2.6")); + + // Act and Assert + assertNotEquals(itemMetric, new ItemMetric("Mr", new BigDecimal("2.6"))); + } + + /** + * Test {@link ItemMetric#equals(Object)}. + *

    + *
  • When other is different.
  • + *
  • Then throw exception.
  • + *
+ *

+ * Method under test: {@link ItemMetric#equals(Object)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testEquals_whenOtherIsDifferent_thenThrowException() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: No inputs found that don't throw a trivial exception. + // Diffblue Cover tried to run the arrange/act section, but the method under + // test threw + // java.lang.NullPointerException: Cannot invoke "String.equalsIgnoreCase(String)" because "this.title" is null + // at com.piggymetrics.statistics.domain.timeseries.ItemMetric.equals(ItemMetric.java:38) + // See https://diff.blue/R013 to resolve this issue. + + // Arrange + ItemMetric itemMetric = new ItemMetric(null, new BigDecimal("2.6")); + + // Act and Assert + thrown.expect(NullPointerException.class); + itemMetric.equals(new ItemMetric("Mr", new BigDecimal("2.6"))); + } + + /** + * Test {@link ItemMetric#equals(Object)}. + *

    + *
  • When other is {@code null}.
  • + *
  • Then return not equal.
  • + *
+ *

+ * Method under test: {@link ItemMetric#equals(Object)} + */ + @Test + public void testEquals_whenOtherIsNull_thenReturnNotEqual() { + // Arrange, Act and Assert + assertNotEquals(new ItemMetric("Mr", new BigDecimal("2.6")), null); + } + + /** + * Test {@link ItemMetric#equals(Object)}, and {@link ItemMetric#hashCode()}. + *

    + *
  • When other is equal.
  • + *
  • Then return equal.
  • + *
+ *

+ * Methods under test: + *

    + *
  • {@link ItemMetric#equals(Object)} + *
  • {@link ItemMetric#hashCode()} + *
+ */ + @Test + public void testEqualsAndHashCode_whenOtherIsEqual_thenReturnEqual() { + // Arrange + ItemMetric itemMetric = new ItemMetric("Mr", new BigDecimal("2.6")); + ItemMetric itemMetric2 = new ItemMetric("Mr", new BigDecimal("2.6")); + + // Act and Assert + assertEquals(itemMetric, itemMetric2); + int expectedHashCodeResult = itemMetric.hashCode(); + assertEquals(expectedHashCodeResult, itemMetric2.hashCode()); + } + + /** + * Test {@link ItemMetric#equals(Object)}. + *
    + *
  • When other is wrong type.
  • + *
  • Then return not equal.
  • + *
+ *

+ * Method under test: {@link ItemMetric#equals(Object)} + */ + @Test + public void testEquals_whenOtherIsWrongType_thenReturnNotEqual() { + // Arrange, Act and Assert + assertNotEquals(new ItemMetric("Mr", new BigDecimal("2.6")), "Different type to ItemMetric"); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • {@link ItemMetric#ItemMetric(String, BigDecimal)} + *
  • {@link ItemMetric#getAmount()} + *
  • {@link ItemMetric#getTitle()} + *
+ */ + @Test + public void testGettersAndSetters() { + // Arrange + BigDecimal amount = new BigDecimal("2.6"); + + // Act + ItemMetric actualItemMetric = new ItemMetric("Mr", amount); + BigDecimal actualAmount = actualItemMetric.getAmount(); + + // Assert + assertEquals("Mr", actualItemMetric.getTitle()); + assertEquals(new BigDecimal("2.6"), actualAmount); + assertSame(amount, actualAmount); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java deleted file mode 100644 index fcf52574..00000000 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.piggymetrics.statistics.repository; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; -import com.piggymetrics.statistics.domain.timeseries.DataPoint; -import com.piggymetrics.statistics.domain.timeseries.DataPointId; -import com.piggymetrics.statistics.domain.timeseries.ItemMetric; -import com.piggymetrics.statistics.domain.timeseries.StatisticMetric; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.math.BigDecimal; -import java.util.Date; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringRunner.class) -@DataMongoTest -public class DataPointRepositoryTest { - - @Autowired - private DataPointRepository repository; - - @Test - public void shouldSaveDataPoint() { - - ItemMetric salary = new ItemMetric("salary", new BigDecimal(20_000)); - - ItemMetric grocery = new ItemMetric("grocery", new BigDecimal(1_000)); - ItemMetric vacation = new ItemMetric("vacation", new BigDecimal(2_000)); - - DataPointId pointId = new DataPointId("test-account", new Date(0)); - - DataPoint point = new DataPoint(); - point.setId(pointId); - point.setIncomes(Sets.newHashSet(salary)); - point.setExpenses(Sets.newHashSet(grocery, vacation)); - point.setStatistics(ImmutableMap.of( - StatisticMetric.SAVING_AMOUNT, new BigDecimal(400_000), - StatisticMetric.INCOMES_AMOUNT, new BigDecimal(20_000), - StatisticMetric.EXPENSES_AMOUNT, new BigDecimal(3_000) - )); - - repository.save(point); - - List points = repository.findByIdAccount(pointId.getAccount()); - assertEquals(1, points.size()); - assertEquals(pointId.getDate(), points.get(0).getId().getDate()); - assertEquals(point.getStatistics().size(), points.get(0).getStatistics().size()); - assertEquals(point.getIncomes().size(), points.get(0).getIncomes().size()); - assertEquals(point.getExpenses().size(), points.get(0).getExpenses().size()); - } - - @Test - public void shouldRewriteDataPointWithinADay() { - - final BigDecimal earlyAmount = new BigDecimal(100); - final BigDecimal lateAmount = new BigDecimal(200); - - DataPointId pointId = new DataPointId("test-account", new Date(0)); - - DataPoint earlier = new DataPoint(); - earlier.setId(pointId); - earlier.setStatistics(ImmutableMap.of( - StatisticMetric.SAVING_AMOUNT, earlyAmount - )); - - repository.save(earlier); - - DataPoint later = new DataPoint(); - later.setId(pointId); - later.setStatistics(ImmutableMap.of( - StatisticMetric.SAVING_AMOUNT, lateAmount - )); - - repository.save(later); - - List points = repository.findByIdAccount(pointId.getAccount()); - - assertEquals(1, points.size()); - assertEquals(lateAmount, points.get(0).getStatistics().get(StatisticMetric.SAVING_AMOUNT)); - } -} diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/repository/converter/DataPointIdReaderConverterDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/repository/converter/DataPointIdReaderConverterDiffblueTest.java new file mode 100644 index 00000000..500982de --- /dev/null +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/repository/converter/DataPointIdReaderConverterDiffblueTest.java @@ -0,0 +1,83 @@ +package com.piggymetrics.statistics.repository.converter; + +import com.mongodb.BasicDBList; +import com.mongodb.DBObject; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@ContextConfiguration(classes = {DataPointIdReaderConverter.class}) +@RunWith(SpringJUnit4ClassRunner.class) +public class DataPointIdReaderConverterDiffblueTest { + @Autowired + private DataPointIdReaderConverter dataPointIdReaderConverter; + + /** + * Test {@link DataPointIdReaderConverter#convert(DBObject)} with + * {@code DBObject}. + *

+ * Method under test: {@link DataPointIdReaderConverter#convert(DBObject)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConvertWithDBObject() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + dataPointIdReaderConverter.convert(new BasicDBList()); + } +} diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/repository/converter/DataPointIdWriterConverterDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/repository/converter/DataPointIdWriterConverterDiffblueTest.java index 3788522b..7c2f79da 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/repository/converter/DataPointIdWriterConverterDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/repository/converter/DataPointIdWriterConverterDiffblueTest.java @@ -3,12 +3,17 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; + import com.mongodb.DBObject; import com.piggymetrics.statistics.domain.timeseries.DataPointId; + import java.time.LocalDate; import java.time.ZoneOffset; import java.util.Date; import java.util.Map; + +import org.junit.Ignore; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -18,30 +23,102 @@ @ContextConfiguration(classes = {DataPointIdWriterConverter.class}) @RunWith(SpringJUnit4ClassRunner.class) public class DataPointIdWriterConverterDiffblueTest { - @Autowired - private DataPointIdWriterConverter dataPointIdWriterConverter; - - /** - * Test {@link DataPointIdWriterConverter#convert(DataPointId)} with - * {@code DataPointId}. - *

    - *
  • Then return {@link Map}.
  • - *
- *

- * Method under test: {@link DataPointIdWriterConverter#convert(DataPointId)} - */ - @Test - public void testConvertWithDataPointId_thenReturnMap() { - // Arrange - Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); - - // Act - DBObject actualConvertResult = dataPointIdWriterConverter.convert(new DataPointId("3", date)); - - // Assert - assertTrue(actualConvertResult instanceof Map); - assertEquals(2, ((Map) actualConvertResult).size()); - assertEquals("3", ((Map) actualConvertResult).get("account")); - assertSame(date, ((Map) actualConvertResult).get("date")); - } + @Autowired + private DataPointIdWriterConverter dataPointIdWriterConverter; + + /** + * Test {@link DataPointIdWriterConverter#convert(DataPointId)} with + * {@code DataPointId}. + *

+ * Method under test: {@link DataPointIdWriterConverter#convert(DataPointId)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConvertWithDataPointId() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + dataPointIdWriterConverter.convert( + new DataPointId("3", Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()))); + } + + /** + * Test {@link DataPointIdWriterConverter#convert(DataPointId)} with + * {@code DataPointId}. + *

    + *
  • Then return {@link Map}.
  • + *
+ *

+ * Method under test: {@link DataPointIdWriterConverter#convert(DataPointId)} + */ + @Test + public void testConvertWithDataPointId_thenReturnMap() { + // Diffblue Cover was unable to create a Spring-specific test for this Spring method. + // Run dcover create --keep-partial-tests to gain insights into why + // a non-Spring test was created. + + // Arrange + DataPointIdWriterConverter dataPointIdWriterConverter = new DataPointIdWriterConverter(); + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act + DBObject actualConvertResult = dataPointIdWriterConverter.convert(new DataPointId("3", date)); + + // Assert + assertTrue(actualConvertResult instanceof Map); + assertEquals(2, ((Map) actualConvertResult).size()); + assertEquals("3", ((Map) actualConvertResult).get("account")); + assertSame(date, ((Map) actualConvertResult).get("date")); + } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/service/ExchangeRatesServiceImplDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/service/ExchangeRatesServiceImplDiffblueTest.java new file mode 100644 index 00000000..87a8dfa3 --- /dev/null +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/service/ExchangeRatesServiceImplDiffblueTest.java @@ -0,0 +1,157 @@ +package com.piggymetrics.statistics.service; + +import com.piggymetrics.statistics.client.ExchangeRatesClient; +import com.piggymetrics.statistics.domain.Currency; + +import java.math.BigDecimal; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@ContextConfiguration(classes = {ExchangeRatesServiceImpl.class}) +@RunWith(SpringJUnit4ClassRunner.class) +public class ExchangeRatesServiceImplDiffblueTest { + @MockBean + private ExchangeRatesClient exchangeRatesClient; + + @Autowired + private ExchangeRatesServiceImpl exchangeRatesServiceImpl; + + /** + * Test {@link ExchangeRatesServiceImpl#getCurrentRates()}. + *

+ * Method under test: {@link ExchangeRatesServiceImpl#getCurrentRates()} + */ + @Test + @Ignore("TODO: Complete this test") + public void testGetCurrentRates() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + exchangeRatesServiceImpl.getCurrentRates(); + } + + /** + * Test + * {@link ExchangeRatesServiceImpl#convert(Currency, Currency, BigDecimal)}. + *

+ * Method under test: + * {@link ExchangeRatesServiceImpl#convert(Currency, Currency, BigDecimal)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testConvert() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + exchangeRatesServiceImpl.convert(Currency.USD, Currency.USD, new BigDecimal("2.6")); + } + +} diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/service/ExchangeRatesServiceImplTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/service/ExchangeRatesServiceImplTest.java deleted file mode 100644 index 1e019c8e..00000000 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/service/ExchangeRatesServiceImplTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.piggymetrics.statistics.service; - -import com.google.common.collect.ImmutableMap; -import com.piggymetrics.statistics.client.ExchangeRatesClient; -import com.piggymetrics.statistics.domain.Currency; -import com.piggymetrics.statistics.domain.ExchangeRatesContainer; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -import java.math.BigDecimal; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; - -public class ExchangeRatesServiceImplTest { - - @InjectMocks - private ExchangeRatesServiceImpl ratesService; - - @Mock - private ExchangeRatesClient client; - - @Before - public void setup() { - initMocks(this); - } - - @Test - public void shouldReturnCurrentRatesWhenContainerIsEmptySoFar() { - - ExchangeRatesContainer container = new ExchangeRatesContainer(); - container.setRates(ImmutableMap.of( - Currency.EUR.name(), new BigDecimal("0.8"), - Currency.RUB.name(), new BigDecimal("80") - )); - - when(client.getRates(Currency.getBase())).thenReturn(container); - - Map result = ratesService.getCurrentRates(); - verify(client, times(1)).getRates(Currency.getBase()); - - assertEquals(container.getRates().get(Currency.EUR.name()), result.get(Currency.EUR)); - assertEquals(container.getRates().get(Currency.RUB.name()), result.get(Currency.RUB)); - assertEquals(BigDecimal.ONE, result.get(Currency.USD)); - } - - @Test - public void shouldNotRequestRatesWhenTodaysContainerAlreadyExists() { - - ExchangeRatesContainer container = new ExchangeRatesContainer(); - container.setRates(ImmutableMap.of( - Currency.EUR.name(), new BigDecimal("0.8"), - Currency.RUB.name(), new BigDecimal("80") - )); - - when(client.getRates(Currency.getBase())).thenReturn(container); - - // initialize container - ratesService.getCurrentRates(); - - // use existing container - ratesService.getCurrentRates(); - - verify(client, times(1)).getRates(Currency.getBase()); - } - - @Test - public void shouldConvertCurrency() { - - ExchangeRatesContainer container = new ExchangeRatesContainer(); - container.setRates(ImmutableMap.of( - Currency.EUR.name(), new BigDecimal("0.8"), - Currency.RUB.name(), new BigDecimal("80") - )); - - when(client.getRates(Currency.getBase())).thenReturn(container); - - final BigDecimal amount = new BigDecimal(100); - final BigDecimal expectedConvertionResult = new BigDecimal("1.25"); - - BigDecimal result = ratesService.convert(Currency.RUB, Currency.USD, amount); - - assertTrue(expectedConvertionResult.compareTo(result) == 0); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailToConvertWhenAmountIsNull() { - ratesService.convert(Currency.EUR, Currency.RUB, null); - } -} \ No newline at end of file diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplDiffblueTest.java index d8b20da8..ed852c41 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplDiffblueTest.java @@ -1,348 +1,174 @@ package com.piggymetrics.statistics.service; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import com.piggymetrics.statistics.domain.Account; import com.piggymetrics.statistics.domain.Currency; -import com.piggymetrics.statistics.domain.Item; import com.piggymetrics.statistics.domain.Saving; -import com.piggymetrics.statistics.domain.TimePeriod; -import com.piggymetrics.statistics.domain.timeseries.DataPoint; -import com.piggymetrics.statistics.domain.timeseries.DataPointId; import com.piggymetrics.statistics.repository.DataPointRepository; -import de.flapdoodle.embed.mongo.MongodExecutable; + import java.math.BigDecimal; -import java.time.LocalDate; -import java.time.ZoneOffset; import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; + +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@SpringBootTest +@ContextConfiguration(classes = {StatisticsServiceImpl.class}) @RunWith(SpringJUnit4ClassRunner.class) public class StatisticsServiceImplDiffblueTest { - @MockBean - private ExchangeRatesService exchangeRatesService; - - @MockBean - private DataPointRepository dataPointRepository; - - @MockBean - private MongodExecutable mongodExecutable; - - @Autowired - private StatisticsServiceImpl statisticsServiceImpl; - - /** - * Test {@link StatisticsServiceImpl#findByAccountName(String)}. - *

    - *
  • When {@code Dr Jane Doe}.
  • - *
  • Then return Empty.
  • - *
- *

- * Method under test: {@link StatisticsServiceImpl#findByAccountName(String)} - */ - @Test - public void testFindByAccountName_whenDrJaneDoe_thenReturnEmpty() { - // Arrange - when(dataPointRepository.findByIdAccount(Mockito.any())).thenReturn(new ArrayList<>()); - - // Act - List actualFindByAccountNameResult = statisticsServiceImpl.findByAccountName("Dr Jane Doe"); - - // Assert - verify(dataPointRepository).findByIdAccount(eq("Dr Jane Doe")); - assertTrue(actualFindByAccountNameResult.isEmpty()); - } - - /** - * Test {@link StatisticsServiceImpl#save(String, Account)}. - *

    - *
  • Given {@link Item} (default constructor) Currency is {@code EUR}.
  • - *
  • Then calls {@link Account#getExpenses()}.
  • - *
- *

- * Method under test: {@link StatisticsServiceImpl#save(String, Account)} - */ - @Test - public void testSave_givenItemCurrencyIsEur_thenCallsGetExpenses() { - // Arrange - when(exchangeRatesService.getCurrentRates()).thenReturn(new HashMap<>()); - when(exchangeRatesService.convert(Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(new BigDecimal("2.3")); - - DataPoint dataPoint = new DataPoint(); - dataPoint.setExpenses(new HashSet<>()); - dataPoint.setId( - new DataPointId("3", Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()))); - dataPoint.setIncomes(new HashSet<>()); - dataPoint.setRates(new HashMap<>()); - dataPoint.setStatistics(new HashMap<>()); - when(dataPointRepository.save(Mockito.any())).thenReturn(dataPoint); - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - - Saving saving2 = new Saving(); - saving2.setAmount(new BigDecimal("2.3")); - saving2.setCapitalization(true); - saving2.setCurrency(Currency.USD); - saving2.setDeposit(true); - saving2.setInterest(new BigDecimal("2.3")); - - Item item = new Item(); - item.setAmount(new BigDecimal("2.3")); - item.setCurrency(Currency.USD); - item.setPeriod(TimePeriod.YEAR); - item.setTitle("Dr"); - - Item item2 = new Item(); - item2.setAmount(new BigDecimal("2.3")); - item2.setCurrency(Currency.EUR); - item2.setPeriod(TimePeriod.QUARTER); - item2.setTitle("Mr"); - - ArrayList itemList = new ArrayList<>(); - itemList.add(item2); - itemList.add(item); - Account account = mock(Account.class); - when(account.getSaving()).thenReturn(saving2); - when(account.getExpenses()).thenReturn(itemList); - when(account.getIncomes()).thenReturn(new ArrayList<>()); - doNothing().when(account).setExpenses(Mockito.>any()); - doNothing().when(account).setIncomes(Mockito.>any()); - doNothing().when(account).setSaving(Mockito.any()); - account.setExpenses(new ArrayList<>()); - account.setIncomes(new ArrayList<>()); - account.setSaving(saving); - - // Act - DataPoint actualSaveResult = statisticsServiceImpl.save("Dr Jane Doe", account); - - // Assert - verify(account).getExpenses(); - verify(account).getIncomes(); - verify(account).getSaving(); - verify(account).setExpenses(isA(List.class)); - verify(account).setIncomes(isA(List.class)); - verify(account).setSaving(isA(Saving.class)); - verify(exchangeRatesService, atLeast(1)).convert(Mockito.any(), eq(Currency.USD), isA(BigDecimal.class)); - verify(exchangeRatesService).getCurrentRates(); - verify(dataPointRepository).save(isA(DataPoint.class)); - assertSame(dataPoint, actualSaveResult); - } - - /** - * Test {@link StatisticsServiceImpl#save(String, Account)}. - *

    - *
  • Then calls {@link Account#getExpenses()}.
  • - *
- *

- * Method under test: {@link StatisticsServiceImpl#save(String, Account)} - */ - @Test - public void testSave_thenCallsGetExpenses() { - // Arrange - when(exchangeRatesService.getCurrentRates()).thenReturn(new HashMap<>()); - when(exchangeRatesService.convert(Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(new BigDecimal("2.3")); - - DataPoint dataPoint = new DataPoint(); - dataPoint.setExpenses(new HashSet<>()); - dataPoint.setId( - new DataPointId("3", Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()))); - dataPoint.setIncomes(new HashSet<>()); - dataPoint.setRates(new HashMap<>()); - dataPoint.setStatistics(new HashMap<>()); - when(dataPointRepository.save(Mockito.any())).thenReturn(dataPoint); - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - - Saving saving2 = new Saving(); - saving2.setAmount(new BigDecimal("2.3")); - saving2.setCapitalization(true); - saving2.setCurrency(Currency.USD); - saving2.setDeposit(true); - saving2.setInterest(new BigDecimal("2.3")); - - Item item = new Item(); - item.setAmount(new BigDecimal("2.3")); - item.setCurrency(Currency.USD); - item.setPeriod(TimePeriod.YEAR); - item.setTitle("Dr"); - - ArrayList itemList = new ArrayList<>(); - itemList.add(item); - Account account = mock(Account.class); - when(account.getSaving()).thenReturn(saving2); - when(account.getExpenses()).thenReturn(itemList); - when(account.getIncomes()).thenReturn(new ArrayList<>()); - doNothing().when(account).setExpenses(Mockito.>any()); - doNothing().when(account).setIncomes(Mockito.>any()); - doNothing().when(account).setSaving(Mockito.any()); - account.setExpenses(new ArrayList<>()); - account.setIncomes(new ArrayList<>()); - account.setSaving(saving); - - // Act - DataPoint actualSaveResult = statisticsServiceImpl.save("Dr Jane Doe", account); - - // Assert - verify(account).getExpenses(); - verify(account).getIncomes(); - verify(account).getSaving(); - verify(account).setExpenses(isA(List.class)); - verify(account).setIncomes(isA(List.class)); - verify(account).setSaving(isA(Saving.class)); - verify(exchangeRatesService, atLeast(1)).convert(eq(Currency.USD), eq(Currency.USD), isA(BigDecimal.class)); - verify(exchangeRatesService).getCurrentRates(); - verify(dataPointRepository).save(isA(DataPoint.class)); - assertSame(dataPoint, actualSaveResult); - } - - /** - * Test {@link StatisticsServiceImpl#save(String, Account)}. - *

    - *
  • Then calls {@link Account#getExpenses()}.
  • - *
- *

- * Method under test: {@link StatisticsServiceImpl#save(String, Account)} - */ - @Test - public void testSave_thenCallsGetExpenses2() { - // Arrange - when(exchangeRatesService.getCurrentRates()).thenReturn(new HashMap<>()); - when(exchangeRatesService.convert(Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(new BigDecimal("2.3")); - - DataPoint dataPoint = new DataPoint(); - dataPoint.setExpenses(new HashSet<>()); - dataPoint.setId( - new DataPointId("3", Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()))); - dataPoint.setIncomes(new HashSet<>()); - dataPoint.setRates(new HashMap<>()); - dataPoint.setStatistics(new HashMap<>()); - when(dataPointRepository.save(Mockito.any())).thenReturn(dataPoint); - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - - Saving saving2 = new Saving(); - saving2.setAmount(new BigDecimal("2.3")); - saving2.setCapitalization(true); - saving2.setCurrency(Currency.USD); - saving2.setDeposit(true); - saving2.setInterest(new BigDecimal("2.3")); - - Item item = new Item(); - item.setAmount(new BigDecimal("2.3")); - item.setCurrency(Currency.USD); - item.setPeriod(TimePeriod.YEAR); - item.setTitle("Dr"); - - ArrayList itemList = new ArrayList<>(); - itemList.add(item); - Account account = mock(Account.class); - when(account.getSaving()).thenReturn(saving2); - when(account.getExpenses()).thenReturn(new ArrayList<>()); - when(account.getIncomes()).thenReturn(itemList); - doNothing().when(account).setExpenses(Mockito.>any()); - doNothing().when(account).setIncomes(Mockito.>any()); - doNothing().when(account).setSaving(Mockito.any()); - account.setExpenses(new ArrayList<>()); - account.setIncomes(new ArrayList<>()); - account.setSaving(saving); - - // Act - DataPoint actualSaveResult = statisticsServiceImpl.save("Dr Jane Doe", account); - - // Assert - verify(account).getExpenses(); - verify(account).getIncomes(); - verify(account).getSaving(); - verify(account).setExpenses(isA(List.class)); - verify(account).setIncomes(isA(List.class)); - verify(account).setSaving(isA(Saving.class)); - verify(exchangeRatesService, atLeast(1)).convert(eq(Currency.USD), eq(Currency.USD), isA(BigDecimal.class)); - verify(exchangeRatesService).getCurrentRates(); - verify(dataPointRepository).save(isA(DataPoint.class)); - assertSame(dataPoint, actualSaveResult); - } - - /** - * Test {@link StatisticsServiceImpl#save(String, Account)}. - *

    - *
  • When {@link Account} (default constructor) Expenses is - * {@link ArrayList#ArrayList()}.
  • - *
  • Then return {@link DataPoint} (default constructor).
  • - *
- *

- * Method under test: {@link StatisticsServiceImpl#save(String, Account)} - */ - @Test - public void testSave_whenAccountExpensesIsArrayList_thenReturnDataPoint() { - // Arrange - when(exchangeRatesService.getCurrentRates()).thenReturn(new HashMap<>()); - when(exchangeRatesService.convert(Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(new BigDecimal("2.3")); - - DataPoint dataPoint = new DataPoint(); - dataPoint.setExpenses(new HashSet<>()); - dataPoint.setId( - new DataPointId("3", Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()))); - dataPoint.setIncomes(new HashSet<>()); - dataPoint.setRates(new HashMap<>()); - dataPoint.setStatistics(new HashMap<>()); - when(dataPointRepository.save(Mockito.any())).thenReturn(dataPoint); - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal("2.3")); - saving.setCapitalization(true); - saving.setCurrency(Currency.USD); - saving.setDeposit(true); - saving.setInterest(new BigDecimal("2.3")); - - Account account = new Account(); - account.setExpenses(new ArrayList<>()); - account.setIncomes(new ArrayList<>()); - account.setSaving(saving); - - // Act - DataPoint actualSaveResult = statisticsServiceImpl.save("Dr Jane Doe", account); + @MockBean + private DataPointRepository dataPointRepository; + + @MockBean + private ExchangeRatesService exchangeRatesService; + + @Autowired + private StatisticsServiceImpl statisticsServiceImpl; + + /** + * Test {@link StatisticsServiceImpl#findByAccountName(String)}. + *

+ * Method under test: {@link StatisticsServiceImpl#findByAccountName(String)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testFindByAccountName() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange and Act + statisticsServiceImpl.findByAccountName("Smith"); + } + + /** + * Test {@link StatisticsServiceImpl#save(String, Account)}. + *

+ * Method under test: {@link StatisticsServiceImpl#save(String, Account)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testSave() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Failed to create Spring context. + // Attempt to initialize test context failed with + // com.diffblue.fuzztest.shared.proxy.LibraryLinkageException: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // java.lang.ClassNotFoundException: org.springframework.core.NestedIOException + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:309) + // at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) + // at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) + // at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) + // at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:221) + // at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:110) + // at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:212) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187) + // at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119) + // at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127) + // at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) + // at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709) + // at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) + // at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) + // at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) + // at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) + // at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702) + // See https://diff.blue/R026 to resolve this issue. + + // Arrange + Saving saving = new Saving(); + saving.setAmount(new BigDecimal("2.6")); + saving.setCapitalization(true); + saving.setCurrency(Currency.USD); + saving.setDeposit(true); + saving.setInterest(new BigDecimal("2.6")); + + Account account = new Account(); + account.setExpenses(new ArrayList<>()); + account.setIncomes(new ArrayList<>()); + account.setSaving(saving); + + // Act + statisticsServiceImpl.save("Smith", account); + } - // Assert - verify(exchangeRatesService).convert(eq(Currency.USD), eq(Currency.USD), isA(BigDecimal.class)); - verify(exchangeRatesService).getCurrentRates(); - verify(dataPointRepository).save(isA(DataPoint.class)); - assertSame(dataPoint, actualSaveResult); - } } diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplTest.java deleted file mode 100644 index beeef32a..00000000 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplTest.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.piggymetrics.statistics.service; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.piggymetrics.statistics.domain.Account; -import com.piggymetrics.statistics.domain.Currency; -import com.piggymetrics.statistics.domain.Item; -import com.piggymetrics.statistics.domain.Saving; -import com.piggymetrics.statistics.domain.TimePeriod; -import com.piggymetrics.statistics.domain.timeseries.DataPoint; -import com.piggymetrics.statistics.domain.timeseries.ItemMetric; -import com.piggymetrics.statistics.domain.timeseries.StatisticMetric; -import com.piggymetrics.statistics.repository.DataPointRepository; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.AdditionalAnswers.returnsFirstArg; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -public class StatisticsServiceImplTest { - - @InjectMocks - private StatisticsServiceImpl statisticsService; - - @Mock - private ExchangeRatesServiceImpl ratesService; - - @Mock - private DataPointRepository repository; - - @Before - public void setup() { - initMocks(this); - } - - @Test - public void shouldFindDataPointListByAccountName() { - final List list = ImmutableList.of(new DataPoint()); - when(repository.findByIdAccount("test")).thenReturn(list); - - List result = statisticsService.findByAccountName("test"); - assertEquals(list, result); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailToFindDataPointWhenAccountNameIsNull() { - statisticsService.findByAccountName(null); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailToFindDataPointWhenAccountNameIsEmpty() { - statisticsService.findByAccountName(""); - } - - @Test - public void shouldSaveDataPoint() { - - /** - * Given - */ - - Item salary = new Item(); - salary.setTitle("Salary"); - salary.setAmount(new BigDecimal(9100)); - salary.setCurrency(Currency.USD); - salary.setPeriod(TimePeriod.MONTH); - - Item grocery = new Item(); - grocery.setTitle("Grocery"); - grocery.setAmount(new BigDecimal(500)); - grocery.setCurrency(Currency.RUB); - grocery.setPeriod(TimePeriod.DAY); - - Item vacation = new Item(); - vacation.setTitle("Vacation"); - vacation.setAmount(new BigDecimal(3400)); - vacation.setCurrency(Currency.EUR); - vacation.setPeriod(TimePeriod.YEAR); - - Saving saving = new Saving(); - saving.setAmount(new BigDecimal(1000)); - saving.setCurrency(Currency.EUR); - saving.setInterest(new BigDecimal(3.2)); - saving.setDeposit(true); - saving.setCapitalization(false); - - Account account = new Account(); - account.setIncomes(ImmutableList.of(salary)); - account.setExpenses(ImmutableList.of(grocery, vacation)); - account.setSaving(saving); - - final Map rates = ImmutableMap.of( - Currency.EUR, new BigDecimal("0.8"), - Currency.RUB, new BigDecimal("80"), - Currency.USD, BigDecimal.ONE - ); - - /** - * When - */ - - when(ratesService.convert(any(Currency.class),any(Currency.class),any(BigDecimal.class))) - .then(i -> ((BigDecimal)i.getArgument(2)) - .divide(rates.get(i.getArgument(0)), 4, RoundingMode.HALF_UP)); - - when(ratesService.getCurrentRates()).thenReturn(rates); - - when(repository.save(any(DataPoint.class))).then(returnsFirstArg()); - - DataPoint dataPoint = statisticsService.save("test", account); - - /** - * Then - */ - - final BigDecimal expectedExpensesAmount = new BigDecimal("17.8861"); - final BigDecimal expectedIncomesAmount = new BigDecimal("298.9802"); - final BigDecimal expectedSavingAmount = new BigDecimal("1250"); - - final BigDecimal expectedNormalizedSalaryAmount = new BigDecimal("298.9802"); - final BigDecimal expectedNormalizedVacationAmount = new BigDecimal("11.6361"); - final BigDecimal expectedNormalizedGroceryAmount = new BigDecimal("6.25"); - - assertEquals(dataPoint.getId().getAccount(), "test"); - assertEquals(dataPoint.getId().getDate(), Date.from(LocalDate.now().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())); - - assertTrue(expectedExpensesAmount.compareTo(dataPoint.getStatistics().get(StatisticMetric.EXPENSES_AMOUNT)) == 0); - assertTrue(expectedIncomesAmount.compareTo(dataPoint.getStatistics().get(StatisticMetric.INCOMES_AMOUNT)) == 0); - assertTrue(expectedSavingAmount.compareTo(dataPoint.getStatistics().get(StatisticMetric.SAVING_AMOUNT)) == 0); - - ItemMetric salaryItemMetric = dataPoint.getIncomes().stream() - .filter(i -> i.getTitle().equals(salary.getTitle())) - .findFirst().get(); - - ItemMetric vacationItemMetric = dataPoint.getExpenses().stream() - .filter(i -> i.getTitle().equals(vacation.getTitle())) - .findFirst().get(); - - ItemMetric groceryItemMetric = dataPoint.getExpenses().stream() - .filter(i -> i.getTitle().equals(grocery.getTitle())) - .findFirst().get(); - - assertTrue(expectedNormalizedSalaryAmount.compareTo(salaryItemMetric.getAmount()) == 0); - assertTrue(expectedNormalizedVacationAmount.compareTo(vacationItemMetric.getAmount()) == 0); - assertTrue(expectedNormalizedGroceryAmount.compareTo(groceryItemMetric.getAmount()) == 0); - - assertEquals(rates, dataPoint.getRates()); - - verify(repository, times(1)).save(dataPoint); - } -} \ No newline at end of file diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/service/security/CustomUserInfoTokenServicesDiffblueTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/service/security/CustomUserInfoTokenServicesDiffblueTest.java index 9e184dec..a1686d9a 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/service/security/CustomUserInfoTokenServicesDiffblueTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/service/security/CustomUserInfoTokenServicesDiffblueTest.java @@ -1,56 +1,103 @@ package com.piggymetrics.statistics.service.security; -import com.piggymetrics.statistics.repository.DataPointRepository; -import de.flapdoodle.embed.mongo.MongodExecutable; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.autoconfigure.security.oauth2.resource.AuthoritiesExtractor; +import org.springframework.boot.autoconfigure.security.oauth2.resource.FixedAuthoritiesExtractor; import org.springframework.security.core.AuthenticationException; +import org.springframework.security.oauth2.client.OAuth2RestOperations; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails; import org.springframework.security.oauth2.common.exceptions.InvalidTokenException; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@SpringBootTest +@ContextConfiguration(classes = {CustomUserInfoTokenServices.class, String.class}) @RunWith(SpringJUnit4ClassRunner.class) public class CustomUserInfoTokenServicesDiffblueTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Autowired - private CustomUserInfoTokenServices customUserInfoTokenServices; - - @MockBean - private DataPointRepository dataPointRepository; - - @MockBean - private MongodExecutable mongodExecutable; - - /** - * Test {@link CustomUserInfoTokenServices#loadAuthentication(String)}. - *

- * Method under test: - * {@link CustomUserInfoTokenServices#loadAuthentication(String)} - */ - @Test - public void testLoadAuthentication() throws AuthenticationException, InvalidTokenException { - // Arrange, Act and Assert - thrown.expect(InvalidTokenException.class); - customUserInfoTokenServices.loadAuthentication("ABC123"); - } - - /** - * Test {@link CustomUserInfoTokenServices#readAccessToken(String)}. - *

- * Method under test: - * {@link CustomUserInfoTokenServices#readAccessToken(String)} - */ - @Test - public void testReadAccessToken() { - // Arrange, Act and Assert - thrown.expect(UnsupportedOperationException.class); - customUserInfoTokenServices.readAccessToken("ABC123"); - } + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Autowired + private CustomUserInfoTokenServices customUserInfoTokenServices; + + /** + * Test {@link CustomUserInfoTokenServices#loadAuthentication(String)}. + *

+ * Method under test: + * {@link CustomUserInfoTokenServices#loadAuthentication(String)} + */ + @Test + public void testLoadAuthentication() throws AuthenticationException, InvalidTokenException { + // Arrange, Act and Assert + thrown.expect(InvalidTokenException.class); + customUserInfoTokenServices.loadAuthentication("ABC123"); + } + + /** + * Test getters and setters. + *

+ * Methods under test: + *

    + *
  • + * {@link CustomUserInfoTokenServices#setAuthoritiesExtractor(AuthoritiesExtractor)} + *
  • {@link CustomUserInfoTokenServices#setRestTemplate(OAuth2RestOperations)} + *
  • {@link CustomUserInfoTokenServices#setTokenType(String)} + *
+ */ + @Test + public void testGettersAndSetters() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Reason: Missing observers. + // Diffblue Cover was unable to create an assertion. + // Add getters for the following fields or make them package-private: + // CustomUserInfoTokenServices.authoritiesExtractor + // CustomUserInfoTokenServices.clientId + // CustomUserInfoTokenServices.logger + // CustomUserInfoTokenServices.restTemplate + // CustomUserInfoTokenServices.tokenType + // CustomUserInfoTokenServices.userInfoEndpointUrl + + // Arrange + CustomUserInfoTokenServices customUserInfoTokenServices = new CustomUserInfoTokenServices( + "https://example.org/example", "42"); + + // Act + customUserInfoTokenServices.setAuthoritiesExtractor(new FixedAuthoritiesExtractor()); + customUserInfoTokenServices.setRestTemplate(new OAuth2RestTemplate(new BaseOAuth2ProtectedResourceDetails())); + customUserInfoTokenServices.setTokenType("ABC123"); + } + + /** + * Test {@link CustomUserInfoTokenServices#readAccessToken(String)}. + *

+ * Method under test: + * {@link CustomUserInfoTokenServices#readAccessToken(String)} + */ + @Test + public void testReadAccessToken() { + // Arrange, Act and Assert + thrown.expect(UnsupportedOperationException.class); + customUserInfoTokenServices.readAccessToken("ABC123"); + } + + /** + * Test + * {@link CustomUserInfoTokenServices#CustomUserInfoTokenServices(String, String)}. + *

+ * Method under test: + * {@link CustomUserInfoTokenServices#CustomUserInfoTokenServices(String, String)} + */ + @Test + public void testNewCustomUserInfoTokenServices() { + // TODO: Diffblue Cover was only able to create a partial test for this method: + // Diffblue AI was unable to find a test + + // Arrange and Act + new CustomUserInfoTokenServices("https://example.org/example", "42"); + + } } diff --git a/turbine-stream-service/pom.xml b/turbine-stream-service/pom.xml index ed172c1a..4a4c1d4b 100644 --- a/turbine-stream-service/pom.xml +++ b/turbine-stream-service/pom.xml @@ -15,6 +15,10 @@ + + io.projectreactor + reactor-test + org.springframework.cloud spring-cloud-starter-config @@ -40,7 +44,7 @@ org.jacoco org.jacoco.agent - 0.8.2 + 0.8.11 test runtime @@ -50,6 +54,24 @@ 4.12 test + + org.mockito + mockito-core + 4.1.0 + test + + + org.springframework + spring-core + 6.0.11 + compile + + + org.springframework.boot + spring-boot + 2.5.1 + compile + @@ -75,7 +97,7 @@ org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.11 diff --git a/turbine-stream-service/src/test/java/com/piggymetrics/turbine/TurbineStreamServiceApplicationTests.java b/turbine-stream-service/src/test/java/com/piggymetrics/turbine/TurbineStreamServiceApplicationTests.java deleted file mode 100644 index 78ff7e8b..00000000 --- a/turbine-stream-service/src/test/java/com/piggymetrics/turbine/TurbineStreamServiceApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.piggymetrics.turbine; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class TurbineStreamServiceApplicationTests { - - @Test - public void contextLoads() { - } - -}