Skip to content

Commit f21cfcd

Browse files
Improve ProductData and AbstractContextBasedITextEvent#setMetaInfo test coverage
DEVSIX-5706
1 parent b84e364 commit f21cfcd

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2021 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using System;
24+
using iText.Commons.Actions.Contexts;
25+
using iText.Commons.Actions.Data;
26+
using iText.Commons.Ecosystem;
27+
using iText.Commons.Exceptions;
28+
using iText.Test;
29+
30+
namespace iText.Commons.Actions {
31+
public class AbstractContextBasedITextEventTest : ExtendedITextTest {
32+
[NUnit.Framework.Test]
33+
public virtual void SetMetaInfoTest() {
34+
AbstractContextBasedITextEventTest.BasicAbstractContextBasedITextEvent e = new AbstractContextBasedITextEventTest.BasicAbstractContextBasedITextEvent
35+
(CommonsProductData.GetInstance(), null);
36+
TestMetaInfo metaInfoAfter = new TestMetaInfo("meta-info-after");
37+
e.SetMetaInfo(metaInfoAfter);
38+
NUnit.Framework.Assert.AreSame(metaInfoAfter, e.GetMetaInfo());
39+
}
40+
41+
[NUnit.Framework.Test]
42+
public virtual void ResetMetaInfoForbiddenTest() {
43+
TestMetaInfo metaInfoBefore = new TestMetaInfo("meta-info-before");
44+
TestMetaInfo metaInfoAfter = new TestMetaInfo("meta-info-after");
45+
AbstractContextBasedITextEventTest.BasicAbstractContextBasedITextEvent e = new AbstractContextBasedITextEventTest.BasicAbstractContextBasedITextEvent
46+
(CommonsProductData.GetInstance(), metaInfoBefore);
47+
NUnit.Framework.Assert.AreSame(metaInfoBefore, e.GetMetaInfo());
48+
Exception exception = NUnit.Framework.Assert.Catch(typeof(InvalidOperationException), () => e.SetMetaInfo(
49+
metaInfoAfter));
50+
NUnit.Framework.Assert.AreEqual(CommonsExceptionMessageConstant.META_INFO_SHOULDNT_BE_NULL, exception.Message
51+
);
52+
}
53+
54+
private class BasicAbstractContextBasedITextEvent : AbstractContextBasedITextEvent {
55+
protected internal BasicAbstractContextBasedITextEvent(ProductData productData, IMetaInfo metaInfo)
56+
: base(productData, metaInfo) {
57+
}
58+
}
59+
}
60+
}

itext.tests/itext.commons.tests/itext/commons/actions/data/ProductDataTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,32 @@ public virtual void ProductDataCreationTest() {
3333
NUnit.Framework.Assert.AreEqual(1900, productData.GetSinceCopyrightYear());
3434
NUnit.Framework.Assert.AreEqual(2100, productData.GetToCopyrightYear());
3535
}
36+
37+
[NUnit.Framework.Test]
38+
public virtual void EqualsTest() {
39+
ProductData a = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
40+
ProductData b = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
41+
NUnit.Framework.Assert.AreEqual(a, a);
42+
NUnit.Framework.Assert.AreEqual(a, b);
43+
NUnit.Framework.Assert.AreEqual(b, a);
44+
}
45+
46+
[NUnit.Framework.Test]
47+
public virtual void NotEqualsTest() {
48+
ProductData a = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
49+
ProductData d = new ProductData("publicProductName", "productName", "1.2", 1910, 2110);
50+
NUnit.Framework.Assert.AreNotEqual(a, d);
51+
}
52+
53+
[NUnit.Framework.Test]
54+
public virtual void HashCodeTest() {
55+
ProductData a = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
56+
ProductData b = new ProductData("publicProductName", "productName", "1.2", 1900, 2100);
57+
NUnit.Framework.Assert.AreEqual(a, b);
58+
NUnit.Framework.Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
59+
int h1 = a.GetHashCode();
60+
int h2 = a.GetHashCode();
61+
NUnit.Framework.Assert.AreEqual(h1, h2);
62+
}
3663
}
3764
}

0 commit comments

Comments
 (0)