Skip to content
Snippets Groups Projects
Commit 413762b8 authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Added further JUnit tests

parent fa6e5ae0
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net)
*
* 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 teetime.stage;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import teetime.framework.Analysis;
import teetime.framework.AnalysisConfiguration;
import teetime.framework.pipe.IPipeFactory;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
import teetime.stage.CipherByteArray.CipherMode;
/**
* @author Nils Christian Ehmke
*/
public class CipherByteArrayTest {
@Test
public void decryptShouldInvertEncryption() {
final byte[] input = new byte[] { 1, 2, 3, 4, 5 };
final List<byte[]> output = new ArrayList<byte[]>();
final Configuration configuration = new Configuration(input, output);
final Analysis analysis = new Analysis(configuration);
analysis.start();
assertThat(output, contains(input));
}
private class Configuration extends AnalysisConfiguration {
public Configuration(final byte[] input, final List<byte[]> output) {
final IPipeFactory pipeFactory = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false);
final InitialElementProducer<byte[]> producer = new InitialElementProducer<byte[]>(input);
final CipherByteArray encryptStage = new CipherByteArray("somePassword", CipherMode.ENCRYPT);
final CipherByteArray decryptStage = new CipherByteArray("somePassword", CipherMode.DECRYPT);
final CollectorSink<byte[]> sink = new CollectorSink<byte[]>(output);
pipeFactory.create(producer.getOutputPort(), encryptStage.getInputPort());
pipeFactory.create(encryptStage.getOutputPort(), decryptStage.getInputPort());
pipeFactory.create(decryptStage.getOutputPort(), sink.getInputPort());
super.addThreadableStage(producer);
}
}
}
......@@ -34,25 +34,25 @@ public class ToLowerCaseTest {
@Before
public void initializeFilter() {
filter = new ToLowerCase();
this.filter = new ToLowerCase();
}
@Test
public void toLowerCaseShouldWork() {
List<String> results = new ArrayList<String>();
final List<String> results = new ArrayList<String>();
test(filter).and().send("Hello World").to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
test(this.filter).and().send("Hello World").to(this.filter.getInputPort()).and().receive(results).from(this.filter.getOutputPort()).start();
assertThat(results, contains("hello world"));
}
@Test
public void toLowerCaseShouldRemoveNonWordCharacters() {
List<String> results = new ArrayList<String>();
public void toLowerCaseShouldNotRemoveNonWordCharacters() {
final List<String> results = new ArrayList<String>();
test(filter).and().send("Hello 1 2 3 World").to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start();
test(this.filter).and().send("1 2 3").to(this.filter.getInputPort()).and().receive(results).from(this.filter.getOutputPort()).start();
assertThat(results, contains("hello world"));
assertThat(results, contains("1 2 3"));
}
}
/**
* Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net)
*
* 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 teetime.stage.string;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.junit.Assert.assertThat;
import static teetime.framework.test.StageTester.test;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
/**
* @author Nils Christian Ehmke
*/
public class TokenizerTest {
private Tokenizer tokenizer;
@Before
public void initializeTokenizer() {
tokenizer = new Tokenizer(";");
}
@Test
public void tokenizerShouldJustDelaySingleToken() {
List<String> results = new ArrayList<String>();
test(tokenizer).and().send("Hello World").to(tokenizer.getInputPort()).and().receive(results).from(tokenizer.getOutputPort()).start();
assertThat(results, contains("Hello World"));
}
@Test
public void tokenizerShouldSplitMultipleToken() {
List<String> results = new ArrayList<String>();
test(tokenizer).and().send("Hello;World").to(tokenizer.getInputPort()).and().receive(results).from(tokenizer.getOutputPort()).start();
assertThat(results, contains("Hello", "World"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment