-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code created by the October 18th Coding Dojo session
- Loading branch information
1 parent
b70ee58
commit 4947b52
Showing
29 changed files
with
1,217 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Using Mockito and Powermock in order to test some crappy code |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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>LegacyMocking</groupId> | ||
<artifactId>LegacyMocking</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<powermock.version>1.4.10</powermock.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-beans</artifactId> | ||
<version>3.0.5.RELEASE</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.8.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.easytesting</groupId> | ||
<artifactId>fest-assert</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>1.8.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.powermock</groupId> | ||
<artifactId>powermock-module-junit4</artifactId> | ||
<version>${powermock.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.powermock</groupId> | ||
<artifactId>powermock-api-mockito</artifactId> | ||
<version>${powermock.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
22 changes: 22 additions & 0 deletions
22
Exercice-4/src/main/java/ch/genevajug/crappy/hello/HelloWorld.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2008 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ch.genevajug.crappy.hello; | ||
|
||
public class HelloWorld { | ||
public String greet() { | ||
return SimpleConfig.getGreeting() + " " + SimpleConfig.getTarget(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
Exercice-4/src/main/java/ch/genevajug/crappy/hello/SimpleConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2008 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ch.genevajug.crappy.hello; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* Important third party code that cannot be changed. | ||
*/ | ||
public class SimpleConfig { | ||
|
||
private static Properties PROPERTIES; | ||
|
||
private static synchronized void initialize() { | ||
if (PROPERTIES == null) { | ||
PROPERTIES = new Properties(); | ||
try { | ||
PROPERTIES.load(SimpleConfig.class.getClassLoader().getResourceAsStream("simpleConfig.properties")); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
public static String getGreeting() { | ||
initialize(); | ||
return PROPERTIES.getProperty("greeting"); | ||
} | ||
|
||
public static String getTarget() { | ||
initialize(); | ||
return PROPERTIES.getProperty("target"); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Exercice-4/src/main/java/ch/genevajug/crappy/providerservice/dao/ProviderDao.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2008 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ch.genevajug.crappy.providerservice.dao; | ||
|
||
import ch.genevajug.crappy.providerservice.dao.domain.impl.ServiceArtifact; | ||
|
||
import java.util.Set; | ||
|
||
public interface ProviderDao { | ||
|
||
/** | ||
* @return A set of all available service producers. | ||
*/ | ||
Set<ServiceArtifact> getAllServiceProducers(); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
Exercice-4/src/main/java/ch/genevajug/crappy/providerservice/dao/domain/Connection.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2008 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ch.genevajug.crappy.providerservice.dao.domain; | ||
|
||
public interface Connection { | ||
|
||
void disconnect(); | ||
|
||
void send(byte[] data); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...e-4/src/main/java/ch/genevajug/crappy/providerservice/dao/domain/impl/ConnectionImpl.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2008 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ch.genevajug.crappy.providerservice.dao.domain.impl; | ||
|
||
import ch.genevajug.crappy.providerservice.dao.domain.Connection; | ||
|
||
public class ConnectionImpl implements Connection { | ||
|
||
public void disconnect() { | ||
System.out.println("Disconnecting..."); | ||
} | ||
|
||
public void send(byte[] data) { | ||
System.out.println("Sending data of " + data.length + " bytes."); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...-4/src/main/java/ch/genevajug/crappy/providerservice/dao/domain/impl/ServiceArtifact.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2008 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ch.genevajug.crappy.providerservice.dao.domain.impl; | ||
|
||
import ch.genevajug.crappy.providerservice.dao.domain.Connection; | ||
import ch.genevajug.crappy.providerservice.domain.DataProducer; | ||
|
||
public class ServiceArtifact { | ||
|
||
private final int id; | ||
|
||
private final String name; | ||
|
||
private final DataProducer[] dataProducers; | ||
|
||
public ServiceArtifact(int id, String name, DataProducer... dataProducers) { | ||
this.id = id; | ||
this.name = name; | ||
this.dataProducers = dataProducers; | ||
} | ||
|
||
public DataProducer[] getDataProducers() { | ||
return dataProducers; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Connection connectToService() { | ||
return new ConnectionImpl(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + id; | ||
result = prime * result + ((name == null) ? 0 : name.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
final ServiceArtifact other = (ServiceArtifact) obj; | ||
if (id != other.id) | ||
return false; | ||
if (name == null) { | ||
if (other.name != null) | ||
return false; | ||
} else if (!name.equals(other.name)) | ||
return false; | ||
return true; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
Exercice-4/src/main/java/ch/genevajug/crappy/providerservice/domain/DataProducer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2008 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ch.genevajug.crappy.providerservice.domain; | ||
|
||
public class DataProducer extends ProviderArtifact { | ||
|
||
public DataProducer(int id, String name) { | ||
super(id, name); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
Exercice-4/src/main/java/ch/genevajug/crappy/providerservice/domain/ProviderArtifact.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2008 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ch.genevajug.crappy.providerservice.domain; | ||
|
||
public abstract class ProviderArtifact { | ||
|
||
private final int id; | ||
|
||
private final String name; | ||
|
||
public ProviderArtifact(int id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + id; | ||
result = prime * result + ((name == null) ? 0 : name.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
final ProviderArtifact other = (ProviderArtifact) obj; | ||
if (id != other.id) | ||
return false; | ||
if (name == null) { | ||
if (other.name != null) | ||
return false; | ||
} else if (!name.equals(other.name)) | ||
return false; | ||
return true; | ||
} | ||
} |
Oops, something went wrong.