BAEL-5617 Handle classes with the same name in Java (#12676)

* BAEL-5617 Handle classes with the same name in Java

code samples

* BAEL-5617 Handle classes with the same name in Java

update project module
This commit is contained in:
Bogdan Cardoş 2022-09-01 17:33:41 +03:00 committed by GitHub
parent 3d17a48aa2
commit c3204d4a2e
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package com.baeldung.date;
public class Date {
private long currentTimeMillis;
public Date() {
this(System.currentTimeMillis());
}
public Date(long currentTimeMillis) {
this.currentTimeMillis = currentTimeMillis;
}
public long getTime() {
return currentTimeMillis;
}
}

View File

@ -0,0 +1,27 @@
package com.baeldung.date;
import java.util.Date;
import org.junit.Assert;
import org.junit.Test;
public class DateUnitTest {
@Test
public void whenUsingFullyQualifiedClassNames() {
java.util.Date javaDate = new java.util.Date();
com.baeldung.date.Date baeldungDate = new com.baeldung.date.Date(javaDate.getTime());
Assert.assertEquals(javaDate.getTime(), baeldungDate.getTime());
}
@Test
public void whenImportTheMostUsedOne() {
Date javaDate = new Date();
com.baeldung.date.Date baeldungDate = new com.baeldung.date.Date(javaDate.getTime());
Assert.assertEquals(javaDate.getTime(), baeldungDate.getTime());
}
}