forked from I2P_Developers/i2p.i2p
Compare commits
7 Commits
test-conve
...
test-conte
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c4611c0bd | |||
| 44c3d8cc0c | |||
| d888eee6d1 | |||
|
|
ee06171a2f | ||
|
|
335409f1d2 | ||
|
|
d6edb9e96c | ||
| f150855f1c |
24
.gitlab-ci.yml
Normal file
24
.gitlab-ci.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
image: openjdk:8-alpine
|
||||
|
||||
stages:
|
||||
- test
|
||||
|
||||
cache:
|
||||
key: ${CI_COMMIT_REF_SLUG}
|
||||
paths:
|
||||
- $HOME/.gradle/caches/
|
||||
- $HOME/.gradle/wrapper/
|
||||
- .gradle
|
||||
|
||||
test:
|
||||
stage: test
|
||||
coverage: '/Total.*?([0-9]{1,3})%/'
|
||||
before_script:
|
||||
- apk add --no-cache grep
|
||||
script:
|
||||
- ./gradlew codeCoverageReport
|
||||
# The actual output that will be parsed by the code coverage
|
||||
- grep -oP "Total.*?%" build/reports/jacoco/html/index.html
|
||||
only:
|
||||
- merge_requests
|
||||
- tags
|
||||
@@ -60,6 +60,6 @@ public class I2PSocketExceptionTest {
|
||||
public void testUnknownStatus() {
|
||||
I2PSocketException e = new I2PSocketException(255);
|
||||
assertThat(e.getStatus(), is(255));
|
||||
assertThat(e.getMessage(), is("Failure code: 255"));
|
||||
assertThat(e.getMessage(), endsWith(": 255"));
|
||||
}
|
||||
}
|
||||
|
||||
17
core/java/test/junit/net/i2p/TestContext.java
Normal file
17
core/java/test/junit/net/i2p/TestContext.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package net.i2p;
|
||||
|
||||
public class TestContext extends I2PAppContext {
|
||||
|
||||
public TestContext() {
|
||||
TestContext.setGlobalContext(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows overriding the existing I2PAppContext with a test context who's fields we may mock as we like
|
||||
*
|
||||
* @param ctx Our test context to replace the global context with
|
||||
*/
|
||||
public static void setGlobalContext(TestContext ctx){
|
||||
_globalAppContext = ctx;
|
||||
}
|
||||
}
|
||||
51
core/java/test/junit/net/i2p/util/ConvertToHashMockTest.java
Normal file
51
core/java/test/junit/net/i2p/util/ConvertToHashMockTest.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package net.i2p.util;
|
||||
|
||||
import net.i2p.TestContext;
|
||||
import net.i2p.client.naming.NamingService;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.Hash;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ConvertToHashMockTest{
|
||||
|
||||
@Mock private NamingService namingService;
|
||||
@Mock private Destination destination;
|
||||
@Mock private Hash hash;
|
||||
|
||||
@InjectMocks TestContext testContext;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the global context after all tests in the class are done.
|
||||
*
|
||||
* We would otherwise pollute the other tests that depend on I2PAppContext
|
||||
*/
|
||||
@AfterClass
|
||||
public static void afterClass(){
|
||||
TestContext.setGlobalContext(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMockedDestination() {
|
||||
when(namingService.lookup("zzz.i2p")).thenReturn(destination);
|
||||
when(destination.calculateHash()).thenReturn(hash);
|
||||
|
||||
assertSame(hash, ConvertToHash.getHash("zzz.i2p"));
|
||||
|
||||
verify(namingService).lookup("zzz.i2p");
|
||||
verify(destination).calculateHash();
|
||||
}
|
||||
}
|
||||
@@ -81,22 +81,33 @@ public class WorkingDir {
|
||||
String home = System.getProperty("user.home");
|
||||
if (isWindows) {
|
||||
String appdata = System.getenv("LOCALAPPDATA");
|
||||
if (appdata != null)
|
||||
if (appdata != null) {
|
||||
home = appdata;
|
||||
}
|
||||
// Don't mess with existing Roaming Application Data installs,
|
||||
// in case somebody is using roaming appdata for a reason
|
||||
// already. In new installs, use local appdata by default. -idk
|
||||
appdata = System.getenv("APPDATA");
|
||||
if (appdata != null) {
|
||||
File checkOld = new File(appdata, WORKING_DIR_DEFAULT_WINDOWS);
|
||||
if (checkOld.exists() && checkOld.isDirectory())
|
||||
home = appdata;
|
||||
if (checkOld.exists() && checkOld.isDirectory()){
|
||||
File routerConfig = new File(checkOld.getAbsolutePath(), "router.config");
|
||||
// The Firefox profile installer was mistakenly using the Roaming application data
|
||||
// which is synced between devices on some Windows machines using MS cloud services,
|
||||
// instead of the local application data which is used by default.
|
||||
// It would create the router.config file in an empty directory, which the router would
|
||||
// then attempt to use, resulting in a router with no client applications. Checking
|
||||
// for clients.config.d determines if the directory is "Real" or not.
|
||||
File clientAppsConfig = new File(checkOld.getAbsolutePath(), "clients.config.d");
|
||||
if (routerConfig.exists() && clientAppsConfig.exists() && clientAppsConfig.isDirectory())
|
||||
home = appdata;
|
||||
}
|
||||
}
|
||||
dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT_WINDOWS);
|
||||
} else if (SystemVersion.isMac()) {
|
||||
String appdata = "/Library/Application Support/";
|
||||
File old = new File(home,WORKING_DIR_DEFAULT);
|
||||
if (old.exists() && old.isDirectory())
|
||||
File old = new File(home,WORKING_DIR_DEFAULT);
|
||||
if (old.exists() && old.isDirectory())
|
||||
dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT);
|
||||
else {
|
||||
home = home+appdata;
|
||||
|
||||
Reference in New Issue
Block a user