Skip to content

Instantly share code, notes, and snippets.

package stepDefinitions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
Feature: Wikipedia search
Scenario: Search with title
Given User is at home page
When User searched for a title "iPhone"
Then User found the page
package cucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(features="src/test/java/features", glue="stepDefinitions", monochrome=true)
public class TestNGRunner extends AbstractTestNGCucumberTests {
}
@oofnivek
oofnivek / Main.java
Last active January 11, 2024 17:31
Extract certificate from JKS in PEM format
package org.example;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
import org.bouncycastle.util.io.pem.PemObject;
import java.io.*;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
@oofnivek
oofnivek / Main.java
Created January 11, 2024 12:46
Appending string to file
package org.example;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import static java.util.UUID.randomUUID;
@oofnivek
oofnivek / Main.java
Created January 11, 2024 12:31
Write string contents to file
package org.example;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
String content = "hello world";
try {
@oofnivek
oofnivek / Main.java
Last active January 11, 2024 12:24
Read file line by line
package org.example;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try {
package com.example.demo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit;
@Configuration
public class CacheStoreBeans {
package com.example.demo;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.util.concurrent.TimeUnit;
public class CacheStore<T> {
private Cache<String, T> cache;
package com.example.demo;
import org.springframework.stereotype.Service;
@Service
public class BookService {
public Book getBookById(String id){
try{
// simulate slow retrieval from DB
Thread.sleep(2000);