File tree 8 files changed +117
-0
lines changed
core-java-modules/core-java-interface 8 files changed +117
-0
lines changed Original file line number Diff line number Diff line change
1
+ Code for article: https://drafts.baeldung.com/interface-vs-interface/
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5
+ <modelVersion >4.0.0</modelVersion >
6
+
7
+ <groupId >org.example</groupId >
8
+ <artifactId >CoreJavaInterface</artifactId >
9
+ <version >1.0-SNAPSHOT</version >
10
+
11
+ <properties >
12
+ <maven .compiler.source>8</maven .compiler.source>
13
+ <maven .compiler.target>8</maven .compiler.target>
14
+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
15
+ </properties >
16
+ <dependencies >
17
+ <dependency >
18
+ <groupId >junit</groupId >
19
+ <artifactId >junit</artifactId >
20
+ <version >4.13.1</version >
21
+ <scope >test</scope >
22
+ </dependency >
23
+ </dependencies >
24
+
25
+ </project >
Original file line number Diff line number Diff line change
1
+ package org .annotations ;
2
+
3
+ import java .lang .annotation .ElementType ;
4
+ import java .lang .annotation .Retention ;
5
+ import java .lang .annotation .RetentionPolicy ;
6
+ import java .lang .annotation .Target ;
7
+
8
+ @ Retention (RetentionPolicy .RUNTIME )
9
+ @ Target ({ElementType .METHOD })
10
+ public @interface Review {
11
+ String reviewer ();
12
+ String date () default "" ;
13
+ }
Original file line number Diff line number Diff line change
1
+ package org .annotations ;
2
+
3
+ public class ReviewUsage {
4
+
5
+ @ Review (reviewer = "Natasha" , date = "2024-08-24" )
6
+ public String service () {
7
+ return "Some logic here" ;
8
+ }
9
+
10
+ }
Original file line number Diff line number Diff line change
1
+ package org .interfaces ;
2
+
3
+ public interface Animal {
4
+ String eat ();
5
+ String sleep ();
6
+ }
Original file line number Diff line number Diff line change
1
+ package org .interfaces ;
2
+
3
+ public class Dog implements Animal {
4
+ @ Override
5
+ public String eat () {
6
+ return "Dog is eating" ;
7
+ }
8
+
9
+ @ Override
10
+ public String sleep () {
11
+ return "Dog is sleeping" ;
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ package org .annotations ;
2
+
3
+ import org .junit .Test ;
4
+
5
+ import static org .junit .Assert .assertEquals ;
6
+
7
+ public class ReviewUsageTest {
8
+
9
+ @ Test
10
+ public void whenMethodAnnotatedWithReviewAnnotationIsCalled_ThenReviewerAndReviewDateIsPopulated ()
11
+ throws NoSuchMethodException {
12
+ ReviewUsage reviewUsage = new ReviewUsage ();
13
+
14
+ Review review = reviewUsage
15
+ .getClass ()
16
+ .getDeclaredMethod ("service" )
17
+ .getAnnotation (Review .class );
18
+
19
+ assertEquals ("Natasha" , review .reviewer ());
20
+ assertEquals ("2024-08-24" , review .date ());
21
+ }
22
+
23
+ }
Original file line number Diff line number Diff line change
1
+ package org .interfaces ;
2
+
3
+ import org .junit .Test ;
4
+
5
+ import static org .junit .Assert .assertEquals ;
6
+
7
+ public class DogTest {
8
+
9
+ @ Test
10
+ public void givenDogIsAAnimal_whenEatMethodIsCalled_ThenAssertIfDogIsEating () {
11
+ Dog dog = new Dog ();
12
+
13
+ String response = dog .eat ();
14
+
15
+ assertEquals ("Dog is eating" , response );
16
+ }
17
+
18
+ @ Test
19
+ public void givenDogIsAAnimal_whenSleepMethodIsCalled_ThenAssertIfDogIsSleeping () {
20
+ Dog dog = new Dog ();
21
+
22
+ String response = dog .sleep ();
23
+
24
+ assertEquals ("Dog is sleeping" , response );
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments