AvailableTypeDetector { public boolean isAvailableType(String typeName, Configuration config) { if (typeName == null) { return false; } boolean isTypeAvailable = false; String[] packageArr = typeName.split("\\."); String packageName = null; if (packageArr.length > 1) { packageName = typeName.replaceFirst("\\.[^\\.]+$", StringValue.Empty); } for (String imported : classMeta.importedList) { if (packageName != null && imported.equals(typeName)) { return true; } else if (imported.matches(".+\\." + typeName + "$")) { return true; } } try { Class.forName("java.lang." + typeName); isTypeAvailable = true; } catch (Exception ignore) { if (config != null && packageName != null) { String searchPath = config.directoryPathOfProductSourceCode + "/" + packageName.replaceAll("\\.", "/"); try { List<File> files = FileSearcherFactory.create().searchFilesRecursivelyByName(searchPath, typeName + RegExp.FileExtension.JavaFile); if (files != null && files.size() > 0) { isTypeAvailable = true; } } catch (Exception e) { Stderr.p(e.getLocalizedMessage() + " - " + searchPath); } } } return isTypeAvailable; } AvailableTypeDetector(ClassMeta classMeta); boolean isPrimitive(String typeName); boolean isArray(String typeName); boolean isJavaLangPackageType(String typeName); boolean isAvailableType(String typeName, Configuration config); boolean isJMockitMockableType(String typeName);  }
@Test public void isAvailableType_A$String$Configuration_true() throws Exception { ClassMeta classMeta = new ClassMeta(); AvailableTypeDetector target = new AvailableTypeDetector(classMeta); String typeName = "String"; Configuration config = new Configuration(); boolean actual = target.isAvailableType(typeName, config); boolean expected = true; assertEquals(expected, actual); }
@Test public void isAvailableType_A$String$Configuration_false() throws Exception { ClassMeta classMeta = new ClassMeta(); AvailableTypeDetector target = new AvailableTypeDetector(classMeta); String typeName = "org.juithelper.core.Version"; Configuration config = new Configuration(); boolean actual = target.isAvailableType(typeName, config); boolean expected = false; assertEquals(expected, actual); }
@Test public void isAvailableType_A$String$Configuration_StringIsNull() throws Exception { ClassMeta classMeta = null; AvailableTypeDetector target = new AvailableTypeDetector(classMeta); String typeName = null; Configuration config = null; boolean actual = target.isAvailableType(typeName, config); boolean expected = false; assertThat(actual, is(equalTo(expected))); }
@Test public void isAvailableType_A$String$Configuration_StringIsEmpty() throws Exception { ClassMeta classMeta = new ClassMeta(); AvailableTypeDetector target = new AvailableTypeDetector(classMeta); String typeName = ""; Configuration config = null; boolean actual = target.isAvailableType(typeName, config); boolean expected = false; assertThat(actual, is(equalTo(expected))); }