Skip to content

Commit

Permalink
Fix Constructor Invokes Overridable Function Fortify finding (#1245)
Browse files Browse the repository at this point in the history
* Refactored constructor and made class final

* Converted immutable classes into records

* Added missing tests fixes
  • Loading branch information
basiliskus authored Aug 16, 2024
1 parent 97d2245 commit 6be5312
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
package gov.hhs.cdc.trustedintermediary.etor.orders;

/** Response for the v1/etor/orders endpoint. */
public class OrderResponse {

private String fhirResourceId;
private String patientId;

OrderResponse(String fhirResourceId, String patientId) {
setFhirResourceId(fhirResourceId);
setPatientId(patientId);
}
public record OrderResponse(String fhirResourceId, String patientId) {

public OrderResponse(Order<?> orders) {
setFhirResourceId(orders.getFhirResourceId());
setPatientId(orders.getPatientId());
}

public String getFhirResourceId() {
return fhirResourceId;
}

public void setFhirResourceId(String fhirResourceId) {
this.fhirResourceId = fhirResourceId;
}

public String getPatientId() {
return patientId;
}

public void setPatientId(String patientId) {
this.patientId = patientId;
this(orders.getFhirResourceId(), orders.getPatientId());
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
package gov.hhs.cdc.trustedintermediary.etor.results;

public class ResultResponse {
private String fhirResourceId;

public ResultResponse(String fhirResourceId) {
this.fhirResourceId = fhirResourceId;
}
public record ResultResponse(String fhirResourceId) {

public ResultResponse(Result<?> result) {
this.fhirResourceId = result.getFhirResourceId();
}

public String getFhirResourceId() {
return fhirResourceId;
}

public void setFhirResourceId(final String fhirResourceId) {
this.fhirResourceId = fhirResourceId;
this(result.getFhirResourceId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class OrderResponseTest extends Specification {
def actual = new OrderResponse(orders)

then:
actual.getFhirResourceId() == expectedResourceId
actual.getPatientId() == expectedPatientId
actual.fhirResourceId() == expectedResourceId
actual.patientId() == expectedPatientId
}

def "test argument constructor"() {
Expand All @@ -38,7 +38,7 @@ class OrderResponseTest extends Specification {
def actual = new OrderResponse(expectedResourceId, expectedPatientId)

then:
actual.getFhirResourceId() == expectedResourceId
actual.getPatientId() == expectedPatientId
actual.fhirResourceId() == expectedResourceId
actual.patientId() == expectedPatientId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ResultResponseTest extends Specification {
def actual = new ResultResponse(result)

then:
actual.getFhirResourceId() == expectedResourceId
actual.fhirResourceId() == expectedResourceId
}

def "test argument constructor"() {
Expand All @@ -35,6 +35,6 @@ class ResultResponseTest extends Specification {
def actual = new ResultResponse(expectedResourceId)

then:
actual.getFhirResourceId() == expectedResourceId
actual.fhirResourceId() == expectedResourceId
}
}

0 comments on commit 6be5312

Please sign in to comment.