Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cb05c6c

Browse files
Add files via upload
1 parent c3a6a4d commit cb05c6c

File tree

100 files changed

+3465
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+3465
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project>
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>tkt</groupId>
5+
<artifactId>Part04_01.YourFirstAccount</artifactId>
6+
<name>Part04_01.YourFirstAccount</name>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<version>4.12</version>
21+
<scope>test</scope>
22+
</dependency>
23+
<dependency>
24+
<groupId>fi.helsinki.cs.tmc</groupId>
25+
<artifactId>edu-test-utils</artifactId>
26+
<version>0.4.2</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.powermock</groupId>
31+
<artifactId>powermock-classloading-objenesis</artifactId>
32+
<version>2.0.2</version>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.powermock</groupId>
37+
<artifactId>powermock-api-easymock</artifactId>
38+
<version>2.0.2</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.powermock</groupId>
43+
<artifactId>powermock-module-junit4-rule</artifactId>
44+
<version>2.0.2</version>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-compiler-plugin</artifactId>
54+
<version>3.8.0</version>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.codehaus.mojo</groupId>
58+
<artifactId>exec-maven-plugin</artifactId>
59+
<version>1.6.0</version>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
64+
<repositories>
65+
<repository>
66+
<id>tmc</id>
67+
<name>TMC repo</name>
68+
<url>https://maven.mooc.fi/releases</url>
69+
<releases>
70+
<enabled>true</enabled>
71+
</releases>
72+
<snapshots>
73+
<enabled>true</enabled>
74+
</snapshots>
75+
</repository>
76+
</repositories>
77+
78+
<pluginRepositories>
79+
<pluginRepository>
80+
<id>tmc</id>
81+
<name>TMC repo</name>
82+
<url>https://maven.mooc.fi/releases</url>
83+
<releases>
84+
<enabled>true</enabled>
85+
</releases>
86+
<snapshots>
87+
<enabled>true</enabled>
88+
</snapshots>
89+
</pluginRepository>
90+
</pluginRepositories>
91+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* DO NOT TOUCH THIS !
3+
*/
4+
5+
public class Account {
6+
7+
private double balance;
8+
private String owner;
9+
10+
public Account(String owner, double balance) {
11+
this.balance = balance;
12+
this.owner = owner;
13+
}
14+
15+
public void deposit(double amount) {
16+
this.balance = this.balance + amount;
17+
}
18+
19+
public void withdrawal(double amount) {
20+
this.balance = this.balance - amount;
21+
}
22+
23+
public double saldo() {
24+
return this.balance;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return this.owner + " balance: " + this.balance;
30+
}
31+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
public class YourFirstAccount {
3+
4+
public static void main(String[] args) {
5+
// Do not touch the code in Account.java
6+
// Write your program here
7+
Account myAccount = new Account("Nashida", 100.00);
8+
9+
myAccount.deposit(20);
10+
11+
System.out.println(myAccount);
12+
}
13+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import java.io.InputStream;
2+
import java.io.PrintStream;
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.ByteArrayInputStream;
5+
6+
public class MockInOut {
7+
8+
private PrintStream orig;
9+
private InputStream irig;
10+
private ByteArrayOutputStream os;
11+
private ByteArrayInputStream is;
12+
13+
public MockInOut(String input) {
14+
orig = System.out;
15+
irig = System.in;
16+
17+
os = new ByteArrayOutputStream();
18+
System.setOut(new PrintStream(os));
19+
20+
is = new ByteArrayInputStream(input.getBytes());
21+
System.setIn(is);
22+
}
23+
24+
public InputStream getInputStream() {
25+
return is;
26+
}
27+
28+
public String getOutput() {
29+
if (os != null)
30+
return os.toString();
31+
else
32+
throw new Error("getOutput on closed MockInOut!");
33+
}
34+
35+
public void close() {
36+
os = null;
37+
is = null;
38+
System.setOut(orig);
39+
System.setIn(irig);
40+
}
41+
}
42+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
import fi.helsinki.cs.tmc.edutestutils.Points;
3+
import org.easymock.EasyMock;
4+
import org.junit.Test;
5+
import org.junit.Rule;
6+
import org.powermock.modules.junit4.rule.PowerMockRule;
7+
8+
import org.powermock.core.classloader.annotations.PrepareForTest;
9+
import static org.junit.Assert.*;
10+
import static org.powermock.api.easymock.PowerMock.*;
11+
12+
@Points("04-01")
13+
@PrepareForTest({YourFirstAccount.class, Account.class})
14+
public class YourFirstAccountTest {
15+
16+
@Rule
17+
public PowerMockRule p = new PowerMockRule();
18+
19+
@Test
20+
public void test() throws Exception {
21+
Account accountMock = createMock(Account.class);
22+
23+
expectNew(Account.class, EasyMock.anyObject(String.class), EasyMock.eq(100.0)).andReturn(accountMock);
24+
25+
accountMock.deposit(20.0);
26+
replay(accountMock, Account.class);
27+
28+
try {
29+
YourFirstAccount.main(new String[0]);
30+
verify(accountMock, Account.class);
31+
32+
} catch (Throwable t) {
33+
String error = t.getMessage();
34+
if (error.contains("deposit")) {
35+
fail("create an account and call the deposit method with paramter 20 ");
36+
} else if (error.contains("constructor")) {
37+
fail("When creating an account, give the constructor parameter 100.0 ");
38+
} else if (error.contains("saldo")) {
39+
fail("The program must print the account details by callign System.out.println(account). Here account refers to Account variable named account. " + error);
40+
}
41+
fail("Unexpected error:\n" + error);
42+
}
43+
}
44+
45+
@Test
46+
public void testaaToString() throws Exception {
47+
MockInOut mio = new MockInOut("The program must print the account details by callign System.out.println(account). Here account refers to Account variable named account. ");
48+
49+
YourFirstAccount.main(new String[0]);
50+
51+
String out = mio.getOutput();
52+
assertTrue("", out.contains("120.0"));
53+
mio.close();
54+
55+
}
56+
}
1.04 KB
Binary file not shown.
701 Bytes
Binary file not shown.
1.38 KB
Binary file not shown.
2.8 KB
Binary file not shown.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project>
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>tkt</groupId>
5+
<artifactId>Part04_02.YourFirstBankTransfer</artifactId>
6+
<name>Part04_02.YourFirstBankTransfer</name>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<version>4.12</version>
21+
<scope>test</scope>
22+
</dependency>
23+
<dependency>
24+
<groupId>fi.helsinki.cs.tmc</groupId>
25+
<artifactId>edu-test-utils</artifactId>
26+
<version>0.4.2</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.powermock</groupId>
31+
<artifactId>powermock-classloading-objenesis</artifactId>
32+
<version>2.0.2</version>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.powermock</groupId>
37+
<artifactId>powermock-api-easymock</artifactId>
38+
<version>2.0.2</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.powermock</groupId>
43+
<artifactId>powermock-module-junit4-rule</artifactId>
44+
<version>2.0.2</version>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-compiler-plugin</artifactId>
54+
<version>3.8.0</version>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.codehaus.mojo</groupId>
58+
<artifactId>exec-maven-plugin</artifactId>
59+
<version>1.6.0</version>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
64+
<repositories>
65+
<repository>
66+
<id>tmc</id>
67+
<name>TMC repo</name>
68+
<url>https://maven.mooc.fi/releases</url>
69+
<releases>
70+
<enabled>true</enabled>
71+
</releases>
72+
<snapshots>
73+
<enabled>true</enabled>
74+
</snapshots>
75+
</repository>
76+
</repositories>
77+
78+
<pluginRepositories>
79+
<pluginRepository>
80+
<id>tmc</id>
81+
<name>TMC repo</name>
82+
<url>https://maven.mooc.fi/releases</url>
83+
<releases>
84+
<enabled>true</enabled>
85+
</releases>
86+
<snapshots>
87+
<enabled>true</enabled>
88+
</snapshots>
89+
</pluginRepository>
90+
</pluginRepositories>
91+
</project>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /