<commit_before>/*
 *  Copyright 2013 Deutsche Nationalbibliothek
 *
 *  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.culturegraph.mf.stream.pipe;

import org.culturegraph.mf.stream.pipe.ObjectBuffer;
import org.culturegraph.mf.stream.pipe.StringFilter;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;


/**
 * @author <NAME>
 *
 */
public final class StringFilterTest {

	private static final String[] RECORDS = { "Record 1: Data", "Record 42: Data", "Record 3: Data" };
	private static final String PATTERN = "\\d\\d";
	
	private StringFilter filter;
	private ObjectBuffer<String> buffer;

	@Before
	public void configFlow() {
		filter = new StringFilter(PATTERN);
		buffer = new ObjectBuffer<String>();
		filter.setReceiver(buffer);		
	}
	
	@Test
	public void testPassMatches() {
		filter.setPassMatches(true);
		
		processRecords();
		
		Assert.assertEquals(RECORDS[1], buffer.pop());
		Assert.assertNull(buffer.pop());
	}
	
	@Test
	public void testFilterMatches() {
		filter.setPassMatches(false);
		
		processRecords();		

		Assert.assertEquals(RECORDS[0], buffer.pop());
		Assert.assertEquals(RECORDS[2], buffer.pop());
		Assert.assertNull(buffer.pop());
}

	private void processRecords() {
		filter.process(RECORDS[0]);
		filter.process(RECORDS[1]);
		filter.process(RECORDS[2]);
		filter.closeStream();		
	}
}
<commit_msg>Changed StringFilterTest to use mock objects.<commit_after>/*
 *  Copyright 2013 Deutsche Nationalbibliothek
 *
 *  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.culturegraph.mf.stream.pipe;

import static org.mockito.Mockito.inOrder;

import org.culturegraph.mf.framework.ObjectReceiver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;


/**
 * Tests for {@link StringFilter}.
 * 
 * @author <NAME>
 *
 */
public final class StringFilterTest {

	private static final String[] RECORDS = { 
		"Record 1: Data", 
		"Record 42: Data", 
		"Record 3: Data",
	};
	
	private static final String PATTERN = "\\d\\d";
	
	private StringFilter filter;
	
	@Mock
	private ObjectReceiver<String> receiver;

	@Before
	public void setup() {
		MockitoAnnotations.initMocks(this);
		
		filter = new StringFilter(PATTERN);
		filter.setReceiver(receiver);		
	}
	
	@After
	public void cleanup() {
		filter.closeStream();
	}
	
	@Test
	public void testShouldPassMatchingInput() {
		filter.setPassMatches(true);
		
		filter.process(RECORDS[0]);
		filter.process(RECORDS[1]);
		filter.process(RECORDS[2]);
		
		final InOrder ordered = inOrder(receiver);
		ordered.verify(receiver).process(RECORDS[1]);
		ordered.verifyNoMoreInteractions();
	}
	
	@Test
	public void testShouldPassNonMatchingInput() {
		filter.setPassMatches(false);
		
		filter.process(RECORDS[0]);
		filter.process(RECORDS[1]);
		filter.process(RECORDS[2]);

		final InOrder ordered = inOrder(receiver);
		ordered.verify(receiver).process(RECORDS[0]);
		ordered.verify(receiver).process(RECORDS[2]);
		ordered.verifyNoMoreInteractions();
	}
	
}

{'fraction_non_alphanumeric': 0.1115604186489058, 'fraction_numerical': 0.009276879162702189, 'mean_word_length': 3.811212814645309, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6721029', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1262, 'n_words': 352}