Skip to content

Commit

Permalink
Code created by the October 18th Coding Dojo session
Browse files Browse the repository at this point in the history
  • Loading branch information
GenevaCodingDojo committed Oct 24, 2011
1 parent b70ee58 commit 4947b52
Show file tree
Hide file tree
Showing 29 changed files with 1,217 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Exercice-3/src/main/java/NumberToRomansConvert.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ private String convertRecursive(int number, int power) {
} else if (number == 9 || number == 4) {
sb.append(convertRecursive(1,power)).append(convertRecursive(number + 1,power));
} else if (number >= 5) {
// 5 + number -5
sb.append(convertToRomanNumberWithPowerOf10Mult5(power)).append(convertRecursive(number - 5, power));
} else {
// 1 + number-1
sb.append(convertToRomanNumberWithPowerOf10(power)).append(convertRecursive(number - 1, power));
}
}
Expand Down
1 change: 1 addition & 0 deletions Exercice-4/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Using Mockito and Powermock in order to test some crappy code
54 changes: 54 additions & 0 deletions Exercice-4/pom.xml
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 Exercice-4/src/main/java/ch/genevajug/crappy/hello/HelloWorld.java
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();
}
}
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");
}
}
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();

}
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);

}
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.");
}
}
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;
}

}
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);
}

}
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;
}
}
Loading

0 comments on commit 4947b52

Please sign in to comment.