Created
February 18, 2014 07:19
-
-
Save boniface/9066037 to your computer and use it in GitHub Desktop.
super calc
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.kabaso.calculator.service.Impl; | |
import com.kabaso.calculator.service.CalculatorService; | |
/** | |
* | |
* @author boniface | |
*/ | |
public class SuperCalc implements CalculatorService{ | |
@Override | |
public int add(int a, int b) { | |
System.out.println("AM THE SUPER CALC"); | |
return a+b; //To change body of generated methods, choose Tools | Templates. | |
} | |
} |
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.kabaso</groupId> | |
<artifactId>calculator</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>jar</packaging> | |
<dependencies> | |
<dependency> | |
<groupId>org.testng</groupId> | |
<artifactId>testng</artifactId> | |
<version>6.8.1</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-context</artifactId> | |
</dependency> | |
</dependencies> | |
<dependencyManagement> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-framework-bom</artifactId> | |
<version>4.0.1.RELEASE</version> | |
<type>pom</type> | |
<scope>import</scope> | |
</dependency> | |
</dependencies> | |
</dependencyManagement> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<maven.compiler.source>1.7</maven.compiler.source> | |
<maven.compiler.target>1.7</maven.compiler.target> | |
</properties> | |
</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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.kabaso.calculator.service.Impl; | |
import com.kabaso.calculator.service.CalculatorService; | |
/** | |
* | |
* @author boniface | |
*/ | |
public class CalculatorServiceImpl implements CalculatorService{ | |
@Override | |
public int add(int a, int b) { | |
System.out.println(" AM THE ORIGINAL"); | |
return a+b; //To change body of generated methods, choose Tools | Templates. | |
} | |
} |
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.kabaso.calculator.service.Impl; | |
import com.kabaso.calculator.service.CalculatorService; | |
/** | |
* | |
* @author boniface | |
*/ | |
public class CalculatorServiceImpl implements CalculatorService{ | |
@Override | |
public int add(int a, int b) { | |
System.out.println(" AM THE ORIGINAL"); | |
return a+b; //To change body of generated methods, choose Tools | Templates. | |
} | |
} |
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.kabaso.calculator.config; | |
import com.kabaso.calculator.service.CalculatorService; | |
import com.kabaso.calculator.service.Impl.CalculatorServiceImpl; | |
import com.kabaso.calculator.service.Impl.SuperCalc; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
/** | |
* | |
* @author boniface | |
*/ | |
@Configuration | |
public class AppConfig { | |
@Bean(name="cretired") | |
public CalculatorService getService(){ | |
return new CalculatorServiceImpl(); | |
} | |
@Bean(name="calc") | |
public CalculatorService getServicenew(){ | |
return new SuperCalc(); | |
} | |
} |
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.kabaso.calculator; | |
import com.kabaso.calculator.config.AppConfig; | |
import com.kabaso.calculator.service.CalculatorService; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | |
import org.testng.Assert; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.AfterMethod; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.BeforeMethod; | |
import org.testng.annotations.Test; | |
/** | |
* | |
* @author boniface | |
*/ | |
public class CalculatorTest { | |
private static CalculatorService service; | |
public CalculatorTest() { | |
} | |
// TODO add test methods here. | |
// The methods must be annotated with annotation @Test. For example: | |
// | |
@Test | |
public void add() { | |
Assert.assertEquals(service.add(2, 5), 7); | |
} | |
@BeforeClass | |
public static void setUpClass() throws Exception { | |
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class); | |
service = (CalculatorService)ctx.getBean("calc"); | |
} | |
@AfterClass | |
public static void tearDownClass() throws Exception { | |
} | |
@BeforeMethod | |
public void setUpMethod() throws Exception { | |
} | |
@AfterMethod | |
public void tearDownMethod() throws Exception { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment