Skip to content

Commit 00a7062

Browse files
author
Artyom Yanchevsky
committed
Replace ExpectedException.none to Assert.assertThrows
DEVSIX-5287 Autoported commit. Original commit hash: [2c8594cff] Manual files: io/src/test/java/com/itextpdf/io/font/FontProgramTest.java kernel/src/test/java/com/itextpdf/kernel/pdf/canvas/parser/clipper/PolyNodeTest.java kernel/src/test/java/com/itextpdf/kernel/utils/XmlProcessorCreatorSecurityTest.java sign/src/test/java/com/itextpdf/signatures/CertificateSupportedCriticalExtensionsTest.java styled-xml-parser/src/test/java/com/itextpdf/styledxmlparser/resolver/resource/ResourceResolverTest.java styled-xml-parser/src/test/java/com/itextpdf/styledxmlparser/resolver/resource/UriResolverTest.java
1 parent 14065a4 commit 00a7062

File tree

136 files changed

+3034
-4185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+3034
-4185
lines changed

itext.tests/itext.barcodes.tests/itext/barcodes/BarcodeDataMatrixTest.cs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -208,41 +208,32 @@ public virtual void Barcode11Test() {
208208

209209
[NUnit.Framework.Test]
210210
public virtual void Barcode12Test() {
211-
NUnit.Framework.Assert.That(() => {
212-
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
213-
barcodeDataMatrix.SetWidth(18);
214-
barcodeDataMatrix.SetHeight(18);
215-
byte[] str = "AbcdFFghijklmnop".GetBytes();
216-
barcodeDataMatrix.SetCode(str, -1, str.Length);
217-
}
218-
, NUnit.Framework.Throws.InstanceOf<IndexOutOfRangeException>())
219-
;
211+
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
212+
barcodeDataMatrix.SetWidth(18);
213+
barcodeDataMatrix.SetHeight(18);
214+
byte[] str = "AbcdFFghijklmnop".GetBytes();
215+
Exception e = NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => barcodeDataMatrix.SetCode
216+
(str, -1, str.Length));
220217
}
221218

222219
[NUnit.Framework.Test]
223220
public virtual void Barcode13Test() {
224-
NUnit.Framework.Assert.That(() => {
225-
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
226-
barcodeDataMatrix.SetWidth(18);
227-
barcodeDataMatrix.SetHeight(18);
228-
byte[] str = "AbcdFFghijklmnop".GetBytes();
229-
barcodeDataMatrix.SetCode(str, 0, str.Length + 1);
230-
}
231-
, NUnit.Framework.Throws.InstanceOf<IndexOutOfRangeException>())
232-
;
221+
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
222+
barcodeDataMatrix.SetWidth(18);
223+
barcodeDataMatrix.SetHeight(18);
224+
byte[] str = "AbcdFFghijklmnop".GetBytes();
225+
NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => barcodeDataMatrix.SetCode(str, 0, str
226+
.Length + 1));
233227
}
234228

235229
[NUnit.Framework.Test]
236230
public virtual void Barcode14Test() {
237-
NUnit.Framework.Assert.That(() => {
238-
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
239-
barcodeDataMatrix.SetWidth(18);
240-
barcodeDataMatrix.SetHeight(18);
241-
byte[] str = "AbcdFFghijklmnop".GetBytes();
242-
barcodeDataMatrix.SetCode(str, 0, -1);
243-
}
244-
, NUnit.Framework.Throws.InstanceOf<IndexOutOfRangeException>())
245-
;
231+
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
232+
barcodeDataMatrix.SetWidth(18);
233+
barcodeDataMatrix.SetHeight(18);
234+
byte[] str = "AbcdFFghijklmnop".GetBytes();
235+
NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => barcodeDataMatrix.SetCode(str, 0, -1)
236+
);
246237
}
247238

248239
[NUnit.Framework.Test]

itext.tests/itext.barcodes.tests/itext/barcodes/BarcodeEANUnitTest.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,14 @@ public virtual void GetBarcodeSizeSUPP2Test() {
187187

188188
[NUnit.Framework.Test]
189189
public virtual void GetBarcodeSizeIncorrectTypeTest() {
190-
NUnit.Framework.Assert.That(() => {
191-
PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()));
192-
Barcode1D barcode = new BarcodeEAN(document);
193-
barcode.SetCode("9781935182610");
194-
// Set incorrect type
195-
barcode.SetCodeType(1234);
196-
// We do expect an exception here
197-
barcode.GetBarcodeSize();
198-
}
199-
, NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo("Invalid code type"))
200-
;
190+
PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()));
191+
Barcode1D barcode = new BarcodeEAN(document);
192+
barcode.SetCode("9781935182610");
193+
// Set incorrect type
194+
barcode.SetCodeType(1234);
195+
// We do expect an exception here
196+
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => barcode.GetBarcodeSize());
197+
NUnit.Framework.Assert.AreEqual("Invalid code type", e.Message);
201198
}
202199
}
203200
}

itext.tests/itext.barcodes.tests/itext/barcodes/BarcodePDF417Test.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,16 @@ public virtual void Barcode417OptionsWithBarcodeGenerationTest() {
315315

316316
[NUnit.Framework.Test]
317317
public virtual void Barcode417OptionsWithBarcodeGenerationInvalidSizeTest() {
318-
NUnit.Framework.Assert.That(() => {
319-
MemoryStream baos = new MemoryStream();
320-
PdfWriter writer = new PdfWriter(baos);
321-
PdfDocument document = new PdfDocument(writer);
322-
PdfPage page = document.AddNewPage();
323-
PdfCanvas canvas = new PdfCanvas(page);
324-
BarcodePDF417 barcode = new BarcodePDF417();
325-
barcode.SetOptions(64);
326-
barcode.PlaceBarcode(canvas, null);
327-
NUnit.Framework.Assert.AreEqual(64, barcode.GetOptions());
328-
}
329-
, NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo("Invalid codeword size."))
330-
;
318+
MemoryStream baos = new MemoryStream();
319+
PdfWriter writer = new PdfWriter(baos);
320+
PdfDocument document = new PdfDocument(writer);
321+
PdfPage page = document.AddNewPage();
322+
PdfCanvas canvas = new PdfCanvas(page);
323+
BarcodePDF417 barcode = new BarcodePDF417();
324+
barcode.SetOptions(64);
325+
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => barcode.PlaceBarcode(canvas, null));
326+
NUnit.Framework.Assert.AreEqual("Invalid codeword size.", e.Message);
327+
NUnit.Framework.Assert.AreEqual(64, barcode.GetOptions());
331328
}
332329

333330
private PdfFormXObject CreateMacroBarcodePart(PdfDocument document, String text, float mh, float mw, int segmentId

itext.tests/itext.forms.tests/itext/forms/XfdfUnitTest.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2020
You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
23+
using System;
2324
using iText.Forms.Xfdf;
2425
using iText.Test;
2526

2627
namespace iText.Forms {
2728
public class XfdfUnitTest : ExtendedITextTest {
2829
[NUnit.Framework.Test]
2930
public virtual void FitObjectWithEmptyPageTest() {
30-
NUnit.Framework.Assert.That(() => {
31-
FitObject fitObject = new FitObject(null);
32-
NUnit.Framework.Assert.Fail();
33-
}
34-
, NUnit.Framework.Throws.InstanceOf<XfdfException>().With.Message.EqualTo(XfdfException.PAGE_IS_MISSING))
35-
;
31+
Exception e = NUnit.Framework.Assert.Catch(typeof(XfdfException), () => new FitObject(null));
32+
NUnit.Framework.Assert.AreEqual(XfdfException.PAGE_IS_MISSING, e.Message);
3633
}
3734
}
3835
}

itext.tests/itext.forms.tests/itext/forms/XfdfWriterTest.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -955,21 +955,21 @@ public virtual void XfdfDropDown() {
955955

956956
[NUnit.Framework.Test]
957957
public virtual void XfdfEmptyAttributeTest() {
958-
NUnit.Framework.Assert.That(() => {
959-
XfdfObject xfdfObject = new XfdfObject();
960-
AnnotsObject annots = new AnnotsObject();
961-
xfdfObject.SetAnnots(annots);
962-
AnnotObject annot = new AnnotObject();
963-
annots.AddAnnot(annot);
964-
String namePresent = "name1";
965-
String nameAbsent = null;
966-
String valuePresent = "value";
967-
String valueAbsent = null;
968-
annot.AddAttribute(new AttributeObject(nameAbsent, valuePresent));
969-
annot.AddAttribute(new AttributeObject(namePresent, valueAbsent));
970-
}
971-
, NUnit.Framework.Throws.InstanceOf<XfdfException>().With.Message.EqualTo(XfdfException.ATTRIBUTE_NAME_OR_VALUE_MISSING))
972-
;
958+
XfdfObject xfdfObject = new XfdfObject();
959+
AnnotsObject annots = new AnnotsObject();
960+
xfdfObject.SetAnnots(annots);
961+
AnnotObject annot = new AnnotObject();
962+
annots.AddAnnot(annot);
963+
String namePresent = "name1";
964+
String nameAbsent = null;
965+
String valuePresent = "value";
966+
String valueAbsent = null;
967+
Exception e = NUnit.Framework.Assert.Catch(typeof(XfdfException), () => annot.AddAttribute(new AttributeObject
968+
(nameAbsent, valuePresent)));
969+
NUnit.Framework.Assert.AreEqual(XfdfException.ATTRIBUTE_NAME_OR_VALUE_MISSING, e.Message);
970+
Exception e2 = NUnit.Framework.Assert.Catch(typeof(XfdfException), () => annot.AddAttribute(new AttributeObject
971+
(namePresent, valueAbsent)));
972+
NUnit.Framework.Assert.AreEqual(XfdfException.ATTRIBUTE_NAME_OR_VALUE_MISSING, e2.Message);
973973
}
974974
}
975975
}

