commit 2090a42d2469a0544d04c12a9d7ea6d87960f00d Author: Juanjo Pedraza Date: Thu Feb 3 18:59:17 2022 +0100 inicio diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..0a1dadd --- /dev/null +++ b/.classpath @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..767808b --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + s00.badcoupledsamplefixed + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..f9fe345 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..abec6ca --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..08c40b2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + + es.anaya.spring.badcode + s00.badcoupledsamplefixed + 0.0.1-SNAPSHOT + jar + + s00.badcoupledsamplefixed + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + diff --git a/s00.badcoupledsamplefixed.UCLS.png b/s00.badcoupledsamplefixed.UCLS.png new file mode 100644 index 0000000..5190192 Binary files /dev/null and b/s00.badcoupledsamplefixed.UCLS.png differ diff --git a/s00.badcoupledsamplefixed.UCLS.ucls b/s00.badcoupledsamplefixed.UCLS.ucls new file mode 100644 index 0000000..bd7c9b9 --- /dev/null +++ b/s00.badcoupledsamplefixed.UCLS.ucls @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixed/App.java b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixed/App.java new file mode 100644 index 0000000..4b44abc --- /dev/null +++ b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixed/App.java @@ -0,0 +1,10 @@ +package es.anaya.spring.badcode.s00.badcoupledsamplefixed; + +public class App { + public static void main(String[] args) { + CsvFileDataSource csvFileDataSource = new CsvFileDataSource("file.csv", ";"); + CustomerList customerList = new CustomerList(csvFileDataSource); + customerList.loadFile("samplefile.csv", ";"); + System.out.println(customerList.showAll()); + } +} diff --git a/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixed/CsvFileDataSource.java b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixed/CsvFileDataSource.java new file mode 100644 index 0000000..e41cba5 --- /dev/null +++ b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixed/CsvFileDataSource.java @@ -0,0 +1,24 @@ +package es.anaya.spring.badcode.s00.badcoupledsamplefixed; + +import java.util.ArrayList; + +public class CsvFileDataSource { + private String filename; + private String separator; + + public CsvFileDataSource(String filename, String separator) { + this.filename = filename; + this.separator = separator; + } + + public ArrayList loadData() { + ArrayList lines = new ArrayList(); + + lines.add("Customer1, customer1@sample.com, 234 street"); + lines.add("Customer2, customer2@sample.com, 523 street"); + lines.add("Customer3, customer3@sample.com, 231 street"); + + return lines; + } + +} diff --git a/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixed/CustomerList.java b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixed/CustomerList.java new file mode 100644 index 0000000..9c2cf6b --- /dev/null +++ b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixed/CustomerList.java @@ -0,0 +1,21 @@ +package es.anaya.spring.badcode.s00.badcoupledsamplefixed; + +import java.util.ArrayList; + +public class CustomerList { + private CsvFileDataSource csvFileDataSource; + private ArrayList customerData; + + public CustomerList (CsvFileDataSource csvFileDataSource) { + this.customerData = new ArrayList(); + this.csvFileDataSource = csvFileDataSource; + } + + public void loadFile (String filename, String separator) { + customerData = csvFileDataSource.loadData(); + } + + public String showAll () { + return customerData.toString(); + } +} diff --git a/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/App.java b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/App.java new file mode 100644 index 0000000..0a63560 --- /dev/null +++ b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/App.java @@ -0,0 +1,10 @@ +package es.anaya.spring.badcode.s00.badcoupledsamplefixedwithinterfaces; + +public class App { + public static void main(String[] args) { + DataSource csvFileDataSource = new CsvFileDataSource("file.csv", ";"); + CustomerList customerList = new CustomerList(csvFileDataSource); + customerList.loadFile("samplefile.csv", ";"); + System.out.println(customerList.showAll()); + } +} diff --git a/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/CsvFileDataSource.java b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/CsvFileDataSource.java new file mode 100644 index 0000000..dc968ef --- /dev/null +++ b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/CsvFileDataSource.java @@ -0,0 +1,24 @@ +package es.anaya.spring.badcode.s00.badcoupledsamplefixedwithinterfaces; + +import java.util.ArrayList; + +public class CsvFileDataSource implements DataSource { + private String filename; + private String separator; + + public CsvFileDataSource(String filename, String separator) { + this.filename = filename; + this.separator = separator; + } + + public ArrayList loadData() { + ArrayList lines = new ArrayList(); + + lines.add("Customer1, customer1@sample.com, 234 street"); + lines.add("Customer2, customer2@sample.com, 523 street"); + lines.add("Customer3, customer3@sample.com, 231 street"); + + return lines; + } + +} diff --git a/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/CustomerList.java b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/CustomerList.java new file mode 100644 index 0000000..c78d3c3 --- /dev/null +++ b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/CustomerList.java @@ -0,0 +1,21 @@ +package es.anaya.spring.badcode.s00.badcoupledsamplefixedwithinterfaces; + +import java.util.ArrayList; + +public class CustomerList { + private DataSource dataSource; + private ArrayList customerData; + + public CustomerList (DataSource dataSource) { + this.customerData = new ArrayList(); + this.dataSource = dataSource; + } + + public void loadFile (String filename, String separator) { + customerData = dataSource.loadData(); + } + + public String showAll () { + return customerData.toString(); + } +} diff --git a/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/DataSource.java b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/DataSource.java new file mode 100644 index 0000000..2d6f702 --- /dev/null +++ b/src/main/java/es/anaya/spring/badcode/s00/badcoupledsamplefixedwithinterfaces/DataSource.java @@ -0,0 +1,7 @@ +package es.anaya.spring.badcode.s00.badcoupledsamplefixedwithinterfaces; + +import java.util.ArrayList; + +public interface DataSource { + public ArrayList loadData(); +} diff --git a/src/test/java/es/anaya/spring/badcode/s00/badcoupledsample/AppTest.java b/src/test/java/es/anaya/spring/badcode/s00/badcoupledsample/AppTest.java new file mode 100644 index 0000000..e6b96a2 --- /dev/null +++ b/src/test/java/es/anaya/spring/badcode/s00/badcoupledsample/AppTest.java @@ -0,0 +1,38 @@ +package es.anaya.spring.badcode.s00.badcoupledsample; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}