Skip to content

Commit

Permalink
2024-09-05 17:12:06.587562 new snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardocerqueira committed Sep 5, 2024
1 parent 004b339 commit 551ca93
Show file tree
Hide file tree
Showing 19 changed files with 1,286 additions and 410 deletions.
33 changes: 33 additions & 0 deletions seeker/report.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
--------------------------------------------------------------------------------
2024-09-05 17:12:06.587562
--------------------------------------------------------------------------------
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: snippet/ST_Point_table_from_csv.py
deleted: snippet/ascii-smuggler.py
deleted: snippet/bump
deleted: snippet/context_builder.py
deleted: snippet/dd.java
deleted: snippet/function.sh
deleted: snippet/instala_ccd_serpro_ubuntu.sh
deleted: snippet/login_to_google.py
deleted: snippet/polygon_table_from_datafile.py
deleted: snippet/sedona_df_to_geopandas.py
deleted: snippet/spatial_joins.py

Untracked files:
(use "git add <file>..." to include in what will be committed)
snippet/IntroduceStaticSetter.java
snippet/IntroduceStaticSetter1.java
snippet/ReplaceGlobalReferenceWithGetter2.java
snippet/executor.py
snippet/mini_01_gugudan.java
snippet/snowpark_session.py
snippet/tap-linux.py

no changes added to commit (use "git add" and/or "git commit -a")

--------------------------------------------------------------------------------
2024-09-04 17:12:46.040880
--------------------------------------------------------------------------------
Expand Down
31 changes: 31 additions & 0 deletions seeker/snippet/IntroduceStaticSetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//date: 2024-09-05T16:52:22Z
//url: https://api.github.com/gists/b9c886d5f45c4da84e1e28746c104b79
//owner: https://api.github.com/users/trikitrok

class MessageRouter {
public void Route(Message message) {
//!! ouch... x(
ExternalRouter.getInstance().sendMessage(message);
}
}

class ExternalRouter // another Singleton! x(
{
private static ExternalRouter instance;

private ExternalRouter() {
// initialize stuff
}

public static ExternalRouter getInstance() {
if (instance == null) {
instance = new ExternalRouter();
}
return instance;
}

// more code...
public void sendMessage(Message message) {
// interesting code to send the message
}
}
66 changes: 66 additions & 0 deletions seeker/snippet/IntroduceStaticSetter1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//date: 2024-09-05T17:06:13Z
//url: https://api.github.com/gists/6c259d3e1c1c3d3c0e02c580cbbdf1c5
//owner: https://api.github.com/users/trikitrok

class MessageRouter {
public void Route(Message message) {
//!! ouch... x(
ExternalRouter.getInstance().sendMessage(message);
}
}

class ExternalRouter // another Singleton! x(
{
private static ExternalRouter instance;

private ExternalRouter() {
// initialize stuff
}

public static ExternalRouter getInstance() {
if (instance == null) {
instance = new ExternalRouter();
}
return instance;
}

//!! Added for testing purposes only, do not use this in production code
public static void setInstanceForTesting(ExternalRouter anInstance) {
instance = anInstance;
}

// more code...
public void sendMessage(Message message) {
// interesting code to send the message
}
}

/////////////////////////////////////////////
// In some test we use the static setter to
// set a test double so that we can control
// what the singleton's instance does

class MessageRouterTest
{
@Test
public void routes_message()
{
ExternalRouter externalRouter = mock(ExternalRouter.class);
ExternalRouter.setInstanceForTesting(externalRouter);
MessageRouter messageRouter = new MessageRouter();
Message message = new Message();

messageRouter.Route(message);

verify(externalRouter).sendMessage(message);
}

// some other tests...

@AfterEach
public void TearDown()
{
// to keep tests isolated
ExternalRouter.setInstanceForTesting(null);
}
}
57 changes: 57 additions & 0 deletions seeker/snippet/ReplaceGlobalReferenceWithGetter2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//date: 2024-09-05T16:46:15Z
//url: https://api.github.com/gists/278e3df2a2f14aff40d3162dd3cef94c
//owner: https://api.github.com/users/trikitrok

// After applying Subclass & Override Method

class RegisterSale {
private List<Item> items;
// more code...

public void addItem(Barcode code) {
// using the Singleton!! x(
Item newItem = getInventory().getItemForBarCode(code);
items.add(newItem);
}

protected Inventory getInventory() {
return Inventory.GetInstance();
}

// more code...
}

/////////////////////////////

// In some test

public class RegisterSaleTest {

@Test
public void Adds_An_Item() {
Barcode code = new Barcode();
// some more setup code
//...
// we subclass & override the getter and return a test double of Inventory
Inventory inventory = mock(Inventory.class);

when(inventory.getItemForBarCode(code)).thenReturn(AnItem().withBarcode(code).build());
RegisterSaleForTesting registerSale = new RegisterSaleForTesting(inventory);

// rest of the test...
}

public class RegisterSaleForTesting extends RegisterSale {
private final Inventory inventory;

public RegisterSaleForTesting(Inventory inventory) {
this.inventory = inventory;
}

// overriden to separate from the singleton
@Override
protected Inventory getInventory() {
return inventory;
}
}
}
19 changes: 0 additions & 19 deletions seeker/snippet/ST_Point_table_from_csv.py

This file was deleted.

22 changes: 0 additions & 22 deletions seeker/snippet/ascii-smuggler.py

This file was deleted.

27 changes: 0 additions & 27 deletions seeker/snippet/bump

This file was deleted.

12 changes: 0 additions & 12 deletions seeker/snippet/context_builder.py

This file was deleted.

60 changes: 0 additions & 60 deletions seeker/snippet/dd.java

This file was deleted.

Loading

0 comments on commit 551ca93

Please sign in to comment.