itext.tests/itext.forms.tests/itext/forms/xfa/XfaSecurityTest.cs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,57 +85,45 @@ public virtual void XfaExternalFileCustomFactoryTest() {
8585
String inFileName = SOURCE_FOLDER + "xfaExternalFile.pdf";
8686
XmlProcessorCreator.SetXmlParserFactory(new SecurityTestXmlParserFactory());
8787
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inFileName), new PdfWriter(new MemoryStream()))) {
88-
NUnit.Framework.Assert.That(() => {
89-
PdfAcroForm.GetAcroForm(pdfDoc, true);
90-
}
91-
, NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo(ExceptionTestUtil.GetXxeTestMessage()))
92-
;
88+
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => PdfAcroForm.GetAcroForm(pdfDoc, true
89+
));
90+
NUnit.Framework.Assert.AreEqual(ExceptionTestUtil.GetXxeTestMessage(), e.Message);
9391
}
9492
}
9593

9694
[NUnit.Framework.Test]
9795
public virtual void XfaExternalFileXfaFormTest() {
9896
String inFileName = SOURCE_FOLDER + "xfaExternalFile.pdf";
9997
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inFileName))) {
100-
NUnit.Framework.Assert.That(() => {
101-
new XfaForm(pdfDoc);
102-
}
103-
, NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo(DTD_EXCEPTION_MESSAGE))
104-
;
98+
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => new XfaForm(pdfDoc));
99+
NUnit.Framework.Assert.AreEqual(DTD_EXCEPTION_MESSAGE, e.Message);
105100
}
106101
}
107102

108103
[NUnit.Framework.Test]
109104
public virtual void XfaWithDtdXfaFormTest() {
110105
using (Stream inputStream = new MemoryStream(XFA_WITH_DTD_XML.GetBytes(System.Text.Encoding.UTF8))) {
111-
NUnit.Framework.Assert.That(() => {
112-
new XfaForm(inputStream);
113-
}
114-
, NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo(DTD_EXCEPTION_MESSAGE))
115-
;
106+
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => new XfaForm(inputStream));
107+
NUnit.Framework.Assert.AreEqual(DTD_EXCEPTION_MESSAGE, e.Message);
116108
}
117109
}
118110

119111
[NUnit.Framework.Test]
120112
public virtual void FillXfaFormTest() {
121113
using (Stream inputStream = new MemoryStream(XFA_WITH_DTD_XML.GetBytes(System.Text.Encoding.UTF8))) {
122114
XfaForm form = new XfaForm();
123-
NUnit.Framework.Assert.That(() => {
124-
form.FillXfaForm(inputStream, true);
125-
}
126-
, NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo(DTD_EXCEPTION_MESSAGE))
127-
;
115+
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => form.FillXfaForm(inputStream, true)
116+
);
117+
NUnit.Framework.Assert.AreEqual(DTD_EXCEPTION_MESSAGE, e.Message);
128118
}
129119
}
130120

131121
private void XfaSecurityExceptionTest(String inputFileName) {
132122
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inputFileName), new PdfWriter(new MemoryStream()
133123
))) {
134-
NUnit.Framework.Assert.That(() => {
135-
PdfAcroForm.GetAcroForm(pdfDoc, true);
136-
}
137-
, NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo(DTD_EXCEPTION_MESSAGE))
138-
;
124+
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => PdfAcroForm.GetAcroForm(pdfDoc, true
125+
));
126+
NUnit.Framework.Assert.AreEqual(DTD_EXCEPTION_MESSAGE, e.Message);
139127
}
140128
}
141129
}

