-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust FindFixPaths.java and add test #347
- Loading branch information
Showing
2 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
metafix/src/test/java/org/metafacture/metafix/FindFixPathsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2023 Fabian Steeg, hbz | ||
* | ||
* Licensed under the Apache License, Version 2.0 the "License"; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.metafacture.metafix; | ||
|
||
import org.metafacture.framework.ObjectReceiver; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InOrder; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.exceptions.base.MockitoAssertionError; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
/** | ||
* Tests for class {@link FindFixPaths}. | ||
* | ||
* @author Fabian Steeg | ||
* | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
public final class FindFixPathsTest { | ||
|
||
private final FindFixPaths finder = new FindFixPaths(".*ETL.*"); | ||
|
||
@Mock | ||
private ObjectReceiver<String> receiver; | ||
|
||
public FindFixPathsTest() { | ||
} | ||
|
||
@Test | ||
public void testShouldFindPaths() { | ||
verify( | ||
"a\\t|\\tAn ETL test", | ||
"c.2\\t|\\tETL what?"); | ||
} | ||
|
||
private void processRecord() { | ||
finder.setReceiver(receiver); | ||
finder.startRecord(""); | ||
finder.literal("a", "An ETL test"); | ||
finder.literal("b", ""); | ||
finder.literal("b", "Dummi"); | ||
finder.literal("b", "Dog"); | ||
finder.literal("c", ""); | ||
finder.literal("c", "ETL what?"); | ||
finder.endRecord(); | ||
finder.closeStream(); | ||
} | ||
|
||
private void verify(final String... result) throws MockitoAssertionError { | ||
processRecord(); | ||
try { | ||
final InOrder ordered = Mockito.inOrder(receiver); | ||
for (final String r : result) { | ||
ordered.verify(receiver).process(r); | ||
} | ||
ordered.verify(receiver, Mockito.times(2)).closeStream(); | ||
ordered.verifyNoMoreInteractions(); | ||
Mockito.verifyNoMoreInteractions(receiver); | ||
} | ||
catch (final MockitoAssertionError e) { | ||
System.out.println(Mockito.mockingDetails(receiver).printInvocations()); | ||
throw e; | ||
} | ||
} | ||
|
||
} |