This file contains hidden or 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
pipeline { | |
agent none | |
stages { | |
stage('maven_3_jdk_13') { | |
agent { | |
docker { | |
image 'maven:3-jdk-13' | |
label 'slave-1' | |
} | |
} |
This file contains hidden or 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
// Functional programming approach to parsing query strings in Typescript/ES6. | |
function parseQueryString(search: string) { | |
return (search.startsWith('?') ? search.substring(1) : search) | |
.split('&') | |
.map(str => { | |
const eqIdx = str.indexOf('='); | |
if (eqIdx <= 0 || eqIdx >= str.length - 1) { | |
return {}; | |
} |
This file contains hidden or 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
class AddressVerifier { | |
private MapsClient mapsClient; | |
public AddressVerifier(MapsClient mapsClient) { | |
this.mapsClient = mapsClient; | |
} | |
public boolean isVerified(String address) { | |
return mapsClient.isVerified(address); | |
} |
This file contains hidden or 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
// Now we can have multiple implementations of MapClient interface. | |
class GoogleMapsClientImpl implements MapsClient { | |
private GoogleMapsClient googleMapsClient; | |
public GoogleMapsClientImpl(GoogleMapsClient client) { | |
googleMapsClient = client; | |
} | |
@Override |
This file contains hidden or 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
interface MapsClient { | |
public boolean isVerified(); | |
} |
This file contains hidden or 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
class AddressVerifierTest { | |
@Test public void basicTest() { | |
// We can use a mocking framework to mock the implementation. | |
GoogleMapsClient mockMapsClient = mock(GoogleMapsClient.class); | |
when(mockMapsClient.verifyAddress(SOME_INVALID_TEST_ADDRESS)).return(Result.FAILED); | |
when(mockMapsClient.verifyAddress(SOME_VALID_TEST_ADDRESS)).return(Result.SUCCESS); | |
AddressVerifier verifier = new AddressVerifier(mockMapsClient); | |
assertThat(verifier.isVerified(SOME_INVALID_TEST_ADDRESS)).isFalse(); | |
assertThat(verifier.isVerified(SOME_VALID_TEST_ADDRESS)).isTrue(); | |
// WOOOHOOO! OUR TESTS ARE NOW FULLY INDEPENDENT OF GOOGLE MAPS CLIENT! WE TEST OUR OWN CODE, NOT THEIRS! |
This file contains hidden or 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
class AddressVerifier { | |
private GoogleMapsClient googleMapsClient; | |
public AddressVerifier(GoogleMapsClient googleMapsClient) { | |
this.googleMapsClient = googleMapsClient; | |
} | |
public boolean isVerified(String address) { | |
Result verificationResult = googleMapsClient.verifyAddress(address).result; | |
return verificationResult == Result.SUCCESS; | |
} |
This file contains hidden or 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
class AddressVerifierTest { | |
@Test public void basicTest() { | |
AddressVerifier verifier = new AddressVerifier(); | |
assertThat(verifer.isVerified(SOME_INVALID_TEST_ADDRESS)).isFalse(); | |
assertThat(verifer.isVerified(SOME_VALID_TEST_ADDRESS)).isTrue(); | |
} | |
} |
This file contains hidden or 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
class AddressVerifier { | |
private GoogleMapsClient googleMapsClient; | |
public AddressVerifier() { | |
googleMapsClient = new GoogleMapsClient(); | |
} | |
public boolean isVerified(String address) { | |
Result verificationResult = googleMapsClient.verifyAddress(address).result; | |
return verificationResult == Result.SUCCESS; | |
} |