cleanup work and test naming

This commit is contained in:
eugenp 2017-05-14 19:23:11 +03:00
parent 2b374fa8ae
commit e0b85586e2
19 changed files with 69 additions and 103 deletions

View File

@ -9,8 +9,6 @@ public class TenantBean {
} }
public void sayHello() { public void sayHello() {
System.out.println(String.format("Hello from %s of type %s", System.out.println(String.format("Hello from %s of type %s", this.name, this.getClass().getName()));
this.name,
this.getClass().getName()));
} }
} }

View File

@ -37,8 +37,6 @@ public class SimpleReportExporter {
this.jasperPrint = jasperPrint; this.jasperPrint = jasperPrint;
} }
public void exportToPdf(String fileName, String author) { public void exportToPdf(String fileName, String author) {
// print report to file // print report to file
@ -61,8 +59,7 @@ public class SimpleReportExporter {
try { try {
exporter.exportReport(); exporter.exportReport();
} catch (JRException ex) { } catch (JRException ex) {
Logger.getLogger(SimpleReportFiller.class.getName()) Logger.getLogger(SimpleReportFiller.class.getName()).log(Level.SEVERE, null, ex);
.log(Level.SEVERE, null, ex);
} }
} }
@ -80,8 +77,7 @@ public class SimpleReportExporter {
try { try {
exporter.exportReport(); exporter.exportReport();
} catch (JRException ex) { } catch (JRException ex) {
Logger.getLogger(SimpleReportFiller.class.getName()) Logger.getLogger(SimpleReportFiller.class.getName()).log(Level.SEVERE, null, ex);
.log(Level.SEVERE, null, ex);
} }
} }
@ -94,8 +90,7 @@ public class SimpleReportExporter {
try { try {
exporter.exportReport(); exporter.exportReport();
} catch (JRException ex) { } catch (JRException ex) {
Logger.getLogger(SimpleReportFiller.class.getName()) Logger.getLogger(SimpleReportFiller.class.getName()).log(Level.SEVERE, null, ex);
.log(Level.SEVERE, null, ex);
} }
} }
@ -108,8 +103,7 @@ public class SimpleReportExporter {
try { try {
exporter.exportReport(); exporter.exportReport();
} catch (JRException ex) { } catch (JRException ex) {
Logger.getLogger(SimpleReportFiller.class.getName()) Logger.getLogger(SimpleReportFiller.class.getName()).log(Level.SEVERE, null, ex);
.log(Level.SEVERE, null, ex);
} }
} }
} }

View File

@ -45,8 +45,7 @@ public class SimpleReportFiller {
jasperReport = JasperCompileManager.compileReport(reportStream); jasperReport = JasperCompileManager.compileReport(reportStream);
JRSaver.saveObject(jasperReport, reportFileName.replace(".jrxml", ".jasper")); JRSaver.saveObject(jasperReport, reportFileName.replace(".jrxml", ".jasper"));
} catch (JRException ex) { } catch (JRException ex) {
Logger.getLogger(SimpleReportFiller.class.getName()) Logger.getLogger(SimpleReportFiller.class.getName()).log(Level.SEVERE, null, ex);
.log(Level.SEVERE, null, ex);
} }
} }
@ -54,8 +53,7 @@ public class SimpleReportFiller {
try { try {
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource.getConnection()); jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource.getConnection());
} catch (JRException | SQLException ex) { } catch (JRException | SQLException ex) {
Logger.getLogger(SimpleReportFiller.class.getName()) Logger.getLogger(SimpleReportFiller.class.getName()).log(Level.SEVERE, null, ex);
.log(Level.SEVERE, null, ex);
} }
} }

View File

@ -13,10 +13,7 @@ public class JasperRerportsSimpleConfig {
@Bean @Bean
public DataSource dataSource() { public DataSource dataSource() {
return new EmbeddedDatabaseBuilder() return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).addScript("classpath:employee-schema.sql").build();
.setType(EmbeddedDatabaseType.HSQL)
.addScript("classpath:employee-schema.sql")
.build();
} }
@Bean @Bean

View File

@ -33,24 +33,13 @@ public class SimpleCLI implements CommandMarker {
return sb.toString(); return sb.toString();
} }
@CliCommand( @CliCommand(value = { "web-get", "wg" }, help = "Displays the contents of a URL.")
value = {"web-get", "wg"}, public String webGet(@CliOption(key = { "", "url" }, help = "URL whose contents will be displayed.") URL url) {
help = "Displays the contents of a URL."
)
public String webGet(
@CliOption(
key = {"", "url"},
help = "URL whose contents will be displayed."
) URL url) {
return getContentsOfUrlAsString(url); return getContentsOfUrlAsString(url);
} }
@CliCommand( @CliCommand(value = { "web-save", "ws" }, help = "Saves the contents of a URL.")
value = {"web-save", "ws"}, public String webSave(@CliOption(key = { "", "url" }, help = "URL whose contents will be saved.") URL url, @CliOption(key = { "out", "file" }, mandatory = true, help = "The name of the file.") String file) {
help = "Saves the contents of a URL.")
public String webSave(
@CliOption(key = {"", "url"}, help = "URL whose contents will be saved.") URL url,
@CliOption(key = {"out", "file"}, mandatory = true, help = "The name of the file.") String file) {
String contents = getContentsOfUrlAsString(url); String contents = getContentsOfUrlAsString(url);
try (PrintWriter out = new PrintWriter(file)) { try (PrintWriter out = new PrintWriter(file)) {
out.write(contents); out.write(contents);

View File

@ -22,8 +22,7 @@ public class SimpleURLConverter implements Converter<URL> {
} }
@Override @Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> requiredType, public boolean getAllPossibleValues(List<Completion> completions, Class<?> requiredType, String existingData, String optionContext, MethodTarget target) {
String existingData, String optionContext, MethodTarget target) {
return false; return false;
} }

View File

@ -39,6 +39,7 @@ public class ThreadPoolTaskSchedulerExamples {
public RunnableTask(String message) { public RunnableTask(String message) {
this.message = message; this.message = message;
} }
@Override @Override
public void run() { public void run() {
System.out.println("Runnable Task with " + message + " on thread " + Thread.currentThread().getName()); System.out.println("Runnable Task with " + message + " on thread " + Thread.currentThread().getName());

View File

@ -5,19 +5,17 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class ConstructorBasedBeanInjectionWithJavaConfigTest { public class ConstructorBasedBeanInjectionWithJavaConfigIntegrationTest {
private static final String HELM_NAME = "HelmBrand"; private static final String HELM_NAME = "HelmBrand";
@Test @Test
public void givenJavaConfigFile_whenUsingConstructorBasedBeanInjection_thenCorrectHelmName() { public void givenJavaConfigFile_whenUsingConstructorBasedBeanInjection_thenCorrectHelmName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConstructorBasedShipConfig.class); ctx.register(ConstructorBasedShipConfig.class);
ctx.refresh(); ctx.refresh();
Ship ship = ctx.getBean(Ship.class); Ship ship = ctx.getBean(Ship.class);
Assert.assertEquals(HELM_NAME, ship.getHelm() Assert.assertEquals(HELM_NAME, ship.getHelm().getBrandOfHelm());
.getBrandOfHelm());
} }
} }

View File

@ -5,7 +5,7 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ConstructorBasedBeanInjectionWithXMLConfigTest { public class ConstructorBasedBeanInjectionWithXMLConfigIntegrationTest {
private static final String HELM_NAME = "HelmBrand"; private static final String HELM_NAME = "HelmBrand";
@ -14,7 +14,6 @@ public class ConstructorBasedBeanInjectionWithXMLConfigTest {
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beanInjection-constructor.xml"); final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beanInjection-constructor.xml");
final Ship shipConstructorBean = (Ship) applicationContext.getBean("ship"); final Ship shipConstructorBean = (Ship) applicationContext.getBean("ship");
Assert.assertEquals(HELM_NAME, shipConstructorBean.getHelm() Assert.assertEquals(HELM_NAME, shipConstructorBean.getHelm().getBrandOfHelm());
.getBrandOfHelm());
} }
} }

View File

@ -5,7 +5,7 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class SetterBasedBeanInjectionWithJavaConfigTest { public class SetterBasedBeanInjectionWithJavaConfigIntegrationTest {
private static final String HELM_NAME = "HelmBrand"; private static final String HELM_NAME = "HelmBrand";
@ -18,7 +18,6 @@ public class SetterBasedBeanInjectionWithJavaConfigTest {
Ship ship = ctx.getBean(Ship.class); Ship ship = ctx.getBean(Ship.class);
Assert.assertEquals(HELM_NAME, ship.getHelm() Assert.assertEquals(HELM_NAME, ship.getHelm().getBrandOfHelm());
.getBrandOfHelm());
} }
} }

View File

@ -5,7 +5,7 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SetterBasedBeanInjectionWithXMLConfigTest { public class SetterBasedBeanInjectionWithXMLConfigIntegrationTest {
private static final String HELM_NAME = "HelmBrand"; private static final String HELM_NAME = "HelmBrand";
@ -14,7 +14,6 @@ public class SetterBasedBeanInjectionWithXMLConfigTest {
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beanInjection-setter.xml"); final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beanInjection-setter.xml");
final Ship shipSetterBean = (Ship) applicationContext.getBean("ship"); final Ship shipSetterBean = (Ship) applicationContext.getBean("ship");
Assert.assertEquals(HELM_NAME, shipSetterBean.getHelm() Assert.assertEquals(HELM_NAME, shipSetterBean.getHelm().getBrandOfHelm());
.getBrandOfHelm());
} }
} }

View File

@ -37,8 +37,7 @@ public class TenantScopeTest {
assertThat(fooDefinition.getScope(), equalTo("tenant")); assertThat(fooDefinition.getScope(), equalTo("tenant"));
assertThat(barDefinition.getScope(), equalTo("tenant")); assertThat(barDefinition.getScope(), equalTo("tenant"));
} } finally {
finally {
ctx.close(); ctx.close();
} }
} }
@ -66,8 +65,7 @@ public class TenantScopeTest {
assertThat(fooDefinition.getScope(), equalTo("tenant")); assertThat(fooDefinition.getScope(), equalTo("tenant"));
assertThat(barDefinition.getScope(), equalTo("tenant")); assertThat(barDefinition.getScope(), equalTo("tenant"));
} } finally {
finally {
ctx.close(); ctx.close();
} }
} }

View File

@ -21,8 +21,7 @@ public class SquareCalculatorTest {
public void whenCalculatingSquareValueOnce_thenCacheDontHaveValues() { public void whenCalculatingSquareValueOnce_thenCacheDontHaveValues() {
for (int i = 10; i < 15; i++) { for (int i = 10; i < 15; i++) {
assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); assertFalse(cacheHelper.getSquareNumberCache().containsKey(i));
System.out.println("Square value of " + i + " is: " System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n");
+ squaredCalculator.getSquareValueOfNumber(i) + "\n");
} }
} }
@ -30,14 +29,12 @@ public class SquareCalculatorTest {
public void whenCalculatingSquareValueAgain_thenCacheHasAllValues() { public void whenCalculatingSquareValueAgain_thenCacheHasAllValues() {
for (int i = 10; i < 15; i++) { for (int i = 10; i < 15; i++) {
assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); assertFalse(cacheHelper.getSquareNumberCache().containsKey(i));
System.out.println("Square value of " + i + " is: " System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n");
+ squaredCalculator.getSquareValueOfNumber(i) + "\n");
} }
for (int i = 10; i < 15; i++) { for (int i = 10; i < 15; i++) {
assertTrue(cacheHelper.getSquareNumberCache().containsKey(i)); assertTrue(cacheHelper.getSquareNumberCache().containsKey(i));
System.out.println("Square value of " + i + " is: " System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n");
+ squaredCalculator.getSquareValueOfNumber(i) + "\n");
} }
} }
} }