修改单元测试 #2
11
build.gradle
11
build.gradle
@ -2,6 +2,7 @@ group 'com.zeekling'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'jacoco'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
@ -10,5 +11,13 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation group: 'junit', name: 'junit', version: '4.12'
|
||||
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
|
||||
}
|
||||
|
||||
test {
|
||||
testLogging {
|
||||
outputs.upToDateWhen { false }
|
||||
showStandardStreams = true
|
||||
events 'started', 'passed'
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.zeekling.abstractFactory;
|
||||
|
||||
/**
|
||||
* @apiNote 抽象工厂模式
|
||||
* @author zeekling
|
||||
* @version 1.0
|
||||
* @apiNote 抽象工厂模式
|
||||
* @since 2019-12-04
|
||||
*/
|
||||
public interface AbstractFactory {
|
||||
void america();
|
||||
void chinese();
|
||||
String america();
|
||||
|
||||
String chinese();
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ package com.zeekling.abstractFactory;
|
||||
*/
|
||||
public interface Board {
|
||||
|
||||
void americaBoard();
|
||||
String americaBoard();
|
||||
|
||||
void chineseBoard();
|
||||
String chineseBoard();
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ package com.zeekling.abstractFactory;
|
||||
*/
|
||||
public interface Display {
|
||||
|
||||
void americaDisplay();
|
||||
String americaDisplay();
|
||||
|
||||
void chineseDisplay();
|
||||
String chineseDisplay();
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import com.zeekling.abstractFactory.Board;
|
||||
*/
|
||||
public class BoardImpl implements Board {
|
||||
@Override
|
||||
public void americaBoard() {
|
||||
System.out.println("美国产主板");
|
||||
public String americaBoard() {
|
||||
return "美国产主板";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chineseBoard() {
|
||||
System.out.println("中国产主板");
|
||||
public String chineseBoard() {
|
||||
return "中国产主板";
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import com.zeekling.abstractFactory.Display;
|
||||
*/
|
||||
public class DisplayImpl implements Display {
|
||||
@Override
|
||||
public void americaDisplay() {
|
||||
System.out.println("美国产显示屏");
|
||||
public String americaDisplay() {
|
||||
return "美国产显示屏";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chineseDisplay() {
|
||||
System.out.println("中国产显示屏");
|
||||
public String chineseDisplay() {
|
||||
return "中国产显示屏";
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import com.zeekling.abstractFactory.AbstractFactory;
|
||||
import com.zeekling.abstractFactory.Display;
|
||||
import com.zeekling.abstractFactory.Board;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Created by lzh on 16-6-10.
|
||||
*/
|
||||
@ -13,22 +15,20 @@ public class FactoryImpl implements AbstractFactory {
|
||||
|
||||
public FactoryImpl() {
|
||||
try {
|
||||
button = DisplayImpl.class.newInstance();
|
||||
panel = BoardImpl.class.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
button = DisplayImpl.class.getDeclaredConstructor().newInstance();
|
||||
panel = BoardImpl.class.getDeclaredConstructor().newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void america() {
|
||||
panel.americaBoard();
|
||||
button.americaDisplay();
|
||||
public String america() {
|
||||
return panel.americaBoard() + ":" + button.americaDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chinese() {
|
||||
panel.chineseBoard();
|
||||
button.chineseDisplay();
|
||||
public String chinese() {
|
||||
return panel.chineseBoard() + ":" + button.chineseDisplay();
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package com.zeekling.adapter;
|
||||
/**
|
||||
* Created by lzh on 3/30/16.
|
||||
*/
|
||||
public class Alibaba {
|
||||
public void mayun(){
|
||||
System.out.println("Alibaba");
|
||||
public abstract class Alibaba {
|
||||
public String name() {
|
||||
return "Alibaba";
|
||||
}
|
||||
}
|
||||
|
@ -4,5 +4,5 @@ package com.zeekling.adapter;
|
||||
* Created by lzh on 3/30/16.
|
||||
*/
|
||||
public interface Baidu {
|
||||
void liyanhong();
|
||||
String name();
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ package com.zeekling.adapter;
|
||||
*/
|
||||
public class BaiduImp extends Alibaba implements Baidu {
|
||||
@Override
|
||||
public void liyanhong() {
|
||||
super.mayun();
|
||||
System.out.println("Baidu");
|
||||
public String name() {
|
||||
super.name();
|
||||
return super.name() + ":" + "Baidu";
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package adapter.adapter.test;
|
||||
|
||||
import com.zeekling.adapter.Baidu;
|
||||
import com.zeekling.adapter.BaiduImp;
|
||||
|
||||
/**
|
||||
* Created by lzh on 3/30/16.
|
||||
*/
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
Baidu baidu = new BaiduImp();
|
||||
baidu.liyanhong();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.zeekling.abstractFactory;
|
||||
|
||||
import com.zeekling.abstractFactory.impl.FactoryImpl;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -9,12 +10,12 @@ import org.junit.Test;
|
||||
* @apiNote
|
||||
* @since 2019-12-02
|
||||
*/
|
||||
public class abstractFactoryTest {
|
||||
public class AbstractFactoryTest {
|
||||
|
||||
@Test
|
||||
public void abstractFactory(){
|
||||
AbstractFactory factory = new FactoryImpl();
|
||||
factory.america();
|
||||
factory.chinese();
|
||||
Assert.assertEquals("美国产主板:美国产显示屏", factory.america());
|
||||
Assert.assertEquals("中国产主板:中国产显示屏", factory.chinese());
|
||||
}
|
||||
}
|
17
src/test/java/com/zeekling/adapter/AdapterTest.java
Normal file
17
src/test/java/com/zeekling/adapter/AdapterTest.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.zeekling.adapter;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author zeekling [zeekling@zeekling.cn]
|
||||
* @since 2022-07-10
|
||||
*/
|
||||
public class AdapterTest {
|
||||
|
||||
@Test
|
||||
public void name() {
|
||||
Baidu baidu = new BaiduImp();
|
||||
Assert.assertEquals("Alibaba:Baidu", baidu.name());
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ import org.junit.Test;
|
||||
* @apiNote
|
||||
* @since 2019-12-02
|
||||
*/
|
||||
public class simpleFactoryTest {
|
||||
public class SimpleFactoryTest {
|
||||
|
||||
|
||||
@Test
|
Loading…
Reference in New Issue
Block a user