Skip to content

Commit

Permalink
Cleanups for #1195
Browse files Browse the repository at this point in the history
- Added Test for changed Method
- Added localization for exception message
  • Loading branch information
asturio committed Nov 25, 2024
1 parent 31ed3aa commit 6f2a82d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openpdf/src/main/java/com/lowagie/text/pdf/PdfPTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public PdfPCell addCell(String text) {
*/
public PdfPCell addCell(PdfPTable table) throws DocumentException {
if (table == this) {
throw new DocumentException("unable.to.add.self.to.table.contents");
throw new DocumentException(MessageLocalization.getMessage("unable.to.add.self.to.table.contents"));
}
defaultCell.setTable(table);
addCell(defaultCell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ tsa.1.failed.to.return.time.stamp.token.2=TSA '{1}' failed to return time stamp
two.byte.arrays.are.needed.if.the.type1.font.is.embedded=Two byte arrays are needed if the Type1 font is embedded.
type3.font.used.with.the.wrong.pdfwriter=Type3 font used with the wrong PdfWriter
types.is.null=types is null
unable.to.add.self.to.table.contents=Unable to add self to table contents.
unbalanced.begin.end.marked.content.operators=Unbalanced begin/end marked content operators.
unbalanced.begin.end.text.operators=Unbalanced begin/end text operators.
unbalanced.layer.operators=Unbalanced layer operators.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ fdf.header.not.found=Início de FDF não encontrado.
greaterthan.not.expected='>' inesperado
pdf.header.not.found=Início de PDF não encontrado.
pdf.startxref.not.found=startxref de PDF não encontrado.
unable.to.add.self.to.table.contents=Não é possível adicionar a si mesmo ao conteúdo da tabela.
xref.infinite.loop=Um loop infinito foi detectado na tabela xref.
31 changes: 31 additions & 0 deletions openpdf/src/test/java/com/lowagie/text/pdf/PdfPTableTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.lowagie.text.pdf;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.lowagie.text.DocumentException;
import com.lowagie.text.error_messages.MessageLocalization;
import java.io.IOException;
import org.junit.jupiter.api.Test;

class PdfPTableTest {

@Test
void whenAddCellWithSelf_shouldThrowException() {
PdfPTable table = new PdfPTable(1);
assertThatThrownBy(() -> table.addCell(table))
.isInstanceOf(DocumentException.class)
.hasMessage("Unable to add self to table contents.");
}

@Test
void whenAddCellWithSelf_shouldThrowException_pt() throws IOException {
MessageLocalization.setLanguage("pt", null);
PdfPTable table = new PdfPTable(1);
assertThatThrownBy(() -> table.addCell(table))
.isInstanceOf(DocumentException.class)
.hasMessage("Não é possível adicionar a si mesmo ao conteúdo da tabela.");
MessageLocalization.setLanguage("en", null);
}


}

0 comments on commit 6f2a82d

Please sign in to comment.