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
| /** | |
| * sends batch job to a queue for further processing. | |
| * | |
| * @param job | |
| * task that will be serialized and sent to queue | |
| * @return true if job has been successfully queued | |
| */ | |
| public boolean sendJobToWaitQueue(Batch job) { | |
| LOGGER.debug("Trying to push job to queue: " + job.toString()); | |
| String jobJson = batchToJson(job); |
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
| public class ChannelAdapter { | |
| private static final Logger LOGGER = LoggerFactory.getLogger(ChannelAdapter.class); | |
| private final String waitQueue = "TestSample:waitQueue"; | |
| private final String workQueue = "TestSample:workQueue"; | |
| private final JedisPool jedisPool; | |
| /** | |
| * ChannelAdapter in charge of communication with messaging |
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
| private String getMockResponse(String jsonResource){ | |
| String MockResponse = null; | |
| try { | |
| MockResource = Resources.toString(Resources.getResource(jsonResource), Charsets.UTF_8); | |
| }catch(IOException ex){ | |
| ex.printStackTrace(); | |
| } | |
| return MockResponse; | |
| } |
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
| @Test | |
| public void testGetCountOfStudentsWithCourseID() throws IOException { | |
| private String course_id = "CS101"; | |
| when(httpClient.jsonGetCourseDetails(eq(course_id)) | |
| .thenReturn(getMockResponse("./tests/course/course_details.json")); | |
| Integer count = dao.getCountOfStudents(course_id); | |
| Assert.assertEquals(10, count); | |
| } |
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
| private HttpClient httpClient; | |
| @Before | |
| public void setup() { | |
| apiClient = mock(HttpClient.class); | |
| ... | |
| ... | |
| } | |
| @After |
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
| import static org.mockito.Matchers.any; | |
| import static org.mockito.Matchers.eq; | |
| import static org.mockito.Mockito.*; | |
| import com.google.common.io.Resources; | |
| import com.google.common.base.Charsets; |
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
| @Then('^the new current account balance should be "([^"]*)" euros$') | |
| def the_new_current_account_balance_should_be(self, expected_bal): | |
| expected_bal = int(expected_bal) | |
| assert expected_bal >= 0, "Balance cannot be negative" | |
| new_bal = get_balance(account_id) | |
| assert int(new_bal) == expected_bal, "Expected to get %d euros. Instead got %d euros" % (new_bal, expected_bal) |
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
| // Given a list of colours | |
| let elements = [{ id:1, name: 'Blue’, value: ‘#0000FF’}, { id:1, name: 'White’, value: ‘#FFFFFF’}, { id:1, name: 'Red', value: ‘#FF0000’}]; | |
| // Or a promise for a list of colours | |
| let colourPromise = new ColourService().getAll(); // Assume it returns a promise that resolves an array of colours; | |
| function isPromise(obj) { | |
| … // Check if is a promise | |
| } | |
| function getMap(colours) { | |
| if (isPromise(colours) { |
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
| // main.ts | |
| import {jsxFactory} from “jsxFactory” | |
| let div = <div>Hello world from your first component.</div>; | |
| Compiling: tsc –jsx react –reactNamespace jsxFactory –m commons | |
| Results in: | |
| “use strict”; | |
| var jsxFactory_1 = require(“jsxFactory”); | |
| var div = jsxFactory_1. jsxFactory.createElement(“div”, null, “Hello world from your first component.”); |
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
| let list = []; | |
| for (let i = 0; i < 5; i++) { | |
| list.push(() => i); | |
| } | |
| list.forEach(f => console.log(f())); | |
| /**** results | |
| >> 0 | |
| >> 1 | |
| >> 2 |