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