|
| 1 | +/* |
| 2 | + * Copyright 2023 Fabian Steeg, hbz |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 the "License"; |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.metafacture.metafix; |
| 18 | + |
| 19 | +import org.metafacture.framework.ObjectReceiver; |
| 20 | + |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 23 | +import org.mockito.InOrder; |
| 24 | +import org.mockito.Mock; |
| 25 | +import org.mockito.Mockito; |
| 26 | +import org.mockito.exceptions.base.MockitoAssertionError; |
| 27 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 28 | + |
| 29 | +/** |
| 30 | + * Tests for class {@link FindFixPaths}. |
| 31 | + * |
| 32 | + * @author Fabian Steeg |
| 33 | + * |
| 34 | + */ |
| 35 | +@ExtendWith(MockitoExtension.class) |
| 36 | +public final class FindFixPathsTest { |
| 37 | + |
| 38 | + private final FindFixPaths finder = new FindFixPaths(".*ETL.*"); |
| 39 | + |
| 40 | + @Mock |
| 41 | + private ObjectReceiver<String> receiver; |
| 42 | + |
| 43 | + public FindFixPathsTest() { |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void testShouldFindPaths() { |
| 48 | + verify( |
| 49 | + "a\\t|\\tAn ETL test", |
| 50 | + "c.2\\t|\\tETL what?"); |
| 51 | + } |
| 52 | + |
| 53 | + private void processRecord() { |
| 54 | + finder.setReceiver(receiver); |
| 55 | + finder.startRecord(""); |
| 56 | + finder.literal("a", "An ETL test"); |
| 57 | + finder.literal("b", ""); |
| 58 | + finder.literal("b", "Dummi"); |
| 59 | + finder.literal("b", "Dog"); |
| 60 | + finder.literal("c", ""); |
| 61 | + finder.literal("c", "ETL what?"); |
| 62 | + finder.endRecord(); |
| 63 | + finder.closeStream(); |
| 64 | + } |
| 65 | + |
| 66 | + private void verify(final String... result) throws MockitoAssertionError { |
| 67 | + processRecord(); |
| 68 | + try { |
| 69 | + final InOrder ordered = Mockito.inOrder(receiver); |
| 70 | + for (final String r : result) { |
| 71 | + ordered.verify(receiver).process(r); |
| 72 | + } |
| 73 | + ordered.verify(receiver, Mockito.times(2)).closeStream(); |
| 74 | + ordered.verifyNoMoreInteractions(); |
| 75 | + Mockito.verifyNoMoreInteractions(receiver); |
| 76 | + } |
| 77 | + catch (final MockitoAssertionError e) { |
| 78 | + System.out.println(Mockito.mockingDetails(receiver).printInvocations()); |
| 79 | + throw e; |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | +} |
0 commit comments