|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * SciJava Common shared library for SciJava software. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2009 - 2022 SciJava developers. |
| 6 | + * %% |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions are met: |
| 9 | + * |
| 10 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 11 | + * this list of conditions and the following disclaimer. |
| 12 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | + * this list of conditions and the following disclaimer in the documentation |
| 14 | + * and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 20 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | + * POSSIBILITY OF SUCH DAMAGE. |
| 27 | + * #L% |
| 28 | + */ |
| 29 | +package org.scijava.text; |
| 30 | + |
| 31 | +import static org.junit.Assert.assertEquals; |
| 32 | +import static org.junit.Assert.assertNotNull; |
| 33 | +import static org.junit.Assert.assertNull; |
| 34 | + |
| 35 | +import java.io.File; |
| 36 | +import java.util.Arrays; |
| 37 | +import java.util.List; |
| 38 | + |
| 39 | +import org.junit.After; |
| 40 | +import org.junit.Before; |
| 41 | +import org.junit.Test; |
| 42 | +import org.scijava.Context; |
| 43 | +import org.scijava.plugin.Plugin; |
| 44 | + |
| 45 | +/** Tests {@link TextService}. */ |
| 46 | +public class TextServiceTest { |
| 47 | + |
| 48 | + private Context ctx; |
| 49 | + private TextService textService; |
| 50 | + |
| 51 | + @Before |
| 52 | + public void setUp() { |
| 53 | + ctx = new Context(TextService.class); |
| 54 | + textService = ctx.service(TextService.class); |
| 55 | + } |
| 56 | + |
| 57 | + @After |
| 58 | + public void tearDown() { |
| 59 | + ctx.dispose(); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testGetHandler() { |
| 64 | + final TextFormat fooHandler = textService.getHandler(new File("data.foo")); |
| 65 | + assertNotNull(fooHandler); |
| 66 | + assertEquals(FooTextFormat.class, fooHandler.getClass()); |
| 67 | + System.out.println(fooHandler); |
| 68 | + |
| 69 | + final TextFormat barHandler = textService.getHandler(new File("data.bar")); |
| 70 | + assertNull(barHandler); |
| 71 | + } |
| 72 | + |
| 73 | + @Plugin(type = TextFormat.class) |
| 74 | + public static class FooTextFormat extends AbstractTextFormat { |
| 75 | + |
| 76 | + @Override |
| 77 | + public List<String> getExtensions() { |
| 78 | + return Arrays.asList("foo"); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public String asHTML(final String text) { |
| 83 | + return "[FOO]" + text + "[/FOO]"; |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments