Skip to content

Commit

Permalink
Fixed potential NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
depryf committed Jul 23, 2024
1 parent f7c89cf commit 0093da5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ sonarqube {
property "sonar.projectKey", "imsweb_layout"
property "sonar.organization", "imsweb"
property "sonar.host.url", "https://sonarcloud.io"
property 'sonar.exclusions', '**/lab/*'
property 'sonar.coverage.exclusions', '**/lab/*'
property "sonar.exclusions", "**/lab/**"
property "sonar.coverage.exclusions", "**/lab/**"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ public String createLineFromRecord(Map<String, String> rec, RecordLayoutOptions
// read the data file using the new layout
List<Map<String, String>> records = layout.readAllRecords(file);
Assert.assertEquals(3, records.size());
for (Map<String, String> record : records) {
Assert.assertNotNull(record.get("recordType"));
Assert.assertNotNull(record.get("patientIdNumber"));
Assert.assertNotNull(record.get("race1"));
for (Map<String, String> rec : records) {
Assert.assertNotNull(rec.get("recordType"));
Assert.assertNotNull(rec.get("patientIdNumber"));
Assert.assertNotNull(rec.get("race1"));
}
Assert.assertEquals("20100615", records.get(0).get("dateOfBirth"));
Assert.assertEquals("2010", records.get(0).get("dateOfBirthYear"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.imsweb.layout.record.fixed.xml.FixedColumnLayoutXmlDto;
import com.imsweb.seerutils.SeerUtils;

@SuppressWarnings("ALL")
public class FixedColumnsLayoutTest {

@Test
Expand Down Expand Up @@ -342,29 +343,29 @@ public void testLayoutExtension() throws Exception {

@Test
public void testStateRequestorItems() throws IOException {
Map<String, String> record = new HashMap<>();
record.put("registryField1", "X");
Map<String, String> rec = new HashMap<>();
rec.put("registryField1", "X");

// this layout defines a 1-char field at the beginning of the state requestor items
RecordLayout layout = new FixedColumnsLayout(Thread.currentThread().getContextClassLoader().getResource("testing-state-requestor-items-1.xml"));
String line = layout.createLineFromRecord(record, null);
String line = layout.createLineFromRecord(rec, null);
Assert.assertEquals(3339, line.length());
record = layout.createRecordFromLine(line, null, null);
Assert.assertEquals("X", record.get("registryField1"));
rec = layout.createRecordFromLine(line, null, null);
Assert.assertEquals("X", rec.get("registryField1"));

// this layout defines a 1-char field in the middle of the state requestor items
layout = new FixedColumnsLayout(Thread.currentThread().getContextClassLoader().getResource("testing-state-requestor-items-2.xml"));
line = layout.createLineFromRecord(record, null);
line = layout.createLineFromRecord(rec, null);
Assert.assertEquals(3339, line.length());
record = layout.createRecordFromLine(line, null, null);
Assert.assertEquals("X", record.get("registryField1"));
rec = layout.createRecordFromLine(line, null, null);
Assert.assertEquals("X", rec.get("registryField1"));

// this layout defines a 1-char field at the end of the state requestor items
layout = new FixedColumnsLayout(Thread.currentThread().getContextClassLoader().getResource("testing-state-requestor-items-3.xml"));
line = layout.createLineFromRecord(record, null);
line = layout.createLineFromRecord(rec, null);
Assert.assertEquals(3339, line.length());
record = layout.createRecordFromLine(line, null, null);
Assert.assertEquals("X", record.get("registryField1"));
rec = layout.createRecordFromLine(line, null, null);
Assert.assertEquals("X", rec.get("registryField1"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void testDeprecationMappings() {
public void testBuildFileInfo() throws IOException {
RecordLayout layout = (RecordLayout)LayoutFactory.getLayout(LAYOUT_ID_NAACCR_16_INCIDENCE);

Map<String, String> record = layout.readAllRecords(new File(TestingUtils.getWorkingDirectory() + "/src/test/resources/fake-naaccr16-1-rec.txt")).get(0);
StringBuilder buf = new StringBuilder(layout.createLineFromRecord(record, null));
Map<String, String> rec = layout.readAllRecords(new File(TestingUtils.getWorkingDirectory() + "/src/test/resources/fake-naaccr16-1-rec.txt")).get(0);
StringBuilder buf = new StringBuilder(layout.createLineFromRecord(rec, null));
String line = buf.toString();
String lineShort = line.substring(0, 25);

Expand Down Expand Up @@ -143,12 +143,12 @@ public void testBuildFileInfo() throws IOException {
buf.replace(0, 1, "A");
buf.replace(16, 19, "160");
Assert.assertNull(layout.buildFileInfo(buf.toString(), options));
Assert.assertNull(layout.buildFileInfo(buf.toString().substring(0, 25), options));
Assert.assertNull(layout.buildFileInfo(buf.substring(0, 25), options));

// wrong version
buf.replace(0, 1, "I");
buf.replace(16, 19, "150");
Assert.assertNull(layout.buildFileInfo(buf.toString(), options));
Assert.assertNull(layout.buildFileInfo(buf.toString().substring(0, 25), options));
Assert.assertNull(layout.buildFileInfo(buf.substring(0, 25), options));
}
}

0 comments on commit 0093da5

Please sign in to comment.