Код: Выделить всё
public boolean isSelfServicePortalServerAvailable(String crmEndPoint) {
boolean isServerAvailable = false;
URL url = null;
HttpURLConnection connection = null;
try {
url = new URL(crmEndPoint);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
isServerAvailable = true;
connection.disconnect();
} catch (MalformedURLException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
return isServerAvailable;
}
Код: Выделить всё
@Mock
private URL mockUrl;
@Mock
private HttpURLConnection mockConnection;
@Mock
private ISelfServiceDao selfServiceDao;
@Mock
private RestTemplate restTemplate;
@InjectMocks
private SelfServiceCoreClaimImpl selfServiceCoreClaimImpl = new SelfServiceCoreClaimImpl(restTemplate);
@Test
public void testIsSelfServicePortalServerAvailable_Success() throws IOException {
when(mockUrl.openConnection()).thenReturn(mockConnection);
doNothing().when(mockConnection).connect();
doNothing().when(mockConnection).disconnect();
boolean result = selfServiceCoreClaimImpl.isSelfServicePortalServerAvailable("http://test-url.com");
assertTrue(result);
}
Обнаружены ненужные заглушки.
Чистый и поддерживаемый тестовый код не требует никакого ненужного кода .
Следующие заглушки не нужны (нажмите, чтобы перейти к соответствующей строке кода):
- -> at com .acentra.ssp.impl.SelfServiceCoreClaimImplTest.testIsSelfServicePortalServerAvailable_Success(SelfServiceCoreClaimImplTest.java:71)
- -> на com.acentra.ssp.impl.SelfServiceCoreClaimImplTest.testIsSelfServicePortalServerAvailable_Success(SelfServiceCo) reClaimImplTest.java:72)< /li>
-> на com.impl.SelfServiceCoreClaimImplTest.testIsSelfServicePortalServerAvailable_Success(SelfServiceCoreClaimImplTest.java:73)
Удалите ненужные заглушки. Дополнительная информация: javadoc для класса UnnecessaryStublingException.
на org. ockito.junit.jupiter.MockitoExtension.afterEach(MockitoExtension.java:192)
в java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
в java.base/java. util.ArrayList.forEach(ArrayList.java:1511)
Подробнее здесь: https://stackoverflow.com/questions/790 ... connection
Мобильная версия