Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1588: NPE printing or previewing DropShip #1601

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions megameklab/src/megameklab/printing/PrintAero.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.print.PageFormat;
import java.io.File;
import java.text.DecimalFormat;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -126,8 +125,12 @@ protected void writeTextFields() {
super.writeTextFields();
setTextField(HS_TYPE, formatHeatSinkType());
setTextField(HS_COUNT, formatHeatSinkCount());
setTextField(ENGINE_TYPE, aero.getEngine().getShortEngineName()
if (aero.getEngine() != null) {
setTextField(ENGINE_TYPE, aero.getEngine().getShortEngineName()
.replaceAll("\\[.*]", "").trim());
} else {
setTextField(ENGINE_TYPE, "Unknown");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.awt.print.PageFormat;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -72,4 +73,28 @@ void fillsSheetIllegal() {
var unsupportedEntities = List.of(new SupportTank());
assertThrows(IllegalArgumentException.class, () -> PrintSmallUnitSheet.fillsSheet(unsupportedEntities, noTables));
}

/**
* Verify that we can process the image (basically, create the record sheet output) for an Aero with a null Engine object
* without throwing an NPE.
*/
@Test
void testAeroWithoutEngineDoesNotThrowNPE() {
// Required setting objects
PageFormat pf = new PageFormat();
RecordSheetOptions rso = new RecordSheetOptions();

// Set up DS entity with required attributes
Dropship testDS = new Dropship();
testDS.setChassis("Test Dropship");
testDS.setModel("TDS-999");

// Create print object
PrintAero pa = new PrintDropship(testDS, 1, rso);

// Test A) Document is created, B) Engine is null, C) processImage() doesn't throw.
assertTrue(pa.createDocument(1, pf, false));
assertNull(testDS.getEngine());
pa.processImage(1, pf);
}
}