Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elsevier Applicant Challenges - David W Millar #124

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
build/

.gradle/
.idea/

# Package Files #
*.jar

*.log
*.log
21 changes: 21 additions & 0 deletions java/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# http://editorConfig.org
#

root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{groovy,java,gradle}]
indent_style = space
indent_size = 2

[*.md]
indent_size = 4
trim_trailing_whitespace = false

104 changes: 104 additions & 0 deletions java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Created by https://www.gitignore.io/api/java,intellij,gradle

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

.idea

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/sonarlint

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Gradle ###
.gradle
/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

# End of https://www.gitignore.io/api/java,intellij,gradle
59 changes: 58 additions & 1 deletion java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,61 @@ Steps:
Additional Notes:

- Don't spend more than 30 minutes on this assignment
- Use comments to describe why you made particular design decisions
- Use comments to describe why you made particular design decisions


## Millar Notes

* Changelog
* Project Cleanup
* fixed .gitignore so that gradle wrapper artifacts are retained
* using newer gradle plugin syntax
* modified version to comply with [semantic versioning](http://semver.org)
* Ignored failing tests
* made code formatting consistent, and added a .editorconfig file to keep things consistent
* added settings.gradle to avoid creating cruft in the parent directory
* TDD
* added infrastructure for testing solutions with [spock](http://docs.spockframework.org)
* write failing tests (red)
* make tests pass (green), and refactor as necessary (refactor)

### Project Verification

I wrote tests / specs to validate my implementations.
Run them with:

```
# Using the wrapper
$ ./gradlew check

# Using local gradle installation
$ gradle check
```


### Project and Tests

This project's tests should run consistently across operating systems and platforms.
I usually use jenkins, travis, circle, appveyor, or some similar CI tool to verify interoperability.

Please let me know if there are any issues with tests / verification / project setup.


### Time

It took me a bit more than an hour to complete the exercises.

Most of the time was spent "cleaning up" the project, writing tests, and writing this documentation.
See the git logs for more details.


### Contact Info

Applicant: [David W Millar](mailto://[email protected])

Recruiter: [Linda Pham (Jobspring Partners)](mailto://[email protected])





28 changes: 20 additions & 8 deletions java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
plugins {
id 'groovy'
}

sourceCompatibility = 1.8

apply plugin: 'java'
version = '1.0.0'
description = 'elsevier java interview coding problems'
group = 'org.elsevier.education.interview'

sourceCompatibility = 1.8
ext {
junitVersion = '4.12'
spockVersion = '1.0-groovy-2.4'
groovyVersion = '2.4.10'
}

version = '1.0'

repositories {
mavenCentral()
jcenter()
}

dependencies {
testCompile 'junit:junit:4.12'
compile "org.codehaus.groovy:groovy:${groovyVersion}"
testCompile "junit:junit:${junitVersion}"

testCompile "org.spockframework:spock-core:${spockVersion}"
// For mocking interfaces and classes with no default constructor
testRuntime "cglib:cglib-nodep:3.2.4"
testRuntime "org.objenesis:objenesis:2.5.1"
}

task wrapper(type: Wrapper) {
gradleVersion = '3.0'
}
Binary file added java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Thu Oct 27 15:31:42 EDT 2016
#Wed Apr 05 22:03:43 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
19 changes: 11 additions & 8 deletions java/gradlew
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
Expand Down Expand Up @@ -154,16 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save ( ) {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
9 changes: 9 additions & 0 deletions java/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// gradle settings
//
// This prevents gradle from creating cruft in the parent directory
//

rootProject.name = "elsevier-java-interview"


64 changes: 32 additions & 32 deletions java/src/main/java/com/elsevier/education/Exercise1.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package com.elsevier.education;

import java.util.Set;
import java.util.Collections;

/**

TODO: Make this class immutable.
This solution uses unmodifiable collections and removes setters.

It also changes the classes interface, and is built such that a Person needs to be constructed with all fields.

If this is a problem, or if we don't have all the data, but want to add fields outside of the constructor,
then we could add some methods (eg: Person withName('john')) that return a new Person object.

*/
public class Exercise1 {

public static class Person {

private Set<String> phoneNumbers;
private String firstName;
private String lastName;

public Person() {
}

public Set<String> getPhoneNumbers() {
return phoneNumbers;
}
public void setPhoneNumbers(Set<String> newPhoneNumbers) {
phoneNumbers = newPhoneNumbers;
}

public String getFirstName() {
return firstName;
}
public void setFirstName(String newName) {
firstName = newName;
}

public String getLastName() {
return lastName;
}
public void setLastName(String newName) {
lastName = newName;
}
}
}
public static class Person {

private final Set<String> phoneNumbers;
private final String firstName;
private final String lastName;

public Person(final String first, final String last, final Set<String> phones) {
phoneNumbers = Collections.unmodifiableSet(phones);
firstName = first;
lastName = last;
}

public Set<String> getPhoneNumbers() {
return phoneNumbers;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}
}
}
Loading