Skip to content

Commit

Permalink
end
Browse files Browse the repository at this point in the history
  • Loading branch information
isidore committed Apr 26, 2021
0 parents commit 9da0e94
Show file tree
Hide file tree
Showing 15 changed files with 458 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '11', '14']

steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Build with Maven
run: mvn -B verify --file pom.xml
22 changes: 22 additions & 0 deletions .github/workflows/updateMarkdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: on-push-do-doco
on:
push:
jobs:
release:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Run MarkdownSnippets
run: |
dotnet tool install --global MarkdownSnippets.Tool
mdsnippets ${GITHUB_WORKSPACE}
shell: bash
- name: Push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -m "Doco changes" -a || echo "nothing to commit"
remote="https://${GITHUB_ACTOR}:${{secrets.GITHUB_TOKEN}}@github.com/${GITHUB_REPOSITORY}.git"
branch="${GITHUB_REF:11}"
git push "${remote}" ${branch} || echo "nothing to push"
shell: bash
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.class
.settings
.preferences
.classpath
.project
target
.idea
*.iml

*.received.*
1 change: 1 addition & 0 deletions Launching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Launch Me](https://us-east-2.console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/create/review?templateURL=https://raw.githubusercontent.com/approvals/ApprovalTests.java.StarterProject/master/launch.ec2.yml&stackName=approvaltests-java-starterproject)
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ApprovalTests.java.StarterProject

[![Build Status](../../workflows/build/badge.svg?branch=master)](../../actions?query=build%3Amaster)


This is a starter project for:

* ApprovalTests in java - see [ApprovalTests.java](https://github.com/approvals/ApprovalTests.java)
* Junit
* Maven

Works on Mac, Linux and Windows.

Feel free to copy and go...

## Starting Point

The tests in [SampleTests](https://github.com/approvals/ApprovalTests.java.StarterProject/blob/master/src/test/java/org/samples/SampleTests.java) should pass, and then you should delete/modify as needed to get started.


Notes:

* For more information, see the [ApprovalTests.java User Guide](https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/docs/README.md#top)
* You will need a Diff tool.
* Suggestions:
* Mac: [DiffMerge](https://sourcegear.com/diffmerge/)
* Windows: [WinMerge](winmerge.org/)
* Linux: [meld](http://meldmerge.org/)


19 changes: 19 additions & 0 deletions install.windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# To run this script directly, run this in an elevated admin PowerShell prompt:
# Invoke-WebRequest -UseBasicParsing https://raw.githubusercontent.com/approvals/ApprovalTests.java.StarterProject/master/install.windows.ps1 | Invoke-Expression

# This script is intended to setup a dev machine from scratch. Very useful for setting up a EC2 instance for mobbing.
#


iwr -useb https://raw.githubusercontent.com/JayBazuzi/machine-setup/main/windows.ps1 | iex
iwr -useb https://raw.githubusercontent.com/JayBazuzi/machine-setup/main/java-intellij.ps1 | iex

#install project specific tools
choco install -y jdk8

# Clone repo
& "C:\Program Files\Git\cmd\git.exe" clone https://github.com/approvals/ApprovalTests.java.StarterProject.git C:\Code\ApprovalTests.java.StarterProject

# Done
cls
echo "Done!"
87 changes: 87 additions & 0 deletions launch.ec2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/sample-templates-services-us-west-2.html#w1ab2c21c45c15c15
# Amazon EC2 instance in a security group Creates an Amazon EC2 instance in an Amazon EC2 security group.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS CloudFormation Sample Template EC2InstanceWithSecurityGroupSample:
Create an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based
on the region in which the stack is run. This example creates an EC2 security group
for the instance to give you SSH access. **WARNING** This template creates an Amazon
EC2 instance. You will be billed for the AWS resources used if you create a stack
from this template.'
Parameters:
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: must be the name of an existing EC2 KeyPair.
InstanceType:
Description: WebServer EC2 instance type
Type: String
Default: t2.xlarge
AllowedValues:
- t2.large
- t2.xlarge
ConstraintDescription: must be a valid EC2 instance type.
SSHLocation:
Description: The IP address range that can be used to SSH to the EC2 instances
Type: String
MinLength: '9'
MaxLength: '18'
Default: 0.0.0.0/0
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
Mappings:
AWSInstanceType2Arch:
t2.large:
Arch: HVM64
t2.xlarge:
Arch: HVM64
Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType:
Ref: InstanceType
SecurityGroups:
- Ref: InstanceSecurityGroup
KeyName:
Ref: KeyName
ImageId: ami-0db6a09e9ade44bb3
Tags:
- Key: Name
Value: ApprovalTests.java.StarterProject
UserData:
Fn::Base64: <powershell>Invoke-WebRequest -UseBasicParsing https://raw.githubusercontent.com/approvals/ApprovalTests.java/master/install.windows.ps1 | Invoke-Expression</powershell>
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable RDP access via port 3389
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '3389'
ToPort: '3389'
CidrIp:
Ref: SSHLocation
Outputs:
InstanceId:
Description: InstanceId of the newly created EC2 instance
Value:
Ref: EC2Instance
AZ:
Description: Availability Zone of the newly created EC2 instance
Value:
Fn::GetAtt:
- EC2Instance
- AvailabilityZone
PublicDNS:
Description: Public DNSName of the newly created EC2 instance
Value:
Fn::GetAtt:
- EC2Instance
- PublicDnsName

PublicIP:
Description: Public IP address of the newly created EC2 instance
Value:
Fn::GetAtt:
- EC2Instance
- PublicIp
58 changes: 58 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>starterproject</groupId>
<artifactId>approvaltests_playground</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.approvaltests</groupId>
<artifactId>approvaltests</artifactId>
<version>9.5.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>download-sources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>

</project>
34 changes: 34 additions & 0 deletions src/main/java/org/samples/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.samples;

import org.lambda.query.Queryable;

import java.awt.*;
import java.util.HashMap;

public class Board {
private HashMap<Point, Cell> board = new HashMap<>();

public void addCell(int x, int y, boolean isVampire) {
board.put(new Point(x, y), new Cell(isVampire));
}

public int getNeighborCountAt(int x, int y) {
Cell cell = board.get(new Point(x, y));
boolean isVampire = cell != null && cell.isVampire();

return getNeighborsFor(x, y).where(p -> board.get(p) != null && isVampire == board.get(p).isVampire()).size();
}

private Queryable<Point> getNeighborsFor(int x, int y) {
return Queryable.as(
new Point(x - 1, y - 1),
new Point(x + 0, y - 1),
new Point(x + 1, y - 1),
new Point(x - 1, y),
new Point(x + 1, y),
new Point(x - 1, y + 1),
new Point(x + 0, y + 1),
new Point(x + 1, y + 1)
);
}
}
29 changes: 29 additions & 0 deletions src/main/java/org/samples/Cell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.samples;

public class Cell {
public int age;
private boolean vampire;

public Cell(boolean isVampire) {
vampire = isVampire;
}

public Cell() {
this(false);
}

public void advanceAge() {
age ++;
if (100 < age) {
setVampire();
}
}

public boolean isVampire() {
return vampire;
}

public void setVampire() {
vampire = true;
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/samples/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.samples;

public class Person
{
private final String firstName;
private final String lastName;
private final boolean isMale;
private final int age;
public Person(String firstName, String lastName, boolean isMale, int age)
{
this.firstName = firstName;
this.lastName = lastName;
this.isMale = isMale;
this.age = age;
}
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public boolean isMale()
{
return isMale;
}
public int getAge()
{
return age;
}
}
13 changes: 13 additions & 0 deletions src/test/java/org/samples/PackageSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.samples;

import org.approvaltests.core.ApprovalFailureReporter;
import org.approvaltests.reporters.DiffReporter;

/**
* Here you can set the default reporter used for everything
* starting with org.samples.* including sub-packages
**/
public class PackageSettings
{
public ApprovalFailureReporter UseReporter = DiffReporter.INSTANCE;
}
Loading

0 comments on commit 9da0e94

Please sign in to comment.