修改单元测试 #2

Merged
zeekling merged 1 commits from testImplementation into master 2022-07-10 16:11:33 +00:00
14 changed files with 83 additions and 69 deletions
Showing only changes of commit cc9ba50605 - Show all commits

View File

@ -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'
}
} }

View File

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

View File

@ -5,7 +5,7 @@ package com.zeekling.abstractFactory;
*/ */
public interface Board { public interface Board {
void americaBoard(); String americaBoard();
void chineseBoard(); String chineseBoard();
} }

View File

@ -5,7 +5,7 @@ package com.zeekling.abstractFactory;
*/ */
public interface Display { public interface Display {
void americaDisplay(); String americaDisplay();
void chineseDisplay(); String chineseDisplay();
} }

View File

@ -6,13 +6,13 @@ import com.zeekling.abstractFactory.Board;
* Created by lzh on 16-6-10. * Created by lzh on 16-6-10.
*/ */
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 "中国产主板";
} }
} }

View File

@ -6,13 +6,13 @@ 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 "中国产显示屏";
} }
} }

View File

@ -4,31 +4,31 @@ 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.
*/ */
public class FactoryImpl implements AbstractFactory { public class FactoryImpl implements AbstractFactory {
private Display button = null; private Display button = null;
private Board panel = null; private Board panel = null;
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(); }
}
} }

View File

@ -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";
} }
} }

View File

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

View File

@ -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";
} }
} }

View File

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

View File

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

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

View File

@ -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