blob: 10c0065b094090e38c03aba5e3438eab84babde1 [file] [log] [blame]
/*
* 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.netbeans.modules.php.apigen.annotations.parser;
import java.util.Collections;
import java.util.Map;
import org.netbeans.junit.NbTestCase;
import org.netbeans.modules.csl.api.OffsetRange;
import org.netbeans.modules.php.spi.annotation.AnnotationParsedLine;
/**
*
* @author Ondrej Brejla <obrejla@netbeans.org>
*/
public class ThrowsLineParserTest extends NbTestCase {
private ThrowsLineParser parser;
public ThrowsLineParserTest(String name) {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
parser = new ThrowsLineParser();
}
public void testValidUseCase_01() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("throws Exception");
assertEquals("throws", parsedLine.getName());
assertEquals("Exception", parsedLine.getDescription());
Map<OffsetRange, String> types = parsedLine.getTypes();
assertNotNull(types);
assertEquals(1, types.size());
for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
OffsetRange offsetRange = entry.getKey();
String typeName = entry.getValue();
assertEquals(7, offsetRange.getStart());
assertEquals(16, offsetRange.getEnd());
assertEquals("Exception", typeName);
}
}
public void testValidUseCase_02() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("throws ");
assertEquals("throws", parsedLine.getName());
assertEquals("", parsedLine.getDescription());
assertEquals(Collections.EMPTY_MAP, parsedLine.getTypes());
}
public void testValidUseCase_03() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("throws\t");
assertEquals("throws", parsedLine.getName());
assertEquals("", parsedLine.getDescription());
assertEquals(Collections.EMPTY_MAP, parsedLine.getTypes());
}
public void testValidUseCase_04() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("throws\tException");
assertEquals("throws", parsedLine.getName());
assertEquals("Exception", parsedLine.getDescription());
Map<OffsetRange, String> types = parsedLine.getTypes();
assertNotNull(types);
assertEquals(1, types.size());
for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
OffsetRange offsetRange = entry.getKey();
String typeName = entry.getValue();
assertEquals(7, offsetRange.getStart());
assertEquals(16, offsetRange.getEnd());
assertEquals("Exception", typeName);
}
}
public void testValidUseCase_05() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("throws Exception ");
assertEquals("throws", parsedLine.getName());
assertEquals("Exception", parsedLine.getDescription());
Map<OffsetRange, String> types = parsedLine.getTypes();
assertNotNull(types);
assertEquals(1, types.size());
for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
OffsetRange offsetRange = entry.getKey();
String typeName = entry.getValue();
assertEquals(17, offsetRange.getStart());
assertEquals(26, offsetRange.getEnd());
assertEquals("Exception", typeName);
}
}
public void testValidUseCase_06() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("throws\t \tException \t ");
assertEquals("throws", parsedLine.getName());
assertEquals("Exception", parsedLine.getDescription());
Map<OffsetRange, String> types = parsedLine.getTypes();
assertNotNull(types);
assertEquals(1, types.size());
for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
OffsetRange offsetRange = entry.getKey();
String typeName = entry.getValue();
assertEquals(12, offsetRange.getStart());
assertEquals(21, offsetRange.getEnd());
assertEquals("Exception", typeName);
}
}
public void testValidUseCase_07() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("throws\t\\My\\Cool\\Exception");
assertEquals("throws", parsedLine.getName());
assertEquals("\\My\\Cool\\Exception", parsedLine.getDescription());
Map<OffsetRange, String> types = parsedLine.getTypes();
assertNotNull(types);
assertEquals(1, types.size());
for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
OffsetRange offsetRange = entry.getKey();
String typeName = entry.getValue();
assertEquals(7, offsetRange.getStart());
assertEquals(25, offsetRange.getEnd());
assertEquals("\\My\\Cool\\Exception", typeName);
}
}
public void testValidUseCase_08() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("throws\tMy\\Cool\\Exception");
assertEquals("throws", parsedLine.getName());
assertEquals("My\\Cool\\Exception", parsedLine.getDescription());
Map<OffsetRange, String> types = parsedLine.getTypes();
assertNotNull(types);
assertEquals(1, types.size());
for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
OffsetRange offsetRange = entry.getKey();
String typeName = entry.getValue();
assertEquals(7, offsetRange.getStart());
assertEquals(24, offsetRange.getEnd());
assertEquals("My\\Cool\\Exception", typeName);
}
}
public void testInvalidUseCase_01() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("@throws Exception");
assertNull(parsedLine);
}
public void testInvalidUseCase_02() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("foo Exception");
assertNull(parsedLine);
}
public void testInvalidUseCase_03() throws Exception {
AnnotationParsedLine parsedLine = parser.parse("throw Exception");
assertNull(parsedLine);
}
}