Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a QueryParams builder to allow for any combination of parameter…
…s to be supplied
- Loading branch information
1 parent
1856fce
commit 119c44f
Showing
2 changed files
with
96 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.ecwid.consul.v1; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
import static com.ecwid.consul.v1.QueryParams.Builder; | ||
|
||
public class QueryParamsTest { | ||
@Test | ||
public void queryParamsBuilder_ShouldReturnAllDefaults_WhenNoValuesAdded() { | ||
final ConsistencyMode EXPECTED_MODE = ConsistencyMode.DEFAULT; | ||
final long EXPECTED_INDEX = -1; | ||
final long EXPECTED_WAIT_TIME = -1; | ||
|
||
Builder builder = Builder.builder(); | ||
|
||
QueryParams actual = builder.build(); | ||
|
||
assertNull(actual.getDatacenter()); | ||
assertEquals(actual.getConsistencyMode(), EXPECTED_MODE); | ||
assertEquals(actual.getWaitTime(), EXPECTED_WAIT_TIME); | ||
assertEquals(actual.getIndex(), EXPECTED_INDEX); | ||
} | ||
|
||
@Test | ||
public void queryParamsBuilder_ShouldReturnQueryParams_WithCorrectValuesApplied() { | ||
final String EXPECTED_DATACENTER = "testDC"; | ||
final ConsistencyMode EXPECTED_MODE = ConsistencyMode.CONSISTENT; | ||
final long EXPECTED_INDEX = 100; | ||
final long EXPECTED_WAIT_TIME = 10000; | ||
|
||
Builder builder = Builder.builder(); | ||
QueryParams actual = builder.setDatacenter(EXPECTED_DATACENTER) | ||
.setConsistencyMode(EXPECTED_MODE) | ||
.setWaitTime(EXPECTED_WAIT_TIME) | ||
.setIndex(EXPECTED_INDEX) | ||
.build(); | ||
|
||
assertEquals(actual.getDatacenter(), EXPECTED_DATACENTER); | ||
assertEquals(actual.getConsistencyMode(), EXPECTED_MODE); | ||
assertEquals(actual.getIndex(), EXPECTED_INDEX); | ||
assertEquals(actual.getWaitTime(), EXPECTED_WAIT_TIME); | ||
} | ||
} |