Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
simple_java
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
simple_java
Commits
5a0a5e76
Commit
5a0a5e76
authored
Dec 13, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Testy JUnit i nowe metody w Konto
parent
6d176abe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
0 deletions
+120
-0
pom.xml
pom.xml
+9
-0
Konto.java
src/main/java/com/example/Konto.java
+28
-0
KontoTest.java
src/test/java/com/example/KontoTest.java
+83
-0
No files found.
pom.xml
View file @
5a0a5e76
...
@@ -14,4 +14,13 @@
...
@@ -14,4 +14,13 @@
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
</properties>
<dependencies>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-api
</artifactId>
<version>
5.14.1
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
</project>
src/main/java/com/example/Konto.java
View file @
5a0a5e76
...
@@ -34,4 +34,32 @@ public class Konto {
...
@@ -34,4 +34,32 @@ public class Konto {
public
String
toString
()
{
public
String
toString
()
{
return
"Konto nr "
+
numer
+
", saldo "
+
saldo
+
", wł. "
+
wlasciciel
;
return
"Konto nr "
+
numer
+
", saldo "
+
saldo
+
", wł. "
+
wlasciciel
;
}
}
public
void
wplata
(
int
kwota
)
{
if
(
kwota
<=
0
)
{
throw
new
IllegalArgumentException
(
"kwota wpłaty nie jest dodatnia"
);
}
saldo
+=
kwota
;
}
public
void
wyplata
(
int
kwota
)
throws
BrakSrodkow
{
if
(
kwota
<=
0
)
{
throw
new
IllegalArgumentException
(
"kwota wypłaty nie jest dodatnia"
);
}
if
(
kwota
>
saldo
)
{
throw
new
BrakSrodkow
(
"Za mało kasy"
);
}
saldo
-=
kwota
;
}
public
void
przelew
(
Konto
inne
,
int
kwota
)
throws
BrakSrodkow
{
if
(
kwota
<=
0
)
{
throw
new
IllegalArgumentException
(
"kwota przelewu nie jest dodatnia"
);
}
if
(
kwota
>
saldo
)
{
throw
new
BrakSrodkow
(
"Za mało kasy"
);
}
this
.
saldo
-=
kwota
;
inne
.
saldo
+=
kwota
;
}
}
}
src/test/java/com/example/KontoTest.java
0 → 100644
View file @
5a0a5e76
package
com
.
example
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
class
KontoTest
{
static
final
String
osoba
=
"Ala"
,
osoba2
=
"Ola"
;
Konto
konto
;
@BeforeEach
void
setUp
()
throws
Exception
{
konto
=
new
Konto
(
1
,
1000
,
osoba
);
}
@Test
void
testKonstruktorIGettery
()
{
assertEquals
(
1
,
konto
.
getNumer
());
assertEquals
(
osoba
,
konto
.
getWlasciciel
());
assertEquals
(
1000
,
konto
.
getSaldo
());
}
@Test
void
testToString
()
{
String
napis
=
konto
.
toString
();
assertEquals
(
"Konto nr 1, saldo 1000, wł. "
+
osoba
.
toString
(),
napis
);
}
@Test
void
testWplata
()
{
konto
.
wplata
(
400
);
assertEquals
(
1400
,
konto
.
getSaldo
());
}
@Test
void
testWyplata
()
throws
BrakSrodkow
{
konto
.
wyplata
(
300
);
assertEquals
(
700
,
konto
.
getSaldo
());
}
@Test
void
testWplataUjemna
()
{
assertThrows
(
IllegalArgumentException
.
class
,
()
->
{
konto
.
wplata
(-
100
);
});
assertEquals
(
1000
,
konto
.
getSaldo
());
}
@Test
void
testWyplataUjemna
()
{
assertThrows
(
IllegalArgumentException
.
class
,
()
->
{
konto
.
wyplata
(-
100
);
});
assertEquals
(
1000
,
konto
.
getSaldo
());
}
@Test
void
testBrakSrodkow
()
{
assertThrows
(
BrakSrodkow
.
class
,
()
->
{
konto
.
wyplata
(
1300
);
});
assertEquals
(
1000
,
konto
.
getSaldo
());
}
@Test
void
testPrzelew
()
throws
BrakSrodkow
{
Konto
inne
=
new
Konto
(
2
,
2000
,
osoba2
);
konto
.
przelew
(
inne
,
400
);
assertEquals
(
600
,
konto
.
getSaldo
());
assertEquals
(
2400
,
inne
.
getSaldo
());
}
@Test
void
testPrzelewUjemny
()
{
Konto
inne
=
new
Konto
(
2
,
2000
,
osoba2
);
assertThrows
(
IllegalArgumentException
.
class
,
()
->
{
konto
.
przelew
(
inne
,
-
100
);
});
assertEquals
(
1000
,
konto
.
getSaldo
());
assertEquals
(
2000
,
inne
.
getSaldo
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment