pompitzz / java Goto Github PK
View Code? Open in Web Editor NEW자바 프로그래밍 언어에 대한 기본지식들을 공부하는 저장소
자바 프로그래밍 언어에 대한 기본지식들을 공부하는 저장소
package assertj;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import static assertj.MemberType.ADMIN;
import static assertj.MemberType.USER;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.util.Lists.newArrayList;
class MemberTest {
private Member dexter = new Member("dexter", 12, ADMIN);
private Member james = new Member("james", 30, ADMIN);
private Member park = new Member("park", 23, USER);
private Member lee = new Member("lee", 33, USER);
private List<Member> members = newArrayList(dexter, james, park, lee);
private void throwException() throws Exception {
throw new Exception("I`m Exception");
}
@Test
void file() throws Exception {
File file = writeFile("Temp", "You Know Nothing Jon Snow");
// 1
assertThat(file).exists().isFile().isRelative();
// 2
assertThat(contentOf(file))
.startsWith("You")
.contains("Know Nothing")
.endsWith("Jon Snow");
}
private File writeFile(String fileName, String fileContent) throws Exception {
File file = new File(fileName);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Charset.defaultCharset()));
writer.write(fileContent);
writer.close();
return file;
}
@Test
void no_softAssertion() throws Exception {
assertThat(dexter.getAge()).as("Dexter Age Test").isEqualTo(11);
assertThat(james.getAge()).as("James Age Test").isEqualTo(31);
assertThat(park.getAge()).as("Park Age Test").isEqualTo(24);
assertThat(lee.getAge()).as("Lee Age Test").isEqualTo(32);
}
@Test
void softAssertion() throws Exception {
SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat(dexter.getAge()).as("Dexter Age Test").isEqualTo(11);
softAssertions.assertThat(james.getAge()).as("James Age Test").isEqualTo(31);
softAssertions.assertThat(park.getAge()).as("Park Age Test").isEqualTo(24);
softAssertions.assertThat(lee.getAge()).as("Lee Age Test").isEqualTo(32);
softAssertions.assertAll();
}
@Test
void softAssertion_JUnitSoft() throws Exception {
SoftAssertions.assertSoftly(softAssertions -> {
softAssertions.assertThat(dexter.getAge()).as("Dexter Age Test").isEqualTo(11);
softAssertions.assertThat(james.getAge()).as("James Age Test").isEqualTo(31);
softAssertions.assertThat(park.getAge()).as("Park Age Test").isEqualTo(24);
softAssertions.assertThat(lee.getAge()).as("Lee Age Test").isEqualTo(32);
});
}
@Test
void no_extracting() throws Exception {
List<String> names = new ArrayList<>();
for (Member member : members) {
names.add(member.getName());
}
assertThat(names).containsOnly("dexter", "james", "park", "lee");
}
@Test
void extracting() throws Exception {
assertThat(members)
.extracting("name")
.containsOnly("dexter", "james", "park", "lee");
}
@Test
void extracting_more() throws Exception {
// 1
assertThat(members)
.extracting("name")
.contains("dexter", "james", "park", "lee")
.doesNotContain("ann, jung");
// 2
assertThat(members)
.extracting("name", String.class)
.contains("dexter", "james", "park", "lee");
// 3
assertThat(members)
.extracting("name", "age")
.contains(
tuple("dexter", 12),
tuple("james", 30),
tuple("park", 23),
tuple("lee", 33)
);
}
@Test
void sample() throws Exception {
// 1
assertThat(members)
.filteredOn("type", ADMIN)
.containsOnly(dexter, james);
// 2
assertThat(members)
.filteredOn(m -> m.getType() == USER)
.containsOnly(park, lee);
// 3
assertThat(members).
filteredOn("type", in(ADMIN, USER))
.containsOnly(dexter, james, park, lee);
// 4
assertThat(members)
.filteredOn("type", not(ADMIN))
.containsOnly(park, lee);
// 5
assertThat(members)
.filteredOn("type", ADMIN)
.filteredOn(m -> m.getAge() > 20)
.containsOnly(james);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.