diff --git a/build.gradle b/build.gradle index b0aed13..6f044b9 100644 --- a/build.gradle +++ b/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' + } } diff --git a/src/main/java/com/zeekling/abstractFactory/AbstractFactory.java b/src/main/java/com/zeekling/abstractFactory/AbstractFactory.java index 2bcf4cb..b645db5 100755 --- a/src/main/java/com/zeekling/abstractFactory/AbstractFactory.java +++ b/src/main/java/com/zeekling/abstractFactory/AbstractFactory.java @@ -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(); } diff --git a/src/main/java/com/zeekling/abstractFactory/Board.java b/src/main/java/com/zeekling/abstractFactory/Board.java index bd5a5c9..e3cae88 100755 --- a/src/main/java/com/zeekling/abstractFactory/Board.java +++ b/src/main/java/com/zeekling/abstractFactory/Board.java @@ -5,7 +5,7 @@ package com.zeekling.abstractFactory; */ public interface Board { - void americaBoard(); + String americaBoard(); - void chineseBoard(); + String chineseBoard(); } diff --git a/src/main/java/com/zeekling/abstractFactory/Display.java b/src/main/java/com/zeekling/abstractFactory/Display.java index 3117236..ac5bfa4 100755 --- a/src/main/java/com/zeekling/abstractFactory/Display.java +++ b/src/main/java/com/zeekling/abstractFactory/Display.java @@ -5,7 +5,7 @@ package com.zeekling.abstractFactory; */ public interface Display { - void americaDisplay(); + String americaDisplay(); - void chineseDisplay(); + String chineseDisplay(); } diff --git a/src/main/java/com/zeekling/abstractFactory/impl/BoardImpl.java b/src/main/java/com/zeekling/abstractFactory/impl/BoardImpl.java index 9967520..0261744 100755 --- a/src/main/java/com/zeekling/abstractFactory/impl/BoardImpl.java +++ b/src/main/java/com/zeekling/abstractFactory/impl/BoardImpl.java @@ -6,13 +6,13 @@ import com.zeekling.abstractFactory.Board; * Created by lzh on 16-6-10. */ public class BoardImpl implements Board { - @Override - public void americaBoard() { - System.out.println("美国产主板"); - } + @Override + public String americaBoard() { + return "美国产主板"; + } - @Override - public void chineseBoard() { - System.out.println("中国产主板"); - } + @Override + public String chineseBoard() { + return "中国产主板"; + } } diff --git a/src/main/java/com/zeekling/abstractFactory/impl/DisplayImpl.java b/src/main/java/com/zeekling/abstractFactory/impl/DisplayImpl.java index 27b9679..7db2361 100755 --- a/src/main/java/com/zeekling/abstractFactory/impl/DisplayImpl.java +++ b/src/main/java/com/zeekling/abstractFactory/impl/DisplayImpl.java @@ -6,13 +6,13 @@ import com.zeekling.abstractFactory.Display; * */ public class DisplayImpl implements Display { - @Override - public void americaDisplay() { - System.out.println("美国产显示屏"); - } + @Override + public String americaDisplay() { + return "美国产显示屏"; + } - @Override - public void chineseDisplay() { - System.out.println("中国产显示屏"); - } + @Override + public String chineseDisplay() { + return "中国产显示屏"; + } } diff --git a/src/main/java/com/zeekling/abstractFactory/impl/FactoryImpl.java b/src/main/java/com/zeekling/abstractFactory/impl/FactoryImpl.java index a21fa80..0775030 100755 --- a/src/main/java/com/zeekling/abstractFactory/impl/FactoryImpl.java +++ b/src/main/java/com/zeekling/abstractFactory/impl/FactoryImpl.java @@ -4,31 +4,31 @@ 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. */ public class FactoryImpl implements AbstractFactory { - private Display button = null; - private Board panel = null; + private Display button = null; + private Board panel = null; - public FactoryImpl() { - try { - button = DisplayImpl.class.newInstance(); - panel = BoardImpl.class.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - } + public FactoryImpl() { + try { + 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(); - } + @Override + public String america() { + return panel.americaBoard() + ":" + button.americaDisplay(); + } - @Override - public void chinese() { - panel.chineseBoard(); - button.chineseDisplay(); - } + @Override + public String chinese() { + return panel.chineseBoard() + ":" + button.chineseDisplay(); + } } diff --git a/src/main/java/com/zeekling/adapter/Alibaba.java b/src/main/java/com/zeekling/adapter/Alibaba.java index 4aa92ce..f9a8cc7 100755 --- a/src/main/java/com/zeekling/adapter/Alibaba.java +++ b/src/main/java/com/zeekling/adapter/Alibaba.java @@ -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"; + } } diff --git a/src/main/java/com/zeekling/adapter/Baidu.java b/src/main/java/com/zeekling/adapter/Baidu.java index 43b45c5..7a00e44 100755 --- a/src/main/java/com/zeekling/adapter/Baidu.java +++ b/src/main/java/com/zeekling/adapter/Baidu.java @@ -4,5 +4,5 @@ package com.zeekling.adapter; * Created by lzh on 3/30/16. */ public interface Baidu { - void liyanhong(); + String name(); } diff --git a/src/main/java/com/zeekling/adapter/BaiduImp.java b/src/main/java/com/zeekling/adapter/BaiduImp.java index d3a378d..2332cf7 100755 --- a/src/main/java/com/zeekling/adapter/BaiduImp.java +++ b/src/main/java/com/zeekling/adapter/BaiduImp.java @@ -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"; } } diff --git a/src/main/java/com/zeekling/adapter/test/Test.java b/src/main/java/com/zeekling/adapter/test/Test.java deleted file mode 100755 index 2d0787b..0000000 --- a/src/main/java/com/zeekling/adapter/test/Test.java +++ /dev/null @@ -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(); - } -} diff --git a/src/test/java/com/zeekling/abstractFactory/abstractFactoryTest.java b/src/test/java/com/zeekling/abstractFactory/AbstractFactoryTest.java similarity index 58% rename from src/test/java/com/zeekling/abstractFactory/abstractFactoryTest.java rename to src/test/java/com/zeekling/abstractFactory/AbstractFactoryTest.java index 3989d57..8c9a49e 100644 --- a/src/test/java/com/zeekling/abstractFactory/abstractFactoryTest.java +++ b/src/test/java/com/zeekling/abstractFactory/AbstractFactoryTest.java @@ -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()); } } diff --git a/src/test/java/com/zeekling/adapter/AdapterTest.java b/src/test/java/com/zeekling/adapter/AdapterTest.java new file mode 100644 index 0000000..be2738f --- /dev/null +++ b/src/test/java/com/zeekling/adapter/AdapterTest.java @@ -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()); + } +} diff --git a/src/test/java/com/zeekling/simpleFactory/simpleFactoryTest.java b/src/test/java/com/zeekling/simpleFactory/SimpleFactoryTest.java similarity index 95% rename from src/test/java/com/zeekling/simpleFactory/simpleFactoryTest.java rename to src/test/java/com/zeekling/simpleFactory/SimpleFactoryTest.java index a76be06..d332610 100644 --- a/src/test/java/com/zeekling/simpleFactory/simpleFactoryTest.java +++ b/src/test/java/com/zeekling/simpleFactory/SimpleFactoryTest.java @@ -8,7 +8,7 @@ import org.junit.Test; * @apiNote * @since 2019-12-02 */ -public class simpleFactoryTest { +public class SimpleFactoryTest { @Test