|
| 1 | +/* |
| 2 | + * CDDL HEADER START |
| 3 | + * |
| 4 | + * The contents of this file are subject to the terms of the |
| 5 | + * Common Development and Distribution License (the "License"). |
| 6 | + * You may not use this file except in compliance with the License. |
| 7 | + * |
| 8 | + * See LICENSE.txt included in this distribution for the specific |
| 9 | + * language governing permissions and limitations under the License. |
| 10 | + * |
| 11 | + * When distributing Covered Code, include this CDDL HEADER in each |
| 12 | + * file and include the License file at LICENSE.txt. |
| 13 | + * If applicable, add the following below this CDDL HEADER, with the |
| 14 | + * fields enclosed by brackets "[]" replaced with your own identifying |
| 15 | + * information: Portions Copyright [yyyy] [name of copyright owner] |
| 16 | + * |
| 17 | + * CDDL HEADER END |
| 18 | + */ |
| 19 | + |
| 20 | +/* |
| 21 | + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
| 22 | + * Portions Copyright (c) 2017, Chris Fraire <[email protected]>. |
| 23 | + */ |
| 24 | + |
| 25 | +package org.opensolaris.opengrok.analysis.json; |
| 26 | + |
| 27 | +import java.io.BufferedReader; |
| 28 | +import java.io.InputStream; |
| 29 | +import java.io.InputStreamReader; |
| 30 | +import java.util.ArrayList; |
| 31 | +import java.util.List; |
| 32 | +import static org.junit.Assert.assertNotNull; |
| 33 | +import org.junit.Test; |
| 34 | +import static org.opensolaris.opengrok.util.CustomAssertions.assertSymbolStream; |
| 35 | + |
| 36 | +/** |
| 37 | + * Tests the {@link JsonSymbolTokenizer} class. |
| 38 | + */ |
| 39 | +public class JsonSymbolTokenizerTest { |
| 40 | + |
| 41 | + /** |
| 42 | + * Test sample.json v. samplesymbols.txt |
| 43 | + * @throws java.lang.Exception thrown on error |
| 44 | + */ |
| 45 | + @Test |
| 46 | + public void testJsonSymbolStream() throws Exception { |
| 47 | + InputStream jres = getClass().getClassLoader().getResourceAsStream( |
| 48 | + "org/opensolaris/opengrok/analysis/json/sample.json"); |
| 49 | + assertNotNull("despite sample.json as resource,", jres); |
| 50 | + InputStream symres = getClass().getClassLoader().getResourceAsStream( |
| 51 | + "org/opensolaris/opengrok/analysis/json/samplesymbols.txt"); |
| 52 | + assertNotNull("despite samplesymbols.txt as resource,", symres); |
| 53 | + |
| 54 | + List<String> expectedSymbols = new ArrayList<>(); |
| 55 | + try (BufferedReader wdsr = new BufferedReader(new InputStreamReader( |
| 56 | + symres, "UTF-8"))) { |
| 57 | + String line; |
| 58 | + while ((line = wdsr.readLine()) != null) { |
| 59 | + int hasho = line.indexOf('#'); |
| 60 | + if (hasho != -1) line = line.substring(0, hasho); |
| 61 | + expectedSymbols.add(line.trim()); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + assertSymbolStream(JsonSymbolTokenizer.class, jres, expectedSymbols); |
| 66 | + } |
| 67 | +} |
0 commit comments