Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mageddo.circuitbreaker.failsafe;

import com.mageddo.commons.concurrent.Threads;

import org.junit.jupiter.api.Test;

import testing.templates.solver.remote.FailSafeCircuitBreakerTemplates;

import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -57,7 +59,7 @@ void closedStateWillNotBeAffected() {
}

@Test
void mustIgnoreNulls(){
void mustIgnoreNulls() {
final var refreshed = CircuitStatusRefresh.refresh(null);
assertFalse(refreshed);
}
Expand Down
24 changes: 12 additions & 12 deletions src/test/java/com/mageddo/commons/exec/CommandLinesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class CommandLinesTest {


@Test
void mustValidateWhenExitsWithErrorCode(){
void mustValidateWhenExitsWithErrorCode() {

final var result = CommandLines.exec(
new CommandLine("sh")
.addArgument("-c")
.addArgument("exit 3", false)
new CommandLine("sh")
.addArgument("-c")
.addArgument("exit 3", false)
);

final var ex = assertThrows(ExecutionValidationFailedException.class, result::checkExecution);
Expand All @@ -25,7 +25,7 @@ void mustValidateWhenExitsWithErrorCode(){
}

@Test
void mustExecuteCommand(){
void mustExecuteCommand() {

final var result = CommandLines.exec("echo %s", "hey");

Expand All @@ -37,20 +37,20 @@ void mustExecuteCommand(){
void mustExecuteAndPrintOutputConcurrently() {

final var result = CommandLines.exec(
new CommandLine("sh")
.addArgument("-c")
.addArgument("echo hi && sleep 0.2 && echo hi2", false),
new NopResultHandler()
new CommandLine("sh")
.addArgument("-c")
.addArgument("echo hi && sleep 0.2 && echo hi2", false),
new NopResultHandler()
);

result.printOutToLogsInBackground();

result.waitProcessToFinish();

final var expectedOut = """
hi
hi2
""";
hi
hi2
""";
assertEquals(expectedOut, result.getOutAsString());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.mageddo.commons.exec;

import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

class DelegateOutputStreamTest {
Expand Down
8 changes: 5 additions & 3 deletions src/test/java/com/mageddo/commons/exec/PipedStreamTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.mageddo.commons.exec;

import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

class PipedStreamTest {
Expand All @@ -22,6 +22,8 @@ void mustWriteToOutAndBeAbleToReadWhatIsBeingWritten() throws IOException {
// assert
final var bout = (ByteArrayOutputStream) stream.getOriginalOut();
assertArrayEquals(bytes, bout.toByteArray());
assertArrayEquals(bytes, stream.getPipedIn().readAllBytes());
assertArrayEquals(bytes, stream.getPipedIn()
.readAllBytes()
);
}
}
8 changes: 5 additions & 3 deletions src/test/java/com/mageddo/dns/HostnameTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.mageddo.dns;

import org.junit.jupiter.api.Test;

import testing.templates.HostnameTemplates;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class HostnameTest {

@Test
void mustEndsWith(){
void mustEndsWith() {
final var hostname = Hostname.of(HostnameTemplates.NGINX_COM_BR);
assertTrue(hostname.endsWith(".com.br"));
}

@Test
void mustNotEndsWith(){
void mustNotEndsWith() {
final var hostname = Hostname.of(HostnameTemplates.NGINX_COM_BR);
assertFalse(hostname.endsWith(".com"));
}
Expand Down
15 changes: 8 additions & 7 deletions src/test/java/com/mageddo/dnsproxyserver/AppCompTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void mustCreateTmpDirIfNotExists() {
// arrange
final var args = new String[]{"--create-tmp-dir"};
this.setupStub(args);
doNothing().when(this.app).startContext();
doNothing().when(this.app)
.startContext();

// act
this.app.start();
Expand All @@ -76,12 +77,12 @@ void mustHandleFatalErrors() {
this.setupStub(args);

doThrow(new IllegalAccessError("mocked fatal error"))
.when(this.app)
.checkHiddenCommands()
.when(this.app)
.checkHiddenCommands()
;
doNothing()
.when(this.app)
.exitWithError(anyInt())
.when(this.app)
.exitWithError(anyInt())
;

// act
Expand All @@ -94,8 +95,8 @@ void mustHandleFatalErrors() {
RuntimeException mockExitMethod() {
final var expectedException = new App.SystemExitException("testing");
doThrow(expectedException)
.when(this.app)
.exitGracefully()
.when(this.app)
.exitGracefully()
;
return expectedException;
}
Expand Down
29 changes: 18 additions & 11 deletions src/test/java/com/mageddo/dnsproxyserver/AppIntTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.mageddo.dnsproxyserver;

import java.nio.file.Path;
import java.time.Duration;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;

import com.mageddo.commons.concurrent.Threads;
import com.mageddo.commons.exec.ProcessesWatchDog;
import com.mageddo.dns.utils.Messages;
Expand All @@ -13,21 +18,18 @@
import com.mageddo.dnsproxyserver.utils.Ips;
import com.mageddo.net.IpAddr;
import com.mageddo.utils.Executors;
import lombok.SneakyThrows;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.xbill.DNS.Message;

import lombok.SneakyThrows;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import testing.templates.ConfigFlagArgsTemplates;
import testing.templates.ConfigJsonFileTemplates;

import java.nio.file.Path;
import java.time.Duration;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -43,7 +45,8 @@ void beforeEach() {
@AfterAll
static void afterAll() {
Starter.setMustStartFlagActive(false);
ProcessesWatchDog.instance().killAllProcesses();
ProcessesWatchDog.instance()
.killAllProcesses();
}

@Test
Expand Down Expand Up @@ -88,11 +91,15 @@ void mustQueryRemoteSolverPassingThroughAllModulesAndGetSuccess() {

private static App buildClientAppAndWait(ExecutorService executor, Integer serverPort) {
final var remoteAddr = IpAddr.of("127.0.0.1", serverPort);
return buildAppAndWait(executor, ConfigFlagArgsTemplates.withRandomPortsAndNotAsDefaultDnsUsingRemote(remoteAddr));
return buildAppAndWait(executor,
ConfigFlagArgsTemplates.withRandomPortsAndNotAsDefaultDnsUsingRemote(remoteAddr)
);
}

private static Result buildAndStartServerApp(String hostToQuery) {
final var configFile = ConfigJsonFileTemplates.withRandomPortsAndNotAsDefaultDnsAndCustomLocalDBEntry(hostToQuery);
final var configFile =
ConfigJsonFileTemplates.withRandomPortsAndNotAsDefaultDnsAndCustomLocalDBEntry(
hostToQuery);
final var instance = Sandbox.runFromGradleTests(configFile);
return Result.of(configFile, instance);
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/com/mageddo/dnsproxyserver/AppSettingsTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.mageddo.dnsproxyserver;

import com.mageddo.dnsproxyserver.application.LogSettings;
import testing.templates.ConfigTemplates;
import com.mageddo.logback.LogbackUtils;

import org.junit.jupiter.api.Test;

import testing.templates.ConfigTemplates;

import static org.junit.jupiter.api.Assertions.assertEquals;

class AppSettingsTest {
@Test
void mustLogLevelInSl4jConversion(){
void mustLogLevelInSl4jConversion() {
// arrange
final var config = ConfigTemplates.defaultWithoutId();

Expand Down
14 changes: 7 additions & 7 deletions src/test/java/com/mageddo/dnsproxyserver/config/ConfigsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ void mustGenerateEnvHostnameIdWhenIsNull() {
// act
final var env = EnvTemplates.buildWithoutId();
final var firstEntry = env
.getEntries()
.stream()
.findFirst()
.get();
.getEntries()
.stream()
.findFirst()
.get();

// assert
assertNotNull(firstEntry.getId());
final var currentNanoTime = System.nanoTime();
assertTrue(
firstEntry.getId() < currentNanoTime,
String.format("id=%s, currentTimeInMillis=%s", firstEntry.getId(), currentNanoTime)
firstEntry.getId() < currentNanoTime,
String.format("id=%s, currentTimeInMillis=%s", firstEntry.getId(), currentNanoTime)
);
}

@Test
void mustCreateDefaultConfigFileOnRandomPathWhenTesting(){
void mustCreateDefaultConfigFileOnRandomPathWhenTesting() {

final var config = Configs.getInstance();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.mageddo.dnsproxyserver.config.application;

import java.nio.file.Paths;

import com.mageddo.dnsproxyserver.config.dataformat.v2.cmdargs.ConfigDAOCmdArgs;
import com.mageddo.dnsproxyserver.config.dataformat.v2.legacyenv.ConfigDAOLegacyEnv;

import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;

import testing.templates.ConfigFlagTemplates;
import testing.templates.config.ConfigEnvTemplates;

import java.nio.file.Paths;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doReturn;
Expand All @@ -35,13 +37,13 @@ class ConfigFileFinderServiceTest {
void mustUseEnvConfig() {
// arrange
doReturn(ConfigEnvTemplates.withConfigFilePath())
.when(this.configDAOEnv)
.findRaw()
.when(this.configDAOEnv)
.findRaw()
;

doReturn(ConfigFlagTemplates.withConfigFilePath())
.when(this.configDAOCmdArgs)
.findRaw()
.when(this.configDAOCmdArgs)
.findRaw()
;

// act
Expand All @@ -56,13 +58,13 @@ void mustUseEnvConfig() {
void mustUseArgsConfigWhenEnvNotSet() {
// arrange
doReturn(ConfigEnvTemplates.empty())
.when(this.configDAOEnv)
.findRaw()
.when(this.configDAOEnv)
.findRaw()
;

doReturn(ConfigFlagTemplates.withConfigFilePath())
.when(this.configDAOCmdArgs)
.findRaw()
.when(this.configDAOCmdArgs)
.findRaw()
;

// act
Expand All @@ -78,13 +80,13 @@ void mustUseArgsConfigWhenEnvNotSet() {
void mustUseRandomGeneratedConfigPathWhenRunningInTestsAndNoCustomPathIsSpecified() {
// arrange
doReturn(ConfigEnvTemplates.empty())
.when(this.configDAOEnv)
.findRaw()
.when(this.configDAOEnv)
.findRaw()
;

doReturn(ConfigFlagTemplates.empty())
.when(this.configDAOCmdArgs)
.findRaw()
.when(this.configDAOCmdArgs)
.findRaw()
;

// act
Expand Down
Loading