Skip to content

Commit 6f2a82d

Browse files
committed
Cleanups for #1195
- Added Test for changed Method - Added localization for exception message
1 parent 31ed3aa commit 6f2a82d

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

openpdf/src/main/java/com/lowagie/text/pdf/PdfPTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ public PdfPCell addCell(String text) {
658658
*/
659659
public PdfPCell addCell(PdfPTable table) throws DocumentException {
660660
if (table == this) {
661-
throw new DocumentException("unable.to.add.self.to.table.contents");
661+
throw new DocumentException(MessageLocalization.getMessage("unable.to.add.self.to.table.contents"));
662662
}
663663
defaultCell.setTable(table);
664664
addCell(defaultCell);

openpdf/src/main/resources/com/lowagie/text/error_messages/en.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ tsa.1.failed.to.return.time.stamp.token.2=TSA '{1}' failed to return time stamp
359359
two.byte.arrays.are.needed.if.the.type1.font.is.embedded=Two byte arrays are needed if the Type1 font is embedded.
360360
type3.font.used.with.the.wrong.pdfwriter=Type3 font used with the wrong PdfWriter
361361
types.is.null=types is null
362+
unable.to.add.self.to.table.contents=Unable to add self to table contents.
362363
unbalanced.begin.end.marked.content.operators=Unbalanced begin/end marked content operators.
363364
unbalanced.begin.end.text.operators=Unbalanced begin/end text operators.
364365
unbalanced.layer.operators=Unbalanced layer operators.

openpdf/src/main/resources/com/lowagie/text/error_messages/pt.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ fdf.header.not.found=Início de FDF não encontrado.
55
greaterthan.not.expected='>' inesperado
66
pdf.header.not.found=Início de PDF não encontrado.
77
pdf.startxref.not.found=startxref de PDF não encontrado.
8+
unable.to.add.self.to.table.contents=Não é possível adicionar a si mesmo ao conteúdo da tabela.
89
xref.infinite.loop=Um loop infinito foi detectado na tabela xref.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.lowagie.text.pdf;
2+
3+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4+
5+
import com.lowagie.text.DocumentException;
6+
import com.lowagie.text.error_messages.MessageLocalization;
7+
import java.io.IOException;
8+
import org.junit.jupiter.api.Test;
9+
10+
class PdfPTableTest {
11+
12+
@Test
13+
void whenAddCellWithSelf_shouldThrowException() {
14+
PdfPTable table = new PdfPTable(1);
15+
assertThatThrownBy(() -> table.addCell(table))
16+
.isInstanceOf(DocumentException.class)
17+
.hasMessage("Unable to add self to table contents.");
18+
}
19+
20+
@Test
21+
void whenAddCellWithSelf_shouldThrowException_pt() throws IOException {
22+
MessageLocalization.setLanguage("pt", null);
23+
PdfPTable table = new PdfPTable(1);
24+
assertThatThrownBy(() -> table.addCell(table))
25+
.isInstanceOf(DocumentException.class)
26+
.hasMessage("Não é possível adicionar a si mesmo ao conteúdo da tabela.");
27+
MessageLocalization.setLanguage("en", null);
28+
}
29+
30+
31+
}

0 commit comments

Comments
 (0)