Created
June 12, 2016 13:56
-
-
Save aziaziazi/6fdbaae23309acca1ef3bb45b39ecdd7 to your computer and use it in GitHub Desktop.
First Java program! Learnign with Vincent.
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="CompilerConfiguration"> | |
<resourceExtensions /> | |
<wildcardResourcePatterns> | |
<entry name="!?*.java" /> | |
<entry name="!?*.form" /> | |
<entry name="!?*.class" /> | |
<entry name="!?*.groovy" /> | |
<entry name="!?*.scala" /> | |
<entry name="!?*.flex" /> | |
<entry name="!?*.kt" /> | |
<entry name="!?*.clj" /> | |
<entry name="!?*.aj" /> | |
</wildcardResourcePatterns> | |
<annotationProcessing> | |
<profile default="true" name="Default" enabled="false"> | |
<processorPath useClasspath="true" /> | |
</profile> | |
<profile default="false" name="Maven default annotation processors profile" enabled="true"> | |
<sourceOutputDir name="target/generated-sources/annotations" /> | |
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> | |
<outputRelativeToContentRoot value="true" /> | |
<processorPath useClasspath="true" /> | |
<module name="ValidateExercise1Maven" /> | |
</profile> | |
</annotationProcessing> | |
<bytecodeTargetLevel> | |
<module name="ValidateExercise1Maven" target="1.8" /> | |
</bytecodeTargetLevel> | |
</component> | |
</project> |
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
<component name="CopyrightManager"> | |
<settings default="" /> | |
</component> |
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
<component name="libraryTable"> | |
<library name="Maven: junit:junit:4.12"> | |
<CLASSES> | |
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" /> | |
</CLASSES> | |
<JAVADOC> | |
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" /> | |
</JAVADOC> | |
<SOURCES> | |
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" /> | |
</SOURCES> | |
</library> | |
</component> |
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
<component name="libraryTable"> | |
<library name="Maven: org.hamcrest:hamcrest-core:1.3"> | |
<CLASSES> | |
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" /> | |
</CLASSES> | |
<JAVADOC> | |
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" /> | |
</JAVADOC> | |
<SOURCES> | |
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" /> | |
</SOURCES> | |
</library> | |
</component> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="EntryPointsManager"> | |
<entry_points version="2.0" /> | |
</component> | |
<component name="MavenProjectsManager"> | |
<option name="originalFiles"> | |
<list> | |
<option value="$PROJECT_DIR$/pom.xml" /> | |
</list> | |
</option> | |
</component> | |
<component name="ProjectLevelVcsManager" settingsEditedManually="false"> | |
<OptionsSetting value="true" id="Add" /> | |
<OptionsSetting value="true" id="Remove" /> | |
<OptionsSetting value="true" id="Checkout" /> | |
<OptionsSetting value="true" id="Update" /> | |
<OptionsSetting value="true" id="Status" /> | |
<OptionsSetting value="true" id="Edit" /> | |
<ConfirmationsSetting value="0" id="Add" /> | |
<ConfirmationsSetting value="0" id="Remove" /> | |
</component> | |
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |
<output url="file://$PROJECT_DIR$/out" /> | |
</component> | |
</project> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/ValidateExercise1Maven.iml" filepath="$PROJECT_DIR$/ValidateExercise1Maven.iml" /> | |
</modules> | |
</component> | |
</project> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="Palette2"> | |
<group name="Swing"> | |
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> | |
</item> | |
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> | |
</item> | |
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> | |
</item> | |
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> | |
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> | |
</item> | |
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> | |
<initial-values> | |
<property name="text" value="Button" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | |
<initial-values> | |
<property name="text" value="RadioButton" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | |
<initial-values> | |
<property name="text" value="CheckBox" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> | |
<initial-values> | |
<property name="text" value="Label" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
<preferred-size width="150" height="-1" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
<preferred-size width="150" height="-1" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
<preferred-size width="150" height="-1" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> | |
</item> | |
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | |
<preferred-size width="200" height="200" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | |
<preferred-size width="200" height="200" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | |
</item> | |
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | |
</item> | |
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> | |
</item> | |
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> | |
</item> | |
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> | |
<preferred-size width="-1" height="20" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> | |
</item> | |
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> | |
</item> | |
</group> | |
</component> | |
</project> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.exemple</groupId> | |
<artifactId>ValidateExercise</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.12</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.3</version> | |
<configuration> | |
<source>1.8</source> | |
<target>1.8</target> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
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
package tutorial; | |
/** | |
* Created by camille on 25/05/2016. | |
*/ | |
public class Main { | |
public static void main(String[] args){ | |
Welcomer welcomer = new WelcomerFactory().createWelcomer(); | |
welcomer.start(); | |
} | |
} | |
/* | |
Visibilitée de var d'instance, interfaces ou methodes: | |
-public | |
-private | |
-package private | |
final >> constant. Use for variables d'instances | |
Auto resolve error > Alt+Enter | |
alias > variable d'intances sont "intriqués" | |
pas le cas pour les autres variables | |
*/ | |
// Code source de Angular >> regarder les test unitaires |
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
package tutorial; | |
/** | |
* Created by camille on 08/06/2016. | |
*/ | |
public interface NameRequester { | |
void start(); | |
} |
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
package tutorial; | |
import tutorial.validate.Validator; | |
/** | |
* Created by camille on 08/06/2016. | |
*/ | |
public class NameRequesterImpl implements NameRequester{ | |
private final Writer writer; | |
private final Reader reader; | |
private final Validator validator; | |
public NameRequesterImpl(Writer writer, Reader reader, Validator validator){ | |
this.writer = writer; | |
this.reader = reader; | |
this.validator = validator; | |
} | |
@Override | |
public void start(){ | |
writer.write("Please enter your name\n"); | |
String input = reader.readLine(); | |
while(!(validator.validate(input))){ | |
writer.write("Your name is incorrect. Try again!\n"); | |
input = reader.readLine(); | |
} | |
writer.write("Name Correct!\n"); | |
} | |
} |
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
package tutorial; | |
/** | |
* Created by camille on 12/06/2016. | |
*/ | |
public interface PasswordRequester { | |
void start(); | |
} |
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
package tutorial; | |
import tutorial.validate.Validator; | |
/** | |
* Created by camille on 12/06/2016. | |
*/ | |
public class PasswordRequesterImpl implements PasswordRequester { | |
private final Writer writer; | |
private final Reader reader; | |
private final Validator validator; | |
public PasswordRequesterImpl(Writer writer, Reader reader, Validator validator) { | |
this.writer = writer; | |
this.reader = reader; | |
this.validator = validator; | |
} | |
@Override | |
public void start(){ | |
writer.write("Enter a password\n"); | |
String input = reader.readLine(); | |
while(!(validator.validate(input))){ | |
writer.write("Password not allowed! Try again\n"); | |
input = reader.readLine(); | |
} | |
writer.write("Good!\n"); | |
} | |
} |
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
package tutorial; | |
import tutorial.validate.Validator; | |
/** | |
* Created by camille on 25/05/2016. | |
*/ | |
public class Program { | |
private final Validator validator; | |
private final Writer writer; | |
private final Reader reader; | |
public Program(Validator validator, Writer writer, Reader reader){ | |
this.validator = validator; | |
this.writer = writer; | |
this.reader = reader; | |
} | |
void start(){ | |
writer.write("Please enter your name\n"); | |
String input = reader.readLine(); | |
while(!(validator.validate(input))){ | |
writer.write("Your name is incorrect. Try again!\n"); | |
input = reader.readLine(); | |
} | |
writer.write("Name Correct!"); | |
} | |
} |
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
package tutorial; | |
import tutorial.validate.LengthValidator; | |
/** | |
* Created by camille on 26/05/2016. | |
*/ | |
public class ProgramFactory { | |
public Program createProgram(){ | |
return new Program( new LengthValidator(), | |
new WriterImpl(), | |
new ReaderImpl()); | |
} | |
} |
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
package tutorial; | |
/** | |
* Created by camille on 26/05/2016. | |
*/ | |
public interface Reader { | |
String readLine(); | |
} |
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
package tutorial; | |
import java.util.Scanner; | |
/** | |
* Created by camille on 26/05/2016. | |
*/ | |
public class ReaderImpl implements Reader { | |
private final Scanner reader; | |
public ReaderImpl(){ | |
reader = new Scanner(System.in); | |
} | |
@Override | |
public String readLine() { | |
return reader.nextLine(); | |
} | |
} |
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
package tutorial.validate; | |
/** | |
* Created by camille on 25/05/2016. | |
*/ | |
public class CaseValidator implements Validator { | |
@Override | |
public boolean validate(String name){ | |
return name.equals(name.toLowerCase()); | |
} | |
} |
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
package tutorial.validate; | |
/** | |
* Created by camille on 25/05/2016. | |
*/ | |
public class LengthValidator implements Validator { | |
@Override | |
public boolean validate(String name){ | |
return name.length() >=2; | |
} | |
} |
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
package tutorial.validate; | |
/** | |
* Created by camille on 25/05/2016. | |
*/ | |
public interface Validator { | |
boolean validate(String name); | |
} |
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
package tutorial; | |
/** | |
* Created by camille on 25/05/2016. | |
*/ | |
public class Welcomer { | |
private final Writer writer; | |
private final NameRequester nameRequester; | |
private final PasswordRequester passwordRequester; | |
public Welcomer(Writer writer, NameRequester nameRequester, PasswordRequester passwordRequester){ | |
this.writer = writer; | |
this.nameRequester = nameRequester; | |
this.passwordRequester = passwordRequester; | |
} | |
void start(){ | |
writer.write("Hey! Welcome in the awesome Name Validator!\n"); | |
nameRequester.start(); | |
passwordRequester.start(); | |
} | |
} |
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
package tutorial; | |
import tutorial.validate.CaseValidator; | |
import tutorial.validate.Validator; | |
/** | |
* Created by camille on 26/05/2016. | |
*/ | |
public class WelcomerFactory { | |
public Welcomer createWelcomer(){ | |
Writer writer = new WriterImpl(); | |
Reader reader = new ReaderImpl(); | |
Validator validator = new CaseValidator(); | |
NameRequester nameRequester = new NameRequesterImpl(writer, reader, validator); | |
PasswordRequester passwordRequester = new PasswordRequesterImpl(writer, reader, validator); | |
return new Welcomer(writer, nameRequester, passwordRequester); | |
} | |
} | |
/*TODO | |
Can I delete Program, Pogramfactory and PorgramTest? | |
*/ |
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
package tutorial; | |
/** | |
* Created by camille on 26/05/2016. | |
*/ | |
public interface Writer { | |
void write(String text); | |
} |
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
package tutorial; | |
/** | |
* Created by camille on 26/05/2016. | |
*/ | |
public class WriterImpl implements Writer{ | |
@Override | |
public void write(String text) { | |
System.out.print(text); | |
} | |
} |
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
package tutorial; | |
/** | |
* Created by camille on 08/06/2016. | |
*/ | |
public class MockNameRequester implements NameRequester { | |
public boolean isStarted = false; | |
@Override | |
public void start() { isStarted = true; } | |
} |
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
package tutorial; | |
/** | |
* Created by camille on 12/06/2016. | |
*/ | |
public class MockPasswordRequester implements PasswordRequester { | |
public boolean isStarted = false; | |
@Override | |
public void start() { isStarted = true; } | |
} | |
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
package tutorial; | |
import java.util.Iterator; | |
/** | |
* Created by camille on 29/05/2016. | |
*/ | |
public class MockReader implements Reader { | |
private final Iterator<String> input; | |
public MockReader(Iterator<String> input) { | |
this.input = input; | |
} | |
@Override | |
public String readLine() { | |
return input.next(); | |
} | |
} |
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
package tutorial; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by camille on 29/05/2016. | |
*/ | |
public class MockWriter implements Writer { | |
public final List<String> lines; | |
public MockWriter() { | |
this.lines = new ArrayList<>(); | |
} | |
@Override | |
public void write(String text){ | |
lines.add(text); | |
} | |
} |
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
package tutorial; | |
import org.junit.Test; | |
import tutorial.validate.MockValidator; | |
import java.util.Arrays; | |
import java.util.List; | |
import static org.junit.Assert.assertEquals; | |
/** | |
* Created by camille on 29/05/2016. | |
*/ | |
public class ProgramTest { | |
@Test | |
public void testIter(){ | |
List<String> input = Arrays.asList("bidon", "gojzefz", "bill"); | |
MockValidator validator = new MockValidator("bill"); | |
MockWriter writer = new MockWriter(); | |
MockReader reader = new MockReader(input.iterator()); | |
new Program(validator, writer, reader).start(); | |
assertEquals("Please enter your name\n", writer.lines.get(0)); | |
assertEquals("Your name is incorrect. Try again!\n", writer.lines.get(1)); | |
assertEquals("Your name is incorrect. Try again!\n", writer.lines.get(2)); | |
assertEquals("Name Correct!", writer.lines.get(3)); | |
} | |
} |
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
package tutorial; | |
import org.junit.Test; | |
import tutorial.validate.MockValidator; | |
import java.util.Arrays; | |
import java.util.List; | |
import static org.junit.Assert.assertTrue; | |
import static org.junit.Assert.assertFalse; | |
/** | |
* Created by camille on 12/06/2016. | |
*/ | |
public class TestNameRequester { | |
@Test | |
public void test(){ | |
List<String> input = Arrays.asList("False", "False AGAIN", "good name"); | |
MockValidator mockValidator = new MockValidator("good name"); | |
assertFalse(mockValidator.validate(input.get(0))); | |
assertFalse(mockValidator.validate(input.get(1))); | |
assertTrue(mockValidator.validate(input.get(2))); | |
} | |
} |
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
package tutorial.validate; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
/** | |
* Created by camille on 29/05/2016. | |
*/ | |
public class CaseValidatorTest { | |
@Test | |
public void firstLetterIsUpperCase_False(){ | |
CaseValidator validator = new CaseValidator(); | |
assertFalse(validator.validate("Uppercase")); | |
} | |
@Test | |
public void allLettersAreLowerCase_True(){ | |
CaseValidator validator = new CaseValidator(); | |
assertTrue(validator.validate("lowercase")); | |
} | |
} |
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
package tutorial.validate; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
/** | |
* Created by camille on 29/05/2016. | |
*/ | |
public class LengthValidatorTest { | |
@Test | |
public void whenNameTooShort_invalid(){ | |
LengthValidator validator = new LengthValidator(); | |
assertFalse(validator.validate(".")); | |
} | |
@Test | |
public void whenNameLongEnough_valid(){ | |
LengthValidator validator = new LengthValidator(); | |
assertTrue(validator.validate("camille")); | |
} | |
} |
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
package tutorial.validate; | |
/** | |
* Created by camille on 29/05/2016. | |
*/ | |
public class MockValidator implements Validator{ | |
private final String validName; | |
public MockValidator(String validName) { | |
this.validName = validName; | |
} | |
@Override | |
public boolean validate(String name) { | |
return validName.equals(name); | |
} | |
} |
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
package tutorial; | |
import org.junit.Test; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertTrue; | |
/** | |
* Created by camille on 08/06/2016. | |
*/ | |
public class WelcomerTest { | |
@Test | |
public void test(){ | |
MockWriter writer = new MockWriter(); | |
MockNameRequester nameRequester = new MockNameRequester(); | |
MockPasswordRequester passwordRequester = new MockPasswordRequester(); | |
new Welcomer(writer, nameRequester, passwordRequester).start(); | |
assertEquals("Hey! Welcome in the awesome Name Validator!\n",writer.lines.get(0)); | |
assertTrue(nameRequester.isStarted); | |
assertTrue(passwordRequester.isStarted); | |
} | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | |
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false"> | |
<output url="file://$MODULE_DIR$/target/classes" /> | |
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | |
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | |
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | |
<excludeFolder url="file://$MODULE_DIR$/target" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" /> | |
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | |
</component> | |
</module> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment