Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-16635

This commit is contained in:
amit2103 2019-09-01 14:39:18 +05:30
commit 70156ea452
29 changed files with 206 additions and 27 deletions

3
bazel/README.md Normal file
View File

@ -0,0 +1,3 @@
## Relevant Articles:
- [Building Java Applications with Bazel](https://www.baeldung.com/bazel-build-tool)

View File

@ -1,4 +1,4 @@
package com.baeldung.java8;
package com.baeldung.concurrent.executorservice;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

View File

@ -1,7 +1,7 @@
/**
*
*/
package com.baeldung.java9.datetime;
package com.baeldung.datetolocaldate;
import java.time.Instant;
import java.time.LocalDate;

View File

@ -1,7 +1,7 @@
/**
*
*/
package com.baeldung.java9.datetime;
package com.baeldung.datetolocaldate;
import java.time.Instant;
import java.time.LocalDateTime;

View File

@ -1,7 +1,7 @@
/**
*
*/
package com.baeldung.java9.datetime;
package com.baeldung.datetolocaldate;
import java.time.LocalDateTime;
import java.time.ZoneId;

View File

@ -1,7 +1,7 @@
/**
*
*/
package com.baeldung.java9.datetime;
package com.baeldung.datetolocaldate;
import java.time.LocalDate;
import java.time.ZoneId;

View File

@ -1,7 +1,7 @@
/**
*
*/
package com.baeldung.java9.datetime;
package com.baeldung.datetolocaldate;
import static org.junit.Assert.assertEquals;
@ -12,7 +12,7 @@ import java.util.Date;
import org.junit.Test;
import com.baeldung.java9.datetime.DateToLocalDateConverter;
import com.baeldung.datetolocaldate.DateToLocalDateConverter;
/**
* JUnits for {@link DateToLocalDateConverter} class.

View File

@ -1,7 +1,7 @@
/**
*
*/
package com.baeldung.java9.datetime;
package com.baeldung.datetolocaldate;
import static org.junit.Assert.assertEquals;
@ -12,7 +12,7 @@ import java.util.Date;
import org.junit.Test;
import com.baeldung.java9.datetime.DateToLocalDateTimeConverter;
import com.baeldung.datetolocaldate.DateToLocalDateTimeConverter;
/**
* JUnits for {@link DateToLocalDateTimeConverter} class.

View File

@ -1,7 +1,7 @@
/**
*
*/
package com.baeldung.java9.datetime;
package com.baeldung.datetolocaldate;
import static org.junit.Assert.assertEquals;
@ -11,6 +11,8 @@ import java.util.Date;
import org.junit.Test;
import com.baeldung.datetolocaldate.LocalDateTimeToDateConverter;
/**
*
* JUnits for {@link LocalDateTimeToDateConverter} class.

View File

@ -1,7 +1,7 @@
/**
*
*/
package com.baeldung.java9.datetime;
package com.baeldung.datetolocaldate;
import static org.junit.Assert.assertEquals;
@ -11,6 +11,8 @@ import java.util.Date;
import org.junit.Test;
import com.baeldung.datetolocaldate.LocalDateToDateConverter;
/**
*
* JUnits for {@link LocalDateToDateConverter} class.

View File

@ -1,4 +1,4 @@
package com.baeldung.string;
package com.baeldung.string.newline;
public class AddingNewLineToString {

View File

@ -1,4 +1,4 @@
package org.baeldung;
package org.baeldung.javaxval.beanvalidation;
import java.time.LocalDate;
import java.util.List;

View File

@ -1,20 +1,18 @@
package org.baeldung;
package org.baeldung.javaxval.beanvalidation;
import static org.junit.Assert.assertEquals;
import java.time.LocalDate;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.Optional;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Before;
import org.junit.Test;
public class ValidationIntegrationTest {

View File

@ -1,4 +1,4 @@
package com.baeldung.resource;
package com.baeldung.classpathfileaccess;
import static org.junit.Assert.assertEquals;

View File

@ -1,4 +1,4 @@
package com.baeldung.spring;
package com.baeldung.security.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import com.baeldung.spring.SecSecurityConfig;
import com.baeldung.security.config.SecSecurityConfig;
import javax.servlet.Filter;

View File

@ -1,4 +1,4 @@
package com.baeldung.exception;
package com.baeldung.assertexception;
import static org.junit.jupiter.api.Assertions.assertThrows;

View File

@ -1,4 +1,4 @@
package com.baeldung.migration.junit4;
package com.baeldung.assertexception.migration.junit4;
import org.junit.Rule;
import org.junit.Test;

View File

@ -1,5 +1,7 @@
package org.baeldung.mockito;
import org.baeldung.mockito.voidmethods.MyList;
public final class FinalList extends MyList {
@Override

View File

@ -6,6 +6,8 @@ import static org.junit.Assert.assertNotEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.baeldung.mockito.voidmethods.MyList;
public class MockFinals {
@Test

View File

@ -11,6 +11,8 @@ import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
import org.baeldung.mockito.voidmethods.MyList;
public class MockitoConfigExamplesIntegrationTest {
// tests

View File

@ -1,6 +1,9 @@
package org.baeldung.mockito;
import static org.mockito.Mockito.*;
import org.baeldung.mockito.voidmethods.MyList;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.containsString;

View File

@ -1,6 +1,8 @@
package org.baeldung.mockito;
import com.google.common.collect.Lists;
import org.baeldung.mockito.voidmethods.MyList;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;

View File

@ -1,4 +1,4 @@
package org.baeldung.mockito;
package org.baeldung.mockito.voidmethods;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;

View File

@ -1,8 +1,8 @@
package org.baeldung.mockito;
package org.baeldung.mockito.voidmethods;
import java.util.AbstractList;
class MyList extends AbstractList<String> {
public class MyList extends AbstractList<String> {
@Override
public String get(final int index) {

View File

@ -0,0 +1,74 @@
package com.baeldung.xml.stax;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.ArrayList;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.namespace.QName;
public class StaxParser {
public static List<WebSite> parse(String path) {
List<WebSite> websites = new ArrayList<WebSite>();
WebSite website = null;
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
try {
XMLEventReader reader = xmlInputFactory.createXMLEventReader(new FileInputStream(path));
while (reader.hasNext()) {
XMLEvent nextEvent = reader.nextEvent();
if (nextEvent.isStartElement()) {
StartElement startElement = nextEvent.asStartElement();
switch (startElement.getName()
.getLocalPart()) {
case "website":
website = new WebSite();
Attribute url = startElement.getAttributeByName(new QName("url"));
if (url != null) {
website.setUrl(url.getValue());
}
break;
case "name":
nextEvent = reader.nextEvent();
website.setName(nextEvent.asCharacters()
.getData());
break;
case "category":
nextEvent = reader.nextEvent();
website.setCategory(nextEvent.asCharacters()
.getData());
break;
case "status":
nextEvent = reader.nextEvent();
website.setStatus(nextEvent.asCharacters()
.getData());
break;
}
}
if (nextEvent.isEndElement()) {
EndElement endElement = nextEvent.asEndElement();
if (endElement.getName()
.getLocalPart()
.equals("website")) {
websites.add(website);
}
}
}
} catch (XMLStreamException xse) {
System.out.println("XMLStreamException");
xse.printStackTrace();
} catch (FileNotFoundException fnfe) {
System.out.println("FileNotFoundException");
fnfe.printStackTrace();
}
return websites;
}
}

View File

@ -0,0 +1,40 @@
package com.baeldung.xml.stax;
public class WebSite {
private String url;
private String name;
private String category;
private String status;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

View File

@ -0,0 +1,31 @@
package com.baeldung.xml.stax;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Test;
public class StaxParserUnitTest {
@Test
public void givenWebsitesXML_whenParsed_thenNotNull() {
List<WebSite> websites = StaxParser.parse("src/test/resources/xml/websites.xml");
assertNotNull(websites);
}
@Test
public void givenWebsitesXML_whenParsed_thenSizeIsThree() {
List<WebSite> websites = StaxParser.parse("src/test/resources/xml/websites.xml");
assertEquals(3, websites.size());
}
@Test
public void givenWebsitesXML_whenParsed_thenLocalhostExists() {
List<WebSite> websites = StaxParser.parse("src/test/resources/xml/websites.xml");
assertEquals("Localhost", websites.get(2).getName());
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<websites>
<website url="https://baeldung.com">
<name>Baeldung</name>
<category>Online Courses</category>
<status>Online</status>
</website>
<website url="http://example.com">
<name>Example</name>
<category>Examples</category>
<status>Offline</status>
</website>
<website url="http://localhost:8080">
<name>Localhost</name>
<category>Tests</category>
<status>Offline</status>
</website>
</websites>