Skip to content

Commit 5d04dec

Browse files
Fix sonarqube issues
DEVSIX-5706
1 parent 89df9ce commit 5d04dec

File tree

47 files changed

+492
-125
lines changed

Some content is hidden

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

47 files changed

+492
-125
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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 System.Collections.Generic;
25+
using iText.Commons.Actions.Confirmations;
26+
using iText.Commons.Actions.Data;
27+
using iText.Commons.Actions.Processors;
28+
using iText.Commons.Actions.Sequence;
29+
using iText.Test;
30+
31+
namespace iText.Commons.Actions {
32+
public class AbstractITextConfigurationEventTest : ExtendedITextTest {
33+
[NUnit.Framework.TearDown]
34+
public virtual void After() {
35+
ProductEventHandler.INSTANCE.ClearProcessors();
36+
}
37+
38+
[NUnit.Framework.Test]
39+
public virtual void AddProcessorTest() {
40+
AbstractITextConfigurationEvent @event = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
41+
();
42+
ITextProductEventProcessor processor = new AbstractITextConfigurationEventTest.TestITextProductEventProcessor
43+
();
44+
@event.AddProcessor(processor);
45+
IDictionary<String, ITextProductEventProcessor> processors = ProductEventHandler.INSTANCE.GetProcessors();
46+
NUnit.Framework.Assert.AreEqual(1, processors.Count);
47+
NUnit.Framework.Assert.IsTrue(processors.Values.Contains(processor));
48+
}
49+
50+
[NUnit.Framework.Test]
51+
public virtual void GetProcessorsTest() {
52+
AbstractITextConfigurationEvent @event = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
53+
();
54+
ITextProductEventProcessor processor = new AbstractITextConfigurationEventTest.TestITextProductEventProcessor
55+
();
56+
@event.AddProcessor(processor);
57+
NUnit.Framework.Assert.AreEqual(ProductEventHandler.INSTANCE.GetProcessors(), @event.GetProcessors());
58+
}
59+
60+
[NUnit.Framework.Test]
61+
public virtual void RemoveProcessorTest() {
62+
AbstractITextConfigurationEvent @event = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
63+
();
64+
ITextProductEventProcessor processor = new AbstractITextConfigurationEventTest.TestITextProductEventProcessor
65+
();
66+
@event.AddProcessor(processor);
67+
@event.RemoveProcessor(processor.GetProductName());
68+
IDictionary<String, ITextProductEventProcessor> processors = ProductEventHandler.INSTANCE.GetProcessors();
69+
NUnit.Framework.Assert.AreEqual(0, processors.Count);
70+
}
71+
72+
[NUnit.Framework.Test]
73+
public virtual void GetActiveProcessorTest() {
74+
AbstractITextConfigurationEvent @event = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
75+
();
76+
ITextProductEventProcessor processor = new AbstractITextConfigurationEventTest.TestITextProductEventProcessor
77+
();
78+
@event.AddProcessor(processor);
79+
NUnit.Framework.Assert.AreEqual(processor, @event.GetActiveProcessor(processor.GetProductName()));
80+
}
81+
82+
[NUnit.Framework.Test]
83+
public virtual void AddEventTest() {
84+
AbstractITextConfigurationEvent configurationEvent = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
85+
();
86+
AbstractProductProcessITextEvent processEvent = new AbstractITextConfigurationEventTest.TestAbstractProductProcessITextEvent
87+
();
88+
SequenceId id = new SequenceId();
89+
configurationEvent.AddEvent(id, processEvent);
90+
IList<AbstractProductProcessITextEvent> events = ProductEventHandler.INSTANCE.GetEvents(id);
91+
NUnit.Framework.Assert.AreEqual(1, events.Count);
92+
NUnit.Framework.Assert.AreEqual(processEvent, events[0]);
93+
}
94+
95+
[NUnit.Framework.Test]
96+
public virtual void GetEventsTest() {
97+
AbstractITextConfigurationEvent configurationEvent = new AbstractITextConfigurationEventTest.TestAbstractITextConfigurationEvent
98+
();
99+
SequenceId id = new SequenceId();
100+
configurationEvent.AddEvent(id, new AbstractITextConfigurationEventTest.TestAbstractProductProcessITextEvent
101+
());
102+
configurationEvent.AddEvent(id, new AbstractITextConfigurationEventTest.TestAbstractProductProcessITextEvent
103+
());
104+
NUnit.Framework.Assert.AreEqual(ProductEventHandler.INSTANCE.GetEvents(id), configurationEvent.GetEvents(id
105+
));
106+
}
107+
108+
internal class TestAbstractITextConfigurationEvent : AbstractITextConfigurationEvent {
109+
protected internal override void DoAction() {
110+
}
111+
// Empty method.
112+
}
113+
114+
internal class TestAbstractProductProcessITextEvent : AbstractProductProcessITextEvent {
115+
public TestAbstractProductProcessITextEvent()
116+
: base(new SequenceId(), new ProductData("test public product name", "test product name", "test version",
117+
0, 1), null, EventConfirmationType.ON_DEMAND) {
118+
}
119+
120+
public override String GetEventType() {
121+
return "test event type";
122+
}
123+
}
124+
125+
internal class TestITextProductEventProcessor : ITextProductEventProcessor {
126+
public virtual void OnEvent(AbstractProductProcessITextEvent @event) {
127+
}
128+
129+
// Empty method.
130+
public virtual String GetProductName() {
131+
return "test product";
132+
}
133+
134+
public virtual String GetUsageType() {
135+
return "test usage type";
136+
}
137+
138+
public virtual String GetProducer() {
139+
return "test producer";
140+
}
141+
}
142+
}
143+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.Data;
25+
using iText.Test;
26+
27+
namespace iText.Commons.Actions {
28+
public class AbstractProductITextEventTest : ExtendedITextTest {
29+
[NUnit.Framework.Test]
30+
public virtual void NullProductDataTest() {
31+
Exception exception = NUnit.Framework.Assert.Catch(typeof(InvalidOperationException), () => new _AbstractProductITextEvent_36
32+
(null));
33+
NUnit.Framework.Assert.AreEqual("ProductData shouldn't be null.", exception.Message);
34+
}
35+
36+
private sealed class _AbstractProductITextEvent_36 : AbstractProductITextEvent {
37+
public _AbstractProductITextEvent_36(ProductData baseArg1)
38+
: base(baseArg1) {
39+
}
40+
}
41+
}
42+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 System.Collections.Generic;
25+
using iText.Commons.Actions.Data;
26+
using iText.Commons.Logs;
27+
using iText.Test;
28+
using iText.Test.Attributes;
29+
30+
namespace iText.Commons.Actions {
31+
public class AbstractStatisticsEventTest : ExtendedITextTest {
32+
[NUnit.Framework.Test]
33+
public virtual void ConstructorTest() {
34+
AbstractStatisticsEventTest.DummyStatisticsEvent dummyEvent = new AbstractStatisticsEventTest.DummyStatisticsEvent
35+
(new ProductData("public name", "product name", "version", 15, 3000));
36+
ProductData data = dummyEvent.GetProductData();
37+
NUnit.Framework.Assert.AreEqual("public name", data.GetPublicProductName());
38+
NUnit.Framework.Assert.AreEqual("product name", data.GetProductName());
39+
NUnit.Framework.Assert.AreEqual("version", data.GetVersion());
40+
NUnit.Framework.Assert.AreEqual(15, data.GetSinceCopyrightYear());
41+
NUnit.Framework.Assert.AreEqual(3000, data.GetToCopyrightYear());
42+
}
43+
44+
[NUnit.Framework.Test]
45+
[LogMessage(CommonsLogMessageConstant.INVALID_STATISTICS_NAME)]
46+
public virtual void CreateStatisticsAggregatorFromNameTest() {
47+
AbstractStatisticsEventTest.DummyStatisticsEvent dummyEvent = new AbstractStatisticsEventTest.DummyStatisticsEvent
48+
(new ProductData("public name", "product name", "version", 15, 3000));
49+
NUnit.Framework.Assert.IsNull(dummyEvent.CreateStatisticsAggregatorFromName("statisticsName"));
50+
}
51+
52+
internal class DummyStatisticsEvent : AbstractStatisticsEvent {
53+
internal DummyStatisticsEvent(ProductData data)
54+
: base(data) {
55+
}
56+
57+
public override IList<String> GetStatisticsNames() {
58+
return null;
59+
}
60+
}
61+
}
62+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 iText.Test;
24+
25+
namespace iText.Commons.Actions.Data {
26+
public class CommonsProductDataTest : ExtendedITextTest {
27+
[NUnit.Framework.Test]
28+
public virtual void GetInstanceTest() {
29+
ProductData commonsProductData = CommonsProductData.GetInstance();
30+
NUnit.Framework.Assert.AreEqual("Commons", commonsProductData.GetPublicProductName());
31+
NUnit.Framework.Assert.AreEqual("commons", commonsProductData.GetProductName());
32+
NUnit.Framework.Assert.AreEqual("7.2.0-SNAPSHOT", commonsProductData.GetVersion());
33+
NUnit.Framework.Assert.AreEqual(2000, commonsProductData.GetSinceCopyrightYear());
34+
NUnit.Framework.Assert.AreEqual(2021, commonsProductData.GetToCopyrightYear());
35+
}
36+
}
37+
}

itext.tests/itext.commons.tests/itext/commons/actions/producer/ProducerBuilderTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ namespace iText.Commons.Actions.Producer {
3737
public class ProducerBuilderTest : ExtendedITextTest {
3838
[NUnit.Framework.Test]
3939
public virtual void EmptyEventsProducerLineTest() {
40+
NUnit.Framework.Assert.That(() => {
41+
ProducerBuilder.ModifyProducer(JavaCollectionsUtil.EmptyList<AbstractProductProcessITextEvent>(), null);
42+
}
43+
, NUnit.Framework.Throws.InstanceOf<ArgumentException>().With.Message.EqualTo(CommonsExceptionMessageConstant.NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT))
44+
;
45+
}
46+
47+
[NUnit.Framework.Test]
48+
public virtual void NullEventsProducerLineTest() {
4049
NUnit.Framework.Assert.That(() => {
4150
ProducerBuilder.ModifyProducer((IList<AbstractProductProcessITextEvent>)null, null);
4251
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.Test;
25+
26+
namespace iText.Commons.Exceptions {
27+
public class ITextExceptionTest : ExtendedITextTest {
28+
[NUnit.Framework.Test]
29+
public virtual void NoParametersConstructorTest() {
30+
Exception exception = NUnit.Framework.Assert.Catch(typeof(ITextException), () => {
31+
throw new ITextException();
32+
}
33+
);
34+
NUnit.Framework.Assert.AreEqual(CommonsExceptionMessageConstant.UNKNOWN_ITEXT_EXCEPTION, exception.Message
35+
);
36+
}
37+
38+
[NUnit.Framework.Test]
39+
public virtual void StringConstructorTest() {
40+
Exception exception = NUnit.Framework.Assert.Catch(typeof(ITextException), () => {
41+
throw new ITextException("message");
42+
}
43+
);
44+
NUnit.Framework.Assert.AreEqual("message", exception.Message);
45+
}
46+
47+
[NUnit.Framework.Test]
48+
public virtual void ThrowableConstructorTest() {
49+
Exception cause = new Exception("cause");
50+
Exception exception = NUnit.Framework.Assert.Catch(typeof(ITextException), () => {
51+
throw new ITextException(cause);
52+
}
53+
);
54+
NUnit.Framework.Assert.AreEqual(CommonsExceptionMessageConstant.UNKNOWN_ITEXT_EXCEPTION, exception.Message
55+
);
56+
NUnit.Framework.Assert.AreEqual(cause, exception.InnerException);
57+
}
58+
}
59+
}

itext/itext.commons/itext/commons/actions/AbstractContextBasedEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public abstract class AbstractContextBasedEventHandler : IBaseEventHandler {
3232
/// contexts.
3333
/// </summary>
3434
/// <param name="onUnknownContext">is a fallback for events within unknown context</param>
35-
public AbstractContextBasedEventHandler(IContext onUnknownContext)
35+
protected internal AbstractContextBasedEventHandler(IContext onUnknownContext)
3636
: base() {
3737
this.defaultContext = onUnknownContext;
3838
}

itext/itext.commons/itext/commons/actions/AbstractContextBasedITextEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public abstract class AbstractContextBasedITextEvent : AbstractProductITextEvent
3737
/// <summary>Creates an event containing auxiliary meta data.</summary>
3838
/// <param name="productData">is a description of the product which has generated an event</param>
3939
/// <param name="metaInfo">is an auxiliary meta info</param>
40-
public AbstractContextBasedITextEvent(ProductData productData, IMetaInfo metaInfo)
40+
protected internal AbstractContextBasedITextEvent(ProductData productData, IMetaInfo metaInfo)
4141
: base(productData) {
4242
this.metaInfo = metaInfo;
4343
}

0 commit comments

Comments
 (0)