### Question:
AnnotationDataLocationExtractor { public String extractLocation(DocAnnotationData data) { if (data==null) { return ""; } Method method = data.linkedMethod; if (method!=null) { return createMethodIdentifier(method); } Field field = data.linkedField; if (field!=null) { return createFieldIdentifier(field); } Class<?> clazz = data.linkedClass; if (clazz!=null) { return createClassIdentifier(clazz); } return ""; }  String extractLocation(DocAnnotationData data);  }### Answer:
@Test public void null_results_in_empty_string() throws Exception { String result = extractorToTest.extractLocation(null); assertEquals("", result); }
@Test public void empty_data_results_in_empty_string() throws Exception { DocAnnotationData data = new DocAnnotationData(); String result = extractorToTest.extractLocation(data); assertEquals("", result); }
@Test public void data_with_field_results_in_correct_string() throws Exception { DocAnnotationData data = new DocAnnotationData(); data.linkedField=getClass().getDeclaredField("extractorToTest"); String result = extractorToTest.extractLocation(data); assertEquals("Field:AnnotationDataLocationExtractorTest.extractorToTest", result); }
@Test public void data_with_method_results_in_correct_string() throws Exception { DocAnnotationData data = new DocAnnotationData(); data.linkedMethod=getClass().getMethod("data_with_method_results_in_correct_string"); String result = extractorToTest.extractLocation(data); assertEquals("Method:AnnotationDataLocationExtractorTest#data_with_method_results_in_correct_string", result); }
@Test public void data_with_class_results_in_correct_string() throws Exception { DocAnnotationData data = new DocAnnotationData(); data.linkedClass=AnnotationDataLocationExtractorTest.class; String result = extractorToTest.extractLocation(data); assertEquals("Class:AnnotationDataLocationExtractorTest", result); }