Skip to content

Commit

Permalink
test: add tests for commons parser (#2487)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthe authored Feb 23, 2024
1 parent 04fdcde commit d4c4c6b
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.streampipes.commons.parser;


import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class BooleanParserTest {

private BooleanParser parser;

@Before
public void setup() {
parser = new BooleanParser();
}

@Test
public void parseTrue() {
assertTrue(parser.parse("true"));
}

@Test
public void parseFalse() {
assertFalse(parser.parse("false"));
}

@Test
public void parseNotABoolean() {
assertFalse(parser.parse("not a boolean"));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.streampipes.commons.parser;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

public class FloatParserTest {
private FloatParser parser;

@Before
public void setup() {
parser = new FloatParser();
}

@Test
public void parseValidFloat() {
assertEquals(123.45f, parser.parse("123.45"), 0.0001);
}

@Test
public void parseInvalidFloat() {
assertThrows(NumberFormatException.class, () -> parser.parse("stringValue"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.streampipes.commons.parser;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

public class IntegerParserTest {
private IntegerParser parser;

@Before
public void setup() {
parser = new IntegerParser();
}

@Test
public void parseValidInteger() {
assertEquals(1, (int) parser.parse("1"));
}

@Test
public void parseInvalidInteger() {
assertThrows(NumberFormatException.class, () -> parser.parse("stringValue"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.streampipes.commons.parser;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class StringParserTest {

@Test
public void testParse() {
StringParser stringParser = new StringParser();

String input = "test string";
assertEquals(input, stringParser.parse(input));
}
}

0 comments on commit d4c4c6b

Please sign in to comment.