|
| 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 | +package com.itextpdf.styledxmlparser.css.parse; |
| 24 | + |
| 25 | +import com.itextpdf.commons.utils.MessageFormatUtil; |
| 26 | +import com.itextpdf.io.exceptions.IOException; |
| 27 | +import com.itextpdf.styledxmlparser.exceptions.StyledXmlParserExceptionMessage; |
| 28 | +import com.itextpdf.test.ExtendedITextTest; |
| 29 | +import com.itextpdf.test.annotations.type.UnitTest; |
| 30 | + |
| 31 | +import org.junit.Assert; |
| 32 | +import org.junit.Test; |
| 33 | +import org.junit.experimental.categories.Category; |
| 34 | + |
| 35 | +@Category(UnitTest.class) |
| 36 | +public class CssSelectorParserTest extends ExtendedITextTest { |
| 37 | + |
| 38 | + @Test |
| 39 | + public void selectorBeginsWithSpaceTest() throws IOException { |
| 40 | + String space = " "; |
| 41 | + String selectorWithSpaceAtTheBeginning = space + ".spaceBefore"; |
| 42 | + |
| 43 | + Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, |
| 44 | + () -> CssSelectorParser.parseSelectorItems(selectorWithSpaceAtTheBeginning)); |
| 45 | + Assert.assertEquals( |
| 46 | + MessageFormatUtil.format(StyledXmlParserExceptionMessage.INVALID_TOKEN_AT_THE_BEGINNING_OF_SELECTOR, |
| 47 | + space), |
| 48 | + expectedException.getMessage()); |
| 49 | + } |
| 50 | +} |
0 commit comments