itext.tests/itext.forms.tests/itext/forms/xfdf/XfdfSecurityTest.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,19 @@ public class XfdfSecurityTest : ExtendedITextTest {
5757
public virtual void XxeVulnerabilityXfdfTest() {
5858
XmlProcessorCreator.SetXmlParserFactory(new DefaultSafeXmlParserFactory());
5959
using (Stream inputStream = new MemoryStream(XFDF_WITH_XXE.GetBytes(System.Text.Encoding.UTF8))) {
60-
NUnit.Framework.Assert.That(() => {
61-
XfdfFileUtils.CreateXfdfDocumentFromStream(inputStream);
62-
}
63-
, NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo(ExceptionTestUtil.GetDoctypeIsDisallowedExceptionMessage()))
64-
;
60+
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => XfdfFileUtils.CreateXfdfDocumentFromStream
61+
(inputStream));
62+
NUnit.Framework.Assert.AreEqual(ExceptionTestUtil.GetDoctypeIsDisallowedExceptionMessage(), e.Message);
6563
}
6664
}
6765

6866
[NUnit.Framework.Test]
6967
public virtual void XxeVulnerabilityXfdfCustomXmlParserTest() {
7068
XmlProcessorCreator.SetXmlParserFactory(new SecurityTestXmlParserFactory());
7169
using (Stream inputStream = new MemoryStream(XFDF_WITH_XXE.GetBytes(System.Text.Encoding.UTF8))) {
72-
NUnit.Framework.Assert.That(() => {
73-
XfdfFileUtils.CreateXfdfDocumentFromStream(inputStream);
74-
}
75-
, NUnit.Framework.Throws.InstanceOf<PdfException>().With.Message.EqualTo("Test message"))
76-
;
70+
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => XfdfFileUtils.CreateXfdfDocumentFromStream
71+
(inputStream));
72+
NUnit.Framework.Assert.AreEqual("Test message", e.Message);
7773
}
7874
}
7975
}

itext.tests/itext.io.tests/itext/io/font/FontCacheNoFontAsianTest.cs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -125,46 +125,32 @@ public virtual void GetRegistryNamesNoFontAsian() {
125125

126126
[NUnit.Framework.Test]
127127
public virtual void GetCid2UniCMapNoFontAsian() {
128-
NUnit.Framework.Assert.That(() => {
129-
// Without font-asian module in the class path
130-
// no CMap can be found.
131-
FontCache.GetCid2UniCmap("UniJIS-UTF16-H");
132-
}
133-
, NUnit.Framework.Throws.InstanceOf<iText.IO.IOException>())
134-
;
128+
// Without font-asian module in the class path
129+
// no CMap can be found.
130+
NUnit.Framework.Assert.Catch(typeof(iText.IO.IOException), () => FontCache.GetCid2UniCmap("UniJIS-UTF16-H"
131+
));
135132
}
136133

137134
[NUnit.Framework.Test]
138135
public virtual void GetUni2CidCMapNoFontAsian() {
139-
NUnit.Framework.Assert.That(() => {
140-
// Without font-asian module in the class path
141-
// no CMap can be found.
142-
FontCache.GetUni2CidCmap("UniJIS-UTF16-H");
143-
}
144-
, NUnit.Framework.Throws.InstanceOf<iText.IO.IOException>())
145-
;
136+
// Without font-asian module in the class path
137+
// no CMap can be found.
138+
NUnit.Framework.Assert.Catch(typeof(iText.IO.IOException), () => FontCache.GetUni2CidCmap("UniJIS-UTF16-H"
139+
));
146140
}
147141

148142
[NUnit.Framework.Test]
149143
public virtual void GetByte2CidCMapNoFontAsian() {
150-
NUnit.Framework.Assert.That(() => {
151-
// Without font-asian module in the class path
152-
// no CMap can be found.
153-
FontCache.GetByte2CidCmap("78ms-RKSJ-H");
154-
}
155-
, NUnit.Framework.Throws.InstanceOf<iText.IO.IOException>())
156-
;
144+
// Without font-asian module in the class path
145+
// no CMap can be found.
146+
NUnit.Framework.Assert.Catch(typeof(iText.IO.IOException), () => FontCache.GetByte2CidCmap("78ms-RKSJ-H"));
157147
}
158148

159149
[NUnit.Framework.Test]
160150
public virtual void GetCid2ByteCMapNoFontAsian() {
161-
NUnit.Framework.Assert.That(() => {
162-
// Without font-asian module in the class path
163-
// no CMap can be found.
164-
FontCache.GetCid2Byte("78ms-RKSJ-H");
165-
}
166-
, NUnit.Framework.Throws.InstanceOf<iText.IO.IOException>())
167-
;
151+
// Without font-asian module in the class path
152+
// no CMap can be found.
153+
NUnit.Framework.Assert.Catch(typeof(iText.IO.IOException), () => FontCache.GetCid2Byte("78ms-RKSJ-H"));
168154
}
169155

170156
private class FontProgramMock : FontProgram {

0 commit comments

Comments
 (0)