### Question:
JavaParserTypeParsingService implements TypeParsingService { @Override public ClassOrInterfaceTypeDetails getTypeFromString(final String fileContents, final String declaredByMetadataId, final JavaType typeName) { if (StringUtils.isBlank(fileContents)) { return null; } Validate.notBlank(declaredByMetadataId, "Declaring metadata ID required"); Validate.notNull(typeName, "Java type to locate required"); try { final CompilationUnit compilationUnit = JavaParser.parse(new ByteArrayInputStream(fileContents.getBytes())); final TypeDeclaration typeDeclaration = JavaParserUtils.locateTypeDeclaration(compilationUnit, typeName); if (typeDeclaration == null) { return null; } return JavaParserClassOrInterfaceTypeDetailsBuilder.getInstance(compilationUnit, null, typeDeclaration, declaredByMetadataId, typeName, metadataService, typeLocationService) .build(); } catch (final IOException e) { throw new IllegalStateException(e); } catch (final ParseException e) { throw new IllegalStateException("Failed to parse " + typeName + " : " + e.getMessage()); } }  @Override final String getCompilationUnitContents(final ClassOrInterfaceTypeDetails cid); @Override ClassOrInterfaceTypeDetails getTypeAtLocation(final String fileIdentifier,
      final String declaredByMetadataId, final JavaType typeName); @Override ClassOrInterfaceTypeDetails getTypeFromString(final String fileContents,
      final String declaredByMetadataId, final JavaType typeName); @Override String updateAndGetCompilationUnitContents(final String fileIdentifier,
      final ClassOrInterfaceTypeDetails cid);  }### Answer:
@Test public void testGetTypeFromStringWhenFileContainsNoSuchType() { final JavaType mockTargetType = mock(JavaType.class); when(mockTargetType.getSimpleTypeName()).thenReturn("NoSuchType"); final ClassOrInterfaceTypeDetails locatedType = typeParsingService.getTypeFromString(SOURCE_FILE, DECLARED_BY_MID, mockTargetType); assertNull(locatedType); }
@Test public void testGetTypeFromStringWhenFileContainsNoTypes() { final JavaType mockTargetType = mock(JavaType.class); final ClassOrInterfaceTypeDetails locatedType = typeParsingService.getTypeFromString(EMPTY_FILE, DECLARED_BY_MID, mockTargetType); assertNull(locatedType